Example: Retrieving Values
The following example builds on Example: A Simple Tab Widget by adding the following features:
- “Next” and “Previous” buttons that switch the tab display to the next (or previous) tab in the tab set.
- A mechanism for saving the values of the widgets in the tab interface. Implementing such a mechanism allows the user to view and change all of the settings accessible via the tab widget before committing any of them.
- A mechanism for canceling. It exits from the tabbed interface without committing any changes made via the tab interface.
This example is included in the file tab_widget_example2.pro
in the examples/doc/widgets
subdirectory of the IDL distribution. Run this example procedure by entering tab_widget_example2
at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT tab_widget_example2.pro
. See Running the Example Code if IDL does not run the program as expected.
The following things about this example are worth noting:
- The
retStruct
structure is an example of the kind of information you might pass out of a tab widget, back to a larger widget application. Using an approach like the one here allows the user to set a group of values before sending any of them to the larger application. This may be more efficient than updating the larger application “on the fly” as the user makes changes to the widgets in the tab interface. - Similarly, if the user’s changes are not sent to the larger application until he or she clicks the “Done” button, it is important to provide a way for the user to cancel the operation entirely, without sending any changes.
- In most cases, when we refer to a field in a structure, we refer to it by its name. The event function
TWE2_saveValue
refers to the fields of theretStruct
structure by their indices instead. We do this because while it is not possible to pass the field name in a variable, it is possible to pass the integer index value. Passing the index value of the appropriate field in theretStruct
structure as the user value of the widget whose value is being saved allows us to write a singleTWE2_saveValue
function, rather than one function for each field in theretStruct
structure. - The “Next” and “Previous” buttons in this example imply that there is an order to the actions performed using the tab set. While there is no order in this example, it is easy to imagine a situation in which values from one tab would influence actions taken on another. You could even require that some action be taken on a given tab before a later tab could be displayed.