Re: widget_button, event_pro and passing arguments [message #42011] |
Wed, 15 December 2004 08:00 |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Francois Leduc wrote:
> Hello,
>
> I have a widget_button that calls a procedure "plot_function" :
> row_base4 = widget_button(TLB, /align_left, value=' Plot
> ',event_pro='plot_function')
>
> The proceduce is defined as:
>
> pro plot_function, event
> envi_plot_data, x,y
> end
>
> How to pass arguments, such as X and Y, to the procedure plot_function ?
>
> Thanks
>
> Francois.
>
>
>
You can't pass anything other than the event structure to the event
handler. Instead, the event handler has to fetch the information it
needs from somewhere. The usual strategy is to store all your
information you need to run your widget program (which includes your x
and y) in the top-level base's user value. David Fanning calls this the
"info structure". So, at the end of your widget definition module,
create your info structure like
info = { x: x, y: y } ; and whatever else you need to run your program
For data arrays it usually makes sense to use pointers (free them in the
widget program's cleanup procedure).
Then (still in the widget definition module) store the info structure in
the top-level base's user value:
widget_control, tlb_id, set_uvalue=info, /no_copy
In your event handler, you will then at the very beginning (e.g., after
the error handling code) fetch the info structure:
widget_control, event.top, get_uvalue=info, /no_copy
Then do whatever you want with info.x, info.y etc. At the very end of
the event handler, write the info structure back into the TLB's user
value, so that the next event handler can use it:
widget_control, event.top, set_uvalue=info, /no_copy
This is briefly described in the IDL help, search for "managing the
state of a widget application" in the index. Don't use the first
technique described (COMMON blocks), since that would allow only one
instance of your program running at a time. The second technique
described is explained in detail in David Fanning's book. The third one
(using a pointer to the data or info structure) is used in Liam Gumley's
book.
Good luck!
Benjamin
|
|
|