Re: updating a different widget from the event handler [message #29963 is a reply to message #29957] |
Tue, 26 March 2002 06:39  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Higgins (dmh@medphysics.leeds.ac.uk) writes:
> I have set up my first ever GUI and it runs ok. I have a "Browse"
> button and a text widget for a file path. I would like to have the
> file path appear in the text widget after clicking on Browse and
> choosing a file. Getting the path is easy (I named it "newpath"), but
> how to update the text widget (which is called "source") is beyond me.
>
> I tried
> widget_control, source, set_value=newpath
> but the event handler has never heard of "source"...it thinks it's an
> undefined variable. Is there an easy solution?
Ah, well. This is the trick in widget programs, isn't it?
You need to get information which you have over there, over
here where you need it.
The answer is a common block.
No, just kidding. :-)
Typically, we put all the information we need to run our
program in a structure (usually called the "info" structure).
We store that in the user value of the top-level base, since
it is easy to find there (event.top always points to the
top-level base).
info = {source:source, otherthings:otherthings}
Widget_Control, tlb, Set_UValue=info, /No_Copy
You can get the info structure and use it like this:
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, info.source, Set_Value=newpath
Widget_Control, event.top, Set_UValue=info, /No_Copy
You can find examples of this in almost any well-written widget
program you find on the Internet.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|