Prev: Simple Button Using PyRegister Up: Examples Top: Top

5.3.4. Command Line Program Front End

This example is a simple front end to the unix "cp" command that demonstrates the use of the MrmNcreateCallback to enter the widgets created by UIL into module __main__'s dictionary. This is somewhat cleaner than having to find the UIL-created widgets using NameToWidget. The files involved are panel_cp.uil, panel_cp.uid and panel_cp.py.

panel_cp.uil contains the following:

panel_cp.uil is compiled to panel_cp.uid by the statement:

panel_cp.py contains the following text:

This example demonstrates using the OnCreate MrmNcreateCallback to access the __widget__ symbol and insert an entry in the __main__ module's dictionary for the XmText and XmPushButton widgets declared in the UIL. This makes these widgets accessible as Python-wrapped widget objects to the OnValueChanged and OnCopy callback routines, without having to pass the widgets to these callbacks in the UIL tag argument.

Another way to accomplish this is to insert the names into the __main__ namespace explicitly in main(), for example:

Here, 'src_file' and 'dst_file' are the widget's names as specified in the UIL, and NameToWidget is used to find the widgets, obtain Python wrapped widget objects, and initialize src_file_w and dst_file_w global variables.