[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Widgets
- Subject: Re: Widgets
- From: Liam Gumley <Liam.Gumley(at)ssec.wisc.edu>
- Date: Fri, 01 Oct 1999 13:20:21 -0500
- Newsgroups: comp.lang.idl-pvwave
- Organization: Space Science and Engineering Center, University of Wisconsin-Madison
- References: <#SoKM97C$GA.283@cpmsnbbsa03>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:16735
Robert LeeJoice wrote:
> Question for Widget Gurus: Can I put Widget creation items in an event
> procedure? I want to be able to able to have a menu item open a new window
> that consists of a table to display some data. I have put the following in
> and it seems to work, but I'm concerned about how xmanager sees/doesn't see
> this since the widget statements are not in the "Widget Definition file".
> Is it okay and prudent to do this? I assume as long as there are no
> event_procedures in the code?
Robert,
Anytime you create a new window, the best approach is to create a
separate program to create the widgets in the window and manage events.
For example:
Main program
- Create widgets
- Manage events
- If new window is requested, call new window program
New window program
- Create widgets
- Manage events
Here's an example which creates a simple launcher for XLOADCT, which is
a separate program (see the lib directory in your IDL installation):
;---cut here---
PRO TEST_EVENT, EVENT
;- Get user value from the widget which caused the event
widget_control, event.id, get_uvalue=uvalue
;- Act on the user value
case uvalue of
'Color Table' : xloadct
else : print, 'Unrecognized widget event'
endcase
END
PRO TEST
;- Create widgets
base = widget_base(/column)
butt = widget_button(base, value='Color Table', uvalue='Color Table')
widget_control, base, /realize
;- Manage events
xmanager, 'test', base
END
;---cut here---
In the event handler procedure TEST_EVENT, XLOADCT is called if an event
is received from the 'Color Table' button. XLOADCT is written as a
separate main program so that it can be called from different modes,
such as the command line, or from within a widget program.
Even when you are creating a utility widget which is specific to your
application, it is still much better to code it as a separate IDL
program (like XLOADCT), because you can code and test it as a unit,
separate from the main program.
Cheers,
Liam.