|
Re: xmanager to call object methods? [message #39127 is a reply to message #39118] |
Wed, 21 April 2004 08:16  |
mmiller3
Messages: 81 Registered: January 2002
|
Member |
|
|
>>>> > "Oliver" == Oliver Thilmann <justspam03@yahoo.de> writes:
> Hi, is there any generic way to handle events via objects,
> i.e. make xmanager (or something like it) call an object
> method instead of a function or procedure?
> The reason is that in my current design, I use the uvalue
> of evt.top to store a reference to the object currently
> handling UI input in the respective window and then call
> the event-handler of that object from an intermediate
> function. Alas, that's not possible in all cases. Without
> going into details: I ended up trying to pull myself out of
> the swamps by my own hair as Munchhausen did.
There is generic_class_event in the RSI user-contrib ligbrary
http://www.rsinc.com/codebank/search.asp?FID=209 . (and I'll
stick a copy below...)
Mike
--
Michael A. Miller mmiller3@iupui.edu
Imaging Sciences, Department of Radiology, IU School of Medicine
;+
; This routine is called when an event occurs in any object-based TLB.
; In turn, the ::EVENT method of the class whose object reference is
; stored in the EVENT.HANDLER's UVALUE is called.
;
; @Param
; Event {in}{required}{type=structure}
; Any sort of IDL GUI event
;
; @Examples
; <pre>
; Widget_Control, TLB, Set_UValue = self, Event_Pro = 'Generic_Class_Event' <br>
; XMANAGER, 'GENERIC_CLASS', TLB
; </pre>
;
; @History
; June, 2001 : JLP, RSI
;-
Pro Generic_Class_Event, Event
COMPILE_OPT STRICTARR
Widget_Control, Event.Handler, Get_UValue = oSelf
If (N_elements(oSelf) eq 1) then Begin
If (Obj_Valid(oSelf)) then Begin
;
; A class that uses this routine must have a method
; named "::EVENT".
;
oSelf->Event, Event
EndIf
EndIf
End
|
|
|
Re: xmanager to call object methods? [message #39129 is a reply to message #39127] |
Wed, 21 April 2004 06:31  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Oliver Thilmann writes:
> is there any generic way to handle events via objects, i.e.
> make xmanager (or something like it) call an object method
> instead of a function or procedure?
In simple widget/object systems I often write a single
EVENT_DISPATCHER procedure for the widget program. The
purpose of this program is to input all widget events
generated by the program and dispatch them to the
appropriate object handler method. The "appropriate"
method is determined by reading the user value of the
widget generating the event. I have either stored
an object reference there, or (more often) I have
stored an object reference and the name of a particular
object method to be called for that object. I use
CALL_METHOD to pass the widget event information
on to the object method.
This makes the EVENT_DISPATCHER easy to write, just
a couple of lines, and it means I can write object
handler methods in exactly the same way I previously
wrote event handler procedures and functions. All I
have to remember to do is fill out the user value of
each widget in my program that is going to generate
an event with the appropriate information.
This is basically what I do in more complex systems
like my Catalyst Object Library, too. Although there,
since every widget is itself an object, the process
of assigning an event handler method, etc. is automated
and completely transparent to the end user. Event
handler methods (other than the default one) can be
assigned by means of an EVENT_HANDLER keyword, in exactly
the same way widgets use EVENT_PRO and EVENT_FUNC.
Even nicer, in this system, the EVENT_DISPATCHER has
replaced the ID, TOP, and HANDLER widget identifier
fields of the event structure with object references
to the ID, TOP, and HANDLER objects. This means that
once a widget event has been dispatched, I don't
ever have to be concerned with widget identifiers.
All interaction proceeds by means of consistent
object calls. In some ways, this makes the system
easier to use than straight widget programming.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|