Advanced dialogs¶

Advanced dialogs¶
  1preview_file1 = r"d:\\preview1.ipd"
  2preview_file2 = r"d:\\preview2.ipd"
  3
  4picture_file1 = r"d:\\picture1.jpg"
  5picture_file2 = r"d:\\picture2.jpg"
  6
  7
  8# Define a function to describe a constant from the ipDialogCallbackReason enumeration
  9def describe_callback_reason(reason):
 10    if reason == ipDialogCallbackReason.dcrFieldSelected:
 11        Str = "Field Selected"
 12    elif reason == ipDialogCallbackReason.dcrFieldCurrent:
 13        Str = "Field Current"
 14    elif reason == ipDialogCallbackReason.dcrFieldNonCurrent:
 15        Str = "Field Non Current"
 16    elif reason == ipDialogCallbackReason.dcrDialogClosing:
 17        Str = "DialogClosing"
 18    describe_callback_reason = Str
 19
 20# Define a function to describe a constant from the ipDialogButtonType enumeration
 21def describe_dialog_button_type(button_type):
 22    if button_type == ipDialogButtonType.dbtUnknown:
 23        Str = "Unknown"
 24    elif button_type == ipDialogButtonType.dbtOk:
 25        Str = "Ok"
 26    elif button_type == ipDialogButtonType.dbtCancel:
 27        Str = "Cancel"
 28    elif button_type == ipDialogButtonType.dbtYes:
 29        Str = "Yes"
 30    elif button_type == ipDialogButtonType.dbtNo:
 31        Str = "No"
 32    elif button_type == ipDialogButtonType.dbtNext:
 33        Str = "Next"
 34    elif button_type == ipDialogButtonType.dbtPrevious:
 35        Str = "Previous"
 36    elif button_type == ipDialogButtonType.dbtClose:
 37        Str = "Close"
 38    elif button_type == ipDialogButtonType.dbtPrint:
 39        Str = "Print"
 40    elif button_type == ipDialogButtonType.dbtCustom:
 41        Str = "Custom"
 42    describe_dialog_button_type = Str
 43
 44# Define a function to describe a constant from the ipDialogFieldType enumeration
 45def describe_dialog_field_type(field_type):
 46    if field_type == ipDialogFieldType.dftUnknown:
 47        Str = "Unknown"
 48    elif field_type == ipDialogFieldType.dftAngle:
 49        Str = "Angle"
 50    elif field_type == ipDialogFieldType.dftArea:
 51        Str = "Area"
 52    elif field_type == ipDialogFieldType.dftCheckBox:
 53        Str = "Check Box"
 54    elif field_type == ipDialogFieldType.dftComboBox:
 55        Str = "Combo Box"
 56    elif field_type == ipDialogFieldType.dftDate:
 57        Str = "Date"
 58    elif field_type == ipDialogFieldType.dftDistance:
 59        Str = "Distance"
 60    elif field_type == ipDialogFieldType.dftInteger:
 61        Str = "Integer"
 62    elif field_type == ipDialogFieldType.dftLine:
 63        Str = "Line"
 64    elif field_type == ipDialogFieldType.dftListBox:
 65        Str = "List Box"
 66    elif field_type == ipDialogFieldType.dftPreview:
 67        Str = "Preview"
 68    elif field_type == ipDialogFieldType.dftRadioGroup:
 69        Str = "Radio Group"
 70    elif field_type == ipDialogFieldType.dftReal:
 71        Str = "Real"
 72    elif field_type == ipDialogFieldType.dftText:
 73        Str = "Text"
 74    elif field_type == ipDialogFieldType.dftTextBox:
 75        Str = "Text Box"
 76    elif field_type == ipDialogFieldType.dftTime:
 77        Str = "Time"
 78    elif field_type == ipDialogFieldType.dftTwinList:
 79        Str = "Twin List"
 80    elif field_type == ipDialogFieldType.dftVolume:
 81        Str = "Volume"
 82    elif field_type == ipDialogFieldType.dftWeight:
 83        Str = "Weight"
 84    elif field_type == ipDialogFieldType.dftPicture:
 85        Str = "Picture"
 86    elif field_type == ipDialogFieldType.dftButton:
 87        Str = "Button"
 88    describe_dialog_field_type = Str
 89
 90# Define a sub routine to display a list of items in the output toolbox
 91def display_list_values(message, list):
 92    ot.add(message)
 93
 94    for item in list:
 95        ot.add(item)
 96
 97# Define a callback, passed into the ShowModal method of IDialog
 98def callback(callback_params):
 99    field = callback_params.field
100
101    if field is not None:
102        ot.add(field.label + ": " + Str(describe_callback_reason(callback_params.reason)))
103
104        if field.field_type == ipDialogFieldType.dftPicture:
105            ot.add("HasImage: " + Str(field.picture_has_image))
106        else:
107            ot.add("Value: " + Str(field.value))
108
109        if field.label == "Click Me!":
110            impact.gui.show_message(ipShowMessageType.smtInfo, "You clicked me!", None)
111
112        elif field.label == "Preview Group":
113            if field.value == 0:
114                preview_field.show_preview(preview_file1, "One up", True)
115            else:
116                preview_field.show_preview(preview_file2, "One up", True)
117
118        elif field.label == "load Picture 1":
119            pic1Field.show_picture(picture_file1)
120
121        elif field.label == "load Picture 2":
122            pic1Field.show_picture(picture_file2)
123
124        elif field.field_type == ipDialogFieldType.dftPicture:
125            if pic1Field.picture_has_image:
126                if pic1Field.picture_file_name == "":
127                    impact.gui.show_message(ipShowMessageType.smtInfo, "The image was changed from the clipboard", None)
128
129                else:
130                    impact.gui.show_message(ipShowMessageType.smtInfo, "The image was changed and loaded from '" + Str(pic1Field.picture_file_name) + "'", None)
131
132            else:
133                impact.gui.show_message(ipShowMessageType.smtInfo, "The image was cleared", None)
134
135
136    if callback_params.reason == ipDialogCallbackReason.dcrDialogClosing:
137        ot.add(describe_dialog_button_type(callback_params.button_type))
138
139        if callback_params.button_type == ipDialogButtonType.dbtOk:
140            callback_params.can_close = allow_close_field.value
141
142
143# Create a local variable for the impact impact.gui object
144g = impact.gui
145
146# Create a local variable for the output toolbox
147ot = g.output_toolbox
148
149# Create a dialog
150d = g.make_dialog("Options")
151
152# Check the dialog was created
153if d is not None:
154
155    # Create a local variable for the fields of the dialog
156    fields = d.fields
157
158    # Build up the controls to display in the dialog
159    d.add_button(ipDialogButtonType.dbtOk)
160
161    types_tab = d.add_tab("Types")
162
163    fields.add_line("Simple Types")
164
165    check_box_field = fields.add_check_box(False, "Boolean")
166    check_box_field.value = True
167    check_box_field.use_callback = True
168
169    integer_field = fields.add_integer(5, "Integer")
170    integer_field.value = 2
171    integer_field.use_callback = True
172
173    real_field = fields.add_real(91.2, "Real")
174    real_field.value = 6.23
175    real_field.use_callback = True
176
177    text_field = fields.add_text("Simple text", "Text")
178    text_field.value = "Modified simple text"
179    text_field.case = ipDialogStringCase.dscAll
180    text_field.chars = ipDialogStringChars.dshAll
181
182    short_text_field = fields.add_text("AA123", "Short text")
183    short_text_field.max_length = 5
184    short_text_field.case = ipDialogStringCase.dscUpper
185    short_text_field.chars = ipDialogStringChars.dshAlphaNumeric
186    short_text_field.use_callback = True
187
188    text_box_field = fields.add_text_box("Advanced text" + "\r\n" + "New Line", "Text Box")
189    text_box_field.value = "Modified advanced text" + "\r\n" + "New Line"
190    text_box_field.use_callback = True
191
192    date_field = fields.add_date(datetime.date.today(), "Date")
193    date_field.value = datetime.date.today()
194    date_field.use_callback = True
195
196    time_field = fields.add_time(datetime.datetime.now().time(), "Time")
197    time_field.value = datetime.datetime.now().time()
198    time_field.use_callback = True
199
200    fields.add_line("Advanced Types")
201
202    distance_field = fields.add_distance(-200.0, "Distance", True)
203    distance_field.value = 100.0
204    distance_field.hint = "Enter a distance"
205    distance_field.use_callback = True
206
207    angle_field = fields.add_angle(45.0, "Angle" + "\r\n" + "(use 90 if possible)")
208    angle_field.value = 180.0
209    angle_field.use_callback = True
210
211    weight_field = fields.add_weight(9.2, "Weight")
212    weight_field.value = 64.5
213    weight_field.use_callback = True
214
215    area_field = fields.add_area(8.6, "Area")
216    area_field.value = 23.9
217    area_field.use_callback = True
218
219    volume_field = fields.add_volume(2.4, "Volume")
220    volume_field.value = 15.2
221    volume_field.use_callback = True
222
223    button_field = fields.add_button("Click Me!")
224
225    button_field.hint = "Click this button to show how a callback is triggered"
226
227    # Adds a checkbox field to control the closing of the dialog
228    allow_close_field = fields.add_check_box(False, "Allow close on OK")
229    allow_close_field.value = True
230    allow_close_field.use_callback = True
231
232    lists_tab = d.add_tab("Lists")
233
234    fruits = [None] * 8
235
236    fruits[0] = "Orange"
237    fruits[1] = "Apple"
238    fruits[2] = "Banana"
239    fruits[3] = "Lemon"
240    fruits[4] = "Pineapple"
241    fruits[5] = "Kiwi"
242    fruits[6] = "Strawberry"
243    fruits[7] = "Lime"
244
245    fields.add_line("Select a single fruit from this list")
246
247    combo_box_field = fields.add_combo_box("Lemon", "Fruit Combo", fruits)
248
249    # Set combo_box_field = fields.add_combo_box(3, "Fruit Combo", fruits, False)
250    # combo_box_field.value = 4
251    combo_box_field.value = "Kiwi"
252    combo_box_field.use_callback = True
253
254    selection = [None] * 8
255
256    selection[0] = False
257    selection[1] = True
258    selection[2] = False
259    selection[3] = True
260    selection[4] = False
261    selection[5] = True
262    selection[6] = False
263    selection[7] = True
264
265    fields.add_line("Select none or more fruits from this list box")
266
267    list_box_field = fields.add_list_box(fruits, selection, True, 5)
268    list_box_field.height = 5
269
270    fields.add_line("Select a single fruit from this group")
271
272    radio_group_field = fields.add_radio_group("Apple", "Fruit Group", fruits)
273
274    # Set radio_group_field = fields.add_radio_group(1, "Fruit Group", fruits)
275    # radio_group_field.value = 2
276    radio_group_field.value = "Banana"
277    radio_group_field.use_callback = True
278
279    fields.add_line("Select none or more fruits from this twin list")
280
281    twin_list_field = fields.add_twin_list("Left", "Right", fruits, selection, 6)
282    twin_list_field.height = 6
283
284    preview_tab = d.add_tab("Preview")
285
286    previews = [None] * 2
287
288    previews[0] = "Preview 1"
289    previews[1] = "Preview 2"
290
291    preview_group_field = fields.add_radio_group("Preview 1", "Preview Group", previews)
292    preview_group_field.use_callback = True
293
294    preview_field = fields.add_preview(preview_file1, "One up", True, ipDialogPreviewOrientation.dpoVertical)
295
296    picture_tab = d.add_tab("Picture")
297
298    pic1Opts = impact.gui.create_dialog_picture_options()
299
300    pic1Opts.width = 320
301    pic1Opts.height = 240
302
303    pic1Opts.command_panel_position = ipDialogPictureCommandsPosition.dpcpRightTop
304    pic1Opts.command_panel_always_visible = True
305
306    pic1Field = fields.add_picture(picture_file1, "Picture1", pic1Opts)
307
308    pic1Field.use_callback = True
309
310    load_pic1_button = fields.add_button("load Picture 1")
311    load_pic2_button = fields.add_button("load Picture 2")
312
313    # Display the type of each field in the output toolbox
314    for field in fields:
315        ot.add(describe_dialog_field_type(field.field_type))
316
317    # Show the dialog with a callback handler
318    button_pressed = d.show_modal(GetRef("Callback"))
319
320    if button_pressed == ipDialogButtonType.dbtOk:
321
322        # Display the values from the dialog
323        ot.add(check_box_field.label + ": " + Str(check_box_field.value))
324        ot.add(integer_field.label + ": " + Str(integer_field.value))
325        ot.add(real_field.label + ": " + Str(real_field.value))
326        ot.add(text_field.label + ": " + Str(text_field.value))
327        ot.add(text_box_field.label + ": " + Str(text_box_field.value))
328        ot.add(date_field.label + ": " + Str(date_field.value))
329        ot.add(time_field.label + ": " + Str(time_field.value))
330
331        ot.add(distance_field.label + ": " + Str(distance_field.value))
332        ot.add(angle_field.label + ": " + Str(angle_field.value))
333        ot.add(weight_field.label + ": " + Str(weight_field.value))
334        ot.add(area_field.label + ": " + Str(area_field.value))
335        ot.add(volume_field.label + ": " + Str(volume_field.value))
336
337        ot.add(radio_group_field.label + ": " + Str(radio_group_field.value))
338        ot.add(radio_group_field.label + ": " + Str(radio_group_field.selected_item))
339
340        ot.add(combo_box_field.label + ": " + Str(combo_box_field.value))
341        ot.add(combo_box_field.label + ": " + Str(combo_box_field.selected_item))
342
343        display_list_values("Listbox selected values:", list_box_field.selected_items)
344        display_list_values("Listbox selected indicies:", list_box_field.selected_indices)
345        display_list_values("Twinlist selected values:", twin_list_field.selected_items)
346        display_list_values("Twinlist selected indicies:", twin_list_field.selected_indices)
347
348        ot.add(pic1Field.label + ": " + Str(pic1Field.picture_file_name))