After you define your interface and generate IDL code using the IDL GUIBuilder, you will write the code that controls the application's behavior. You can modify the code, compile it, and run it using the IDLDE.
Generally, you will be writing the event-handler callbacks for the procedures located in the generated *_eventcb.pro file. While doing this, you might like to handle initialization states, have multiple GUIs work together, add compound widgets, or control widget display. For examples of how to handle these different types of events, see the following sections:
When using the IDL GUIBuilder, you assign event procedures to specific events using the Events tab of the Properties dialog. The calling sequence for the events that you set are added to the generated *_eventcb.pro event callback code.
The argument that is passed into the specified event routine depends on the type of event being processed. Creation, realization, and destruction event routines are usually passed the ID of the involved widget, and all other callback routines are passed the appropriate IDL widget event structure.
It is a normal operation in applications to change the attributes of the interface when certain events occur. One method used in handling events for IDL GUIBuilder generated applications is the UNAME keyword, or the Name attribute, given to all created widgets. (In a programmatically-created IDL application, this action is handled using information stored in a widget component's user value.)
When you create a widget in the IDL GUIBuilder, IDL gives it a name unique to the widget hierarchy to which it belongs. You can rename the widget using the Name attribute.
In the generated code, this name is specified by the UNAME keyword. Because these names are unique, you can use the WIDGET_INFO function with the FIND_BY_UNAME keyword in your event callback routines to get the IDs of widgets in the interface application.
| Note |
This short example shows how basic event processing works in code generated by the IDL GUIBuilder. The example demonstrates how to use the FIND_BY_UNAME keyword to obtain the IDs of other widgets in the interface.
To create this simple example application, follow these steps:
Your interface definition should look like the one shown in the following figure.
time.pro widget code file and the time_eventcb.pro event callback code to the specified directory.time_eventcb.pro file and click Open.time_eventcb.pro file, locate the OnPress event procedure place holder, which looks like this:pro OnPress, Event end
; Get the widget ID of the label widget. Label = widget_info(Event.top, find_by_uname='clock') ; Set the value of the label widget to current time. widget_control, Label, set_value=Systime(0)
The first command gets the ID of the label widget by searching the widget hierarchy for a widget named "clock". This is the name that you gave the label widget in the IDL GUIBuilder Properties dialog. Once the ID is found, the second command sets the value of the label widget to the current system time.
time at the IDL command prompt.
This compiles and runs the time.pro file. In the running application, you can press the Time button to cause the current time to be displayed in the label.
You can provide runtime initialization information to the generated *.pro widget code by modifying the *_eventcb.pro file. Keywords provided to the generated widget interface procedure are passed to the post creation routines using the _EXTRA keyword.
If a routine is defined with the _EXTRA keyword parameter, you can add unrecognized keyword and value pairs, and the pairs are placed in an anonymous structure. The name of each unrecognized keyword becomes a tag name, and each value becomes the tag value.
You will use this feature most often when your application launches floating or modal dialogs, but the functionality is always available.
For example, if you want to display a dialog at the creation of an application, you would follow these basic steps:
*_eventcb.pro event code file, locate the "OnCreate" routine place holder, which looks like this:pro OnCreate, wWidget, _EXTRA=_VWBExtra_ end
For example, to process the DO_DIALOG keyword in the defined OnCreate procedure, add the DO_DIALOG keyword to the procedure, and add the logic to handle it to the event callback routine. The completed procedure should look like this:
pro OnCreate, wWidget, DO_DIALOG=DO_DIALOG, _EXTRA=_VWBExtra_
; If DO_DIALOG is set, display a simple message box.
if( Keyword_Set(DO_DIALOG) )then $
status = Dialog_Message("On Dialog Set")
end
<ProgramName>, /DO_DIALOG
You can create multiple interfaces with the IDL GUIBuilder then integrate them to form the complete application hierarchy. This example shows you how to construct two interfaces and integrate them.
The first interface you will create is the main window, and it will consist of a simple push button that will launch a modal dialog. The second interface you will create is the modal dialog, and it will display a close button.
To create the main window, follow these steps:
maingui.pro widget code and the maingui_evnetcb.pro event-handler code.maingui_eventcb.pro file, and click Open.maingui_eventcb.pro file, locate the OnPress event procedure place holder, which looks like this:pro OnPress, Event end
modalgui, group_leader=Event.top
You will create the "modalgui" dialog in the next set of steps. Note that you set the GROUP_LEADER keyword here because the modal dialog requires it.
To create the modal dialog, follow these steps:
modalgui.pro widget code file and the modalgui_eventcb.pro event callback file.modalgui_eventcb.pro file and locate the OnModalPress procedure place holder. Then add the following code between the PRO and END statements so that the dialog closes when the button is pushed:widget_control, Event.top, /destroy
Enter maingui at the IDL command prompt. This command runs the main window. You can press the Modal Dialog button, and the modal dialog is displayed. When you press the OK button on the modal dialog, the dialog exits.
The IDL GUIBuilder tools do not allow you to add a compound widget directly to your interface. You can, however, modify your event code to add a compound widget.
To add a compound widget to an IDL GUIBuilder generated interface, follow these basic steps:
This example demonstrates how to add a compound widget to an application constructed with the IDL GUIBuilder. The application contains a label and a CW_FSLIDER compound widget. In the running application, the values generated by CW_FSLIDER will be displayed in the label widget.
To create this application, follow these steps:
compound.pro widget code file and the compound_eventcb.pro event-handler file.compound_eventcb.pro file.compound_eventcb.pro file, locate the AddCW event routine place holder, and insert the code to add the CW_FSLIDER compound widget to the base widget. The routine should look like this:pro AddCw, wWidget idslide = CW_FSLIDER(wWidget, /SUPPRESS_VALUE) end
FUNCTION HandleEvent, Event ; Fslider event structure is an anonymous structure, so ; the following will return "" if it is from fslider. IF(TAG_NAMES(Event, /STRUCTURE_NAME) eq "")THEN BEGIN ; Get the id of the label widget using its name. id = widget_info(Event.top, find_by_uname='label') ; Set the value of the label, to the value in the slider. WIDGET_CONTROL, id, set_value= $ String(Event.value, format='(f5.2)') RETURN,0 ; Halt event processing here. ENDIF RETURN, Event END
Note that the callback routine finds the label widget using the FIND_BY_UNAME keyword with the name value you gave the widget in the Properties dialog.
To run the application, enter compound at the IDL command prompt. This complies and runs the application. In the running application, move the CW_FSLIDER and the value is placed in the label.
This example demonstrates how to use the IDL GUIBuilder to create an interface that contains overlapping sub-bases containing different types of widgets. The example shows how you can display and hide overlapping controls in an interface created in the IDL GUIBuilder, and it incorporates using the Widget Browser. Note that this example is slightly more complicated than the others.
This example constructs an interface with the following widgets:
The two contained sub-bases overlap and the visibility of each is controlled by the value selected in the droplist. When users select an item in the droplist, one sub-base is hidden and the other one is displayed.
To create this application interface, follow these steps:
visible.prc resource file.The interface is now complete. It should look similar to the one shown in the following figure.
To generate and modify the code, follow these steps:
visible.pro widget code file and the visible_eventcb.pro event-handler file.visible_eventcb.pro file, and click Open.visible_eventcb.pro file, locate the OnSelect event procedure place holder, which looks like this:pro OnSelect, Event end
; Toggle the mapping of the two IDL sub-bases and ; get the Widget IDs of the two sub-bases. wBase1 = Widget_Info(Event.top, find_by_uname="base1") wBase2 = Widget_Info(Event.top, find_by_uname="base2") ; Now update the mapping. widget_control, wBase1, map=(Event.index eq 0) widget_control, wBase2, map=(Event.index eq 1)
The added IDL code gets the Widget IDs of the sub-bases that you created and sets the mapping (hide or show) of these bases depending on the selected value of the droplist.
To run this application, enter visible at the IDL command prompt. This command executes the visible application. In the running application, you can change the selection in the droplist, and the action will change the displayed widget.