Re: Tip for using Compound Widgets [message #31682] |
Mon, 05 August 2002 19:04  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
M. Katz writes:
> Since I'm over 30, I'm still getting used to object programming. I'm
> using it all the time for creating complicated graphics and even for
> the file-output tasks, but it's still "new" to me.
Over 30!? I can only imagine. :-)
> The idea of the compound widget is that we create something new that
> behaves like one of the basic elemental widgets. I can see making the
> leap to objects in several ways, and I'm interested to hear how you'd
> recommend doing it. (Have you written any tips for it on your site?)
Have a look a FSC_FIELD. That is a compound widget that is written
as an object.
http://www.dfanning.com/programs/fsc_field.pro
> When using a compound widget, one accesses the child widgets through
> the parent. That includes events and SET/GET_VALUE. That's the issue I
> was trying to solve: making SET_VALUE more intelligently access the
> functions of the compund widget.
>
> So, in an object widget, (here's where I'm guessing) one doesn't need
> the compound widget formalism. You create an object that knows all
> about the children and dispense completely with
>
> widget_control, SET_VALUE=... in favor of
> widget_obj -> Do_Something, arg
That is right, exactly!
> But what exactly happens to events?
I have an "event handler" for the compound widget (same as in
widgets), but any widget that generates events has a structure
in its UVALUE that has an "object" field and a "method" field.
For example, here is a quit button (in another program, not
FSC_FIELD):
button = Widget_Button(bbase, Value='Quit', $
UVALUE={object:self, method:'Quit'})
All the event handler does is get the user value and dispatch the
event to this method of this object:
PRO EVENTHANDLER, event
Widget_Control, event.id, Get_UValue=cmd
Call_Method, cmd.object, cmd.method, event
END
I use the EVENTHANDLER to handle *all* object widget events.
The objects and methods vary, of course. The methods are written
*exactly* like previous event handler procedures, except they
don't have to have the info structure, since the info structure
*is* the object!
> Does it take a lot longer to program the object widget than the
> equivalanet compound widget?
No, about the same amount of time.
> Is there a template that's been published that other people follow, so
> object newbies don't have to re-invent the wheel? Does RSI have
> anything to say about the subject, as they do for compound widgets?
I don't know if RSI has anything to say about the subject.
Some of those guys write nice object code, however. I've
learned a lot by studying it. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-Mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|