Re: setting widget " EVENT_PRO='myClass::myCallback' " ???? Is it possible? [message #83974] |
Mon, 15 April 2013 17:10 |
justin.mikell
Messages: 5 Registered: May 2009
|
Junior Member |
|
|
On Monday, April 15, 2013 1:04:03 PM UTC-5, fawltyl...@gmail.com wrote:
> On Monday, April 15, 2013 8:00:43 PM UTC+2, fawltyl...@gmail.com wrote:
>
>
>
>> Hi,
>
>>
>
>> IDL calls the event handler with one positional parameter, event.
>
>>
>
>> PRO jkcm_window_level_widget_wwEventHandler, event
>
>>
>
>> one positional parameter: event
>
>>
>
>> PRO jkcm_window_level_widget::wwEventHandler, event
>
>>
>
>> two positional parameters: this (implicit) and event
>
>>
>
>
>
> Well, this 'this' is self, of course :-)
Thanks for reminding me of the implicit 'this/self' that is passed along when calling a class method.
|
|
|
Re: setting widget " EVENT_PRO='myClass::myCallback' " ???? Is it possible? [message #83977 is a reply to message #83974] |
Mon, 15 April 2013 11:39  |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
Justin writes:
>
> I have been unable to set EVENT_PRO to a class method. My current work around is to create a dummy 'global' standalone function at the top of the *__DEFINE.pro file that pulls the object data and then calls the method on the object. I was curious if it is even possible to set a widget event handler to a class method.
Yes, the general approach is to have a single event handler (I call it an event dispatcher) that accepts all program events and dispatches them to the correct event handler method. How you determine the "correct" event handler method is up to you. I generally use some combination of the user value (UVALUE) or user name (UNAME) value of the widget that is causing the event (or sometimes its parent). The dispatching event handler simply calls Call_Method on the self object (stored in the UVALUE of the TLB or anywhere else where you can find it) with the name of the desired event handler method.
This works great, but requires you do the same thing with callback routines like CLEANUP, KILL_NOTIFY, etc. It can be a hassle, but the benefits of object-widgets often outweighs it.
> What is the rationale behind not letting an event handler be a class method? Perhaps it doesn't make sense to do it...
Rationale!? You are using the wrong language. Maybe there will be a rationale with the new widget set, due out soon, I should think. :-)
Cheers,
David
|
|
|
Re: setting widget " EVENT_PRO='myClass::myCallback' " ???? Is it possible? [message #83978 is a reply to message #83977] |
Mon, 15 April 2013 11:04  |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Monday, April 15, 2013 8:00:43 PM UTC+2, fawltyl...@gmail.com wrote:
> Hi,
>
> IDL calls the event handler with one positional parameter, event.
>
> PRO jkcm_window_level_widget_wwEventHandler, event
>
> one positional parameter: event
>
> PRO jkcm_window_level_widget::wwEventHandler, event
>
> two positional parameters: this (implicit) and event
>
Well, this 'this' is self, of course :-)
|
|
|
Re: setting widget " EVENT_PRO='myClass::myCallback' " ???? Is it possible? [message #83979 is a reply to message #83978] |
Mon, 15 April 2013 11:00  |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
Hi,
IDL calls the event handler with one positional parameter, event.
PRO jkcm_window_level_widget_wwEventHandler, event
one positional parameter: event
PRO jkcm_window_level_widget::wwEventHandler, event
two positional parameters: this (implicit) and event
regards,
Lajos
On Monday, April 15, 2013 7:39:55 PM UTC+2, Justin wrote:
> Hi all,
>
>
>
> I have been unable to set EVENT_PRO to a class method. My current work around is to create a dummy 'global' standalone function at the top of the *__DEFINE.pro file that pulls the object data and then calls the method on the object.
>
>
>
> I was curious if it is even possible to set a widget event handler to a class method. What is the rationale behind not letting an event handler be a class method? Perhaps it doesn't make sense to do it...
>
>
>
>
>
> For example,
>
> below is a window/level class that ends up modifying the window/level on a display object that I create. I've been using it for medical imaging.
>
>
>
> ------------------------------------------------------------ --------
>
> PRO jkcm_window_level_widget_wwEventHandler, event
>
> widget_control, event.top, get_uvalue=obj
>
> obj->wwEventHandler, event
>
> END
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;
>
> PRO jkcm_window_level_widget_wlEventHandler, event
>
> widget_control, event.top, get_uvalue=obj
>
> obj->wlEventHandler, event
>
> END
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;
>
> PRO jkcm_window_level_widget::CREATE_WIDGETS, PARENT_WIDGET = inp_PARENT_WIDGET
>
>
>
>
>
> self.parent_widget = (N_ELEMENTS(inp_PARENT_WIDGET) NE 0) ? inp_PARENT_WIDGET : WIDGET_BASE(COLUMN=2, YSIZE=512, TLB_FRAME_ATTR=2)
>
>
>
> ;I would like to be able to say:
>
> ; EVENT_PRO='jkcm_window_level_widget::wwEventHandler'
>
> self.wwSlider = WIDGET_SLIDER(self.parent_widget, UNAME='WW_widget', YSIZE=512,$
>
> TITLE='WW', /VERTICAL, EVENT_PRO='jkcm_window_level_widget_wwEventHandler', $
>
> MINIMUM=0, MAXIMUM=4095, /DRAG)
>
>
>
> self.wlSlider = WIDGET_SLIDER(self.parent_widget, UNAME='WL_widget',YSIZE=512,$
>
> TITLE='WL', /VERTICAL, EVENT_PRO='jkcm_window_level_widget_wlEventHandler', $
>
> MINIMUM=-1024, MAXIMUM=4095, /DRAG)
>
>
>
> END ;jkcm_window_level_widget::CREATE_WIDGETS
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
>
> ...
>
>
>
> PRO jkcm_window_level_widget::wwEventHandler, event
>
>
>
> val=''
>
> widget_control, self.wwSlider, GET_VALUE=val
>
> self.svo->SET_WINDOW_LEVEL, WIDTH=val
>
>
>
> END ;jkcm_window_level_widget::wwEventHandler
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;
>
>
>
> PRO jkcm_window_level_widget::wlEventHandler, event
>
>
>
> val=''
>
> widget_control, self.wlSlider, GET_VALUE=val
>
> self.svo->SET_WINDOW_LEVEL, LEVEL=val
>
>
>
> END ;jkcm_window_level_widget::wlEventHandler
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;
>
> FUNCTION jkcm_window_level_widget::INIT, SVO=inp_SVO
>
>
>
> self.svo = (N_ELEMENTS(inp_svo) NE 0) ? inp_svo : !NULL
>
>
>
> self->CREATE_WIDGETS
>
> RETURN, 1
>
> END
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;
>
> PRO jkcm_window_level_widget::CLEANUP
>
>
>
> widget_control, self.parent_widget, /destroy
>
>
>
> END
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;
>
> PRO jkcm_window_level_widget__DEFINE
>
>
>
>
>
> struct = { jkcm_window_level_widget , $
>
> parent_widget:0L,$ ;'top' level widget
>
> wwSlider:0L, $; widget slider for window width
>
> wlSlider:0L, $; widget slider for window level
>
>
>
> svo:OBJ_NEW(), $;reference to single_view_obj_graphics object (dont delete)
>
>
>
> ww: double(1), $ ;window width
>
> wl: double(1) $ ;window length
>
> }
>
> END ;END jkcm_window_level_widget__DEFINE
|
|
|