|
Re: updating a different widget from the event handler [message #29954 is a reply to message #29936] |
Tue, 26 March 2002 09:49  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
David Higgins wrote:
> 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.
It's probably correct. "source" is not the name of the widget, it's the
name of a variable in which you stored the widget ID number. The only
variables that an event handler knows about are the ones that are given
a value in that event handler itself, or that are stored in a common
block that the event handler uses. Many program use common blocks for
this purpose, but there are nasty problems with that approach. Storing
the widget ID of the text widget inside the button widget, as David
describes, is a better way to do this.
|
|
|
Re: updating a different widget from the event handler [message #29957 is a reply to message #29954] |
Tue, 26 March 2002 09:16  |
Robert Stockwell
Messages: 74 Registered: October 2001
|
Member |
|
|
David Fanning wrote:
> 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.
lol, thanks for making me choke on my coffee!
-bob
> No, just kidding. :-)
|
|
|
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
|
|
|