Propagating event to controls on a popup window

Jeffrey Barish jeff_barish at earthlink.net
Tue Feb 13 15:32:56 PST 2007


My application has a popup window that appears in response to a left mouse
click on a static bitmap.  I dismiss the popup window by clicking anywhere
outside the popup window.  When I click on one of the controls inside the
popup window, I would like to actuate the control, but I haven't been able
to make that happen.  The complication is that to make it possible to
dismiss the popup window by clicking anywhere outside the popup window, the
popup window has to capture the mouse, so clicks inside the window also go
to the popup window, not the controls.  The event handler for the popup
window checks to see whether the position of the event is outside the rect
of the popup window.  If it is, it hides the popup window.  However, it
isn't clear what it should do with the event when the event's position is
inside the popup window.

Here's what I tried:

# Event handler for the main panel on the popup window.
def _onLeftDown(self, event):
    pos = event.GetPosition()
    if self.popupwin.IsShown():
        pos = event.GetPosition()
        if not self.popuppan.GetRect().Contains(pos):
            self.popuppan.ReleaseMouse()
            self.popupwin.Show(False)
        elif self.control1.GetRect().Contains(pos):
            self.control1.SetEvtHandlerEnabled(True)
            self.control1.ProcessEvent(event)

I disable event processing for the control as soon as I create it.  That
way, I can be sure that the EVT_LEFT_DOWN will go to the popup window's
panel first.  If the position of the mouse event corresponds to the
position of control1, then I enable event processing and process the event. 
I do reach the event handler for control1, but I don't get the default
action for the control (e.g., the button doesn't actually get pushed).  The
event handler contains only event.Skip().  I thought that there might be
some information in the event that tells the event handler that the event
was not targeted to this control, so I tried adding:

event.SetEventObject(self.control1)
event.SetId(self.control1.GetId())

but I still don't get the default behavior for control1.  I suspect that
there are other attributes that tell the control to ignore this event.  Any
idea what I have missed?
--- 
Jeffrey Barish





More information about the wxpython-users mailing list