There are two typical ways to pass data from one event handler function to another in a traditional IDL Widget Application. The one most favored in IDL documentation is to assign a "state structure" as the UVALUE ("user value") of the top-level base widget. The state structure would be created with one field for every parameter that you want to share with all event handlers. Thus, in a widget application that, let's say, has a draw widget and a textbox a state structure might be intialized like this:
info = { datafile:'', wDraw:wDraw, wText:wText }
Before the XMANAGER call, one would then normally have an assignment like this:
widget_control, tlb, SET_UVALUE=info
After this all event handler functions could access the current "state" of shared parameters in the widget application, by starting off with the following code call:
widget_control, event.top, GET_UVALUE=info
your WID_BROWSE could update the state structure with code like the following:
info.datafile = dialog_pickfile(FILTER='.csv')
widget_control, event.top, SET_UVALUE=info ; Update the struct stored with the 'tlb'
WID_CALCULATE could then get the current state of the 'datafile' parameter with the following code:
widget_control, event.top, GET_UVALUE=info
openr, lun, info.datafile, /GET_LUN
That is the method you see most often in IDL documentation. An alternative method could be to have your program initialize and share parameters through "global variables" that IDL can initialize in a COMMON block for all the procedures/functions in the program. In your example, this might mean adding three lines of COMMON statements right after each PRO statement that, let's say, might look like this:
COMMON myglobals, datafile, wDraw, wText
All the procedures in the program with the above call would be sharing the same 'datafile', 'wDraw' and 'wText' with equal rights to read or update.
Finally, I should mention the modern way to do this: Making your widget program and your event handlers be methods in your own custom-made IDL object class application. The shared parameters, like 'datafile' can then be fields in the structure that programmers typically initialize in the application's '...__DEFINE' method. And the methods that need acurrent stored value can get it with syntax like:
self.datafile = dialog_pickfile(FILTER='.csv')
If you enjoy programming, then this last approach would be the best for you to learn for long-term benefits.
James Jones
|