[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objects and Widgets



Mark Guagenti (mgenti@evansville.net) writes:

> I am trying to learn how to use objects and widgets together and I have
> ran across a question for all of you.  When I am creating a widget button
> such as:
> 
> openID = Widget_Button(fileID, Value='Open...', Event_Pro='XPU_RI_Open')
> 
> Do I have to make a procedure XPU_RI_Open such as:
> 
> PRO XPU_RI_Open, event
> 	Widget_Control, event.top, Get_UValue=info, /No_Copy
> 	
> 	info.obj->open
> 	
> 	Widget_Control, event.top, Set_UValue=info, /No_Copy
> END
> 
> How come you can't call the object method directly from Event_Pro?  

How come pigs is purple and my girlfriends don't love me no more?
It just is, is why.

> I will be using a lot of methods. Will I always have to make a procedures 
> to call them? 

You will unless you can figure out a way to be clever. :-)

I like to write my event handler "methods" to accept a single
positional parameter--the event structure--just like I write
my event handlers. Then, for every widget that is going to
generate an event in my object widget program, I fill the
user value of the widget with a simple structure containing
the object reference and the event handler method to call.
It looks like this:

   openID = Widget_Button(menuID, Value='Open File...', $
      UValue={object:self, method:'Open'})
   quitID = Widget_Button(menuID, Value='Quit', $
      UValue={object:self, method:'Quit'})

All my events go to one giant event handler. (I learned this
from Stein Vidar. :-) And I write the event handler like this:

   PRO Handle_All_Events, event
   Widget_Control, event.id, Get_UValue=info
   Call_Method, info.method, info.object, event
   END

Pretty clever, huh? I always use the same event handler, so I never
have to write it over. And my object methods are written essentially
like my event handler procedures. :-)

Cheers,

David
-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155