Simple Dialog (Python)

Simple Dialog (Python)
 1# Simple function to prompt the user for two distance values
 2def ShowValues( L, W ):
 3    theDialog = impact.gui.make_dialog("Rectangle")
 4
 5    # the distance entry fields
 6    fieldLength = theDialog.fields.add_distance( L, "Length", False)
 7    fieldWidth = theDialog.fields.add_distance( W, "Width", False)
 8
 9    # the buttons
10    theDialog.add_button( ipDialogButtonType.dbtOk )
11    theDialog.add_button( ipDialogButtonType.dbtClose )
12
13    # show the dialog and determine which button was pressed
14    theButton = theDialog.show_modal(None)
15    if theButton==ipDialogButtonType.dbtOk:
16        # retrieve the values
17        L = fieldLength.value
18        W = fieldWidth.value
19        ShowValues=True
20    else:
21        ShowValues=False
22    return locals().get("ShowValues")
23
24# Set the default values, show the dialog, then use the entered values
25Lsize = 100
26Wsize = 200
27if ShowValues( Lsize, Wsize ):
28    if Lsize>0 and Wsize>0:
29        impact.gui.output_toolbox.add('Create rectangle, size ' + str(Lsize) + ' by ' + str(Wsize))