Re: Widget Basics: Updating a text_widget after user input [message #52746] |
Thu, 01 March 2007 12:47 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Rob writes:
> I'm just starting to learn the basics of widgets in IDL after
> purchasing David's superb book.
Oh oh. :-(
> What I'm doing at the minute is using a text widget to display
> information from a file. The file contains a large number of scans and
> I'm selecting the scan number from a list dropdown box and then want
> the text_widget to refresh with the new scan number and the graphics
> window to display the new scan.
>
> At the minute the graphics window partly works, once I select a scan
> from the dropdown box and then try to trigger another event elsewhere
> via one of the other buttons the graphics window refreshes but the
> widget_text doesn't refresh with the new value.
>
> I'm storing all of the values in an anonymous info structure as David
> recommends and the following is my event handler to handle the scan
> being selected from the dropdown box:
>
> PRO select_scan_spectral_plotter,event
> widget_control,event.top,get_uvalue=info, /no_copy
>
> widget_control, event.id, get_value=scan_list
>
> info.control_panel_info.scan_number=scan_list[event.index]
>
> ;widget_control,
> info.control_panel_info.scan_number,set_value=scan_list[even t.index]
>
> print, scan_list[event.index]
> widget_control,event.top,set_uvalue=info, /no_copy
> END
>
> This prints out the new scan number as I'd expect but I'm not sure how
> to get it to refresh the text_widget.
There are ways to generate events in widget programs (SEND_EVENT keyword
to WIDGET_CONTROL, etc.), but let's keep this simple. The info structure
contains *everything* you need to run your program, so it contains the
text widget ID, the identifier of the draw widget, the draw widget's
window index number, and the image you want to display there. EVERYTHING
as a matter of fact!
So, since it's all there for you to muck around with, just
muck around with it. If you want to change what is displayed
in the text widget, then just do this:
Widget_Control, info.textWidgetID, Set_Value='the new text'
Now new text is displayed in the text widget.
If you want a new image displayed in the draw widget, then do this:
WSet, info.windowIndexNumber
TVImage, info.theNewImageIWantToDisplay
And it is done. All this is done in the event handler that gets the
new scan number event.
Cheers,
David
P.S. I'd spend a few minutes reading that section on how to
name modules in a widget program over again, before you get
*really* confused. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|