[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Beginning GUI Applications
> Is there a way to pass values between event procedures?
finally one I can answer! :)
Use a data structure. Stick it in the UValue of the top level base
widget. There are a few details but this is the main idea. You get at
the data by using the Get_UValue keyword of Widget_Control.
pro my_event_handler, event
;we have the event structure. It contains the reference to our tlb
;widget. Use that to get our user value that we defined in
;our main program routine.
WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
;now I can do anything I want with my info structure
info.xsize=200
info.ysize=400
;Just don't forget to put it back when your done!
WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
end
pro my_gui_main
;create the top level base
tlb=widget_base(column=1, mbar=menuID, /TLB_size_events)
;add buttons and draw areas or whatever
realize the widget hierarchy
widget_control, tlb, /realize
;create the anonymous data structure "info"
info = {
;stick important variables/pointers/objects
;you need to pass around in here. For example:
bigdataset:ptr_new(), $
plotobject:obj_new(), $
xsize:50, $
ysize:50, $
}
;here's the good stuff
;stick your data structure into the UValue of the TLB widget
WIDGET_CONTROL, tlb, SET_UVALUE=info, /NO_COPY
;call x manager and your done here
end
You'll want to look at the IDl docs to understand the /NO_COPY keyword.
Basically it forces widget_control when getting uvalues to "detach" your
data from the source (in our case the UValue of the tlb widget) instead
of making a copy of the data. This is generally preferred but your
UValue becomes undefined and if you don't "reattach" your data to it
using Set_Uvalue the next time you try to get the UValue of your tlb it
will be undefined.
Clear as mud? Hopefully this will at least get you started.
You might want to pillage David's website/FTP server for example code.
He has a bunch of simpler widget programs that are well commented.
http://www.dfanning.com
-Rick Towler
hom@sask.usask.ca wrote:
>
> Is there a way to pass values between event procedures?
>
> I want several values to be carried and modified throughout my GUI
> application.
>
> When just coding, I use a main program. When using GUI's, where is the
> "main program"?
>
> I would really appreciate any help!!