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

Re: Throwing Widget Events?



Richard Tyc (richt@sbrc.umanitoba.ca) writes:

> Is there a way to throw widget events ?  

Of course:

   Widget_Control, widgetToGetEvent, Send_Event=yourEvent

> I know of checking for received
> events with WIDGET_EVENT while your busy in some function (I use this for
> Emergency Stop buttons) but how could one widget program (a child of the
> main parent widget program) initiate an event on its parent's event loop ?

You could, for example, look at how my program XCOLORS lets the
program that called it know that some new color tables were loaded,
so that the calling program can update its display, capture the
new color vectors, etc.

It works via a NOTIFYID keyword:

   XColors, NotifyID=[widgetID_1, widgetID_2]

When XColors loads a color table it looks to see if there
is a widget to notify. If there is, it constructs an
XCOLORS_LOAD event structure, like this:

   myEvent = { XCOLORS_LOAD, $
               ID: widgetID_1, $
               TOP: widgetID_2, $
               HANDLER: 0L, $
               R:R, G:G, B:B, Index:index, Name:name }

where most of the fields deal with the color vectors, and
the index and name of the color table you just loaded.

It then sends the event like this:

   IF Widget_Info(widgetID_1, /Valid_ID) THEN $
      Widget_Control, widgetID_1, Send_Event=myEvent

Since this is like any other event, IDL will fill out the
proper HANDLER field for me. I just have to save space for
it. The widgetID_1 event handler has to expect this event,
but once it gets it, it can do whatever it likes with it.


> While we are at it, what mechanism is there to let a parent application know
> its child programs are dead (or user clicked window close).

I would use a Kill_Notify on the widget you are concerned about.
In the Kill_Notify procedure, you could do the same thing as
above and send an event to the parent indicating you are dying:

   deathNotice = { AAAAHHHHHAAA, $
                   ID:widgetID_1, $
                   TOP: widgetID_2, $
                   HANDLER: 0L, $
                   widgetWhoIsDying: widgetWhoIsDying, $
                   message: "I love you!!!" }

   IF Widget_Info(widgetID_1, /Valid_ID) THEN $
      Widget_Control, widgetID_1, Send_Event=deathNotice


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