Simple dialog showing pulldown list¶
Simple dialog showing pulldown list¶
1# simple function to allow the user to choose a palette (uses an array)
2def palette_chooser1():
3 the_dialog = impact.gui.make_dialog("Choose a palette")
4
5 # we must make an array of the palette names
6 pal_name_array = []
7 pal_count = 0
8
9 # in this example we will only show the Cut palettes
10 for pal in active_drawing.palettes:
11 if pal.palette_type == ipPaletteType.ptCut:
12
13 # we need to resize the array each time we add an item
14 # Redim (resize the list as needed)
15 pal_name_array[count] = pal.full_name
16 count = count +1
17
18 # now add this field to the dialog
19 field_palette_list = the_dialog.fields.add_combo_box(0, "Palettes", pal_name_array)
20
21 # only one button
22 the_dialog.add_button(ipDialogButtonType.dbtOk)
23
24 # display the dialog
25 the_button = the_dialog.show_modal(None)
26
27 # now find with item the user has chosen (for example the third item), and
28 # find which palette name this corresponds to
29 chosen_pal_item = field_palette_list.value
30 chosen_pal = pal_name_array(chosen_pal_item)
31
32 # finally we return this palette name
33 _result = chosen_pal
34 return _result
35
36
37# simple function to allow the user to choose a palette (uses an arraylist, for easy sorting)
38def palette_chooser2():
39 the_dialog = impact.gui.make_dialog("Choose a palette")
40
41 # we must make an array of the palette names, but we will do this with an arraylist object
42 pal_name_array_list = []
43
44 # in this example we will only show the Cut palettes
45 for pal in active_drawing.palettes:
46 if pal.palette_type == ipPaletteType.ptCut:
47
48 # add the palette name to the arraylist
49 pal_name_array_list.append(pal.full_name)
50
51 # now sort the names alphabetically
52 pal_name_array_list.sort()
53
54 # convert the arraylist to an array
55 pal_name_array = pal_name_array_list.to_array()
56
57 # Wrap variant return items with Impact.py wrapper
58 if pal_name_array is not None:
59 pal_name_array = [IMasterSetting(item) for item in pal_name_array]
60
61 # now add this field to the dialog
62 field_palette_list = the_dialog.fields.add_combo_box(0, "Palettes", pal_name_array)
63
64 # only one button
65 the_dialog.add_button(ipDialogButtonType.dbtOk)
66
67 # display the dialog
68 the_button = the_dialog.show_modal(None)
69
70 # now find with item the user has chosen (for example the third item), and
71 # find which palette name this corresponds to
72 chosen_pal_item = field_palette_list.value
73 chosen_pal = pal_name_array(chosen_pal_item)
74
75 # finally we return this palette name
76 _result = chosen_pal
77 return _result
78
79if not active_drawing.isNone():
80 pal_name = palette_chooser2()
81
82 impact.gui.output_toolbox.add("The chosen palette was '" + str(pal_name) + "'")