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:
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?
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).
Because calling ProcessEvent only sends the wxEvent to the wx classes. It does not cause it to get turned back into the native event and forwarded on to the native widget as if it was originally sent there. The only way to do that is to call the native API that does it, such as SendMessage on Windows. OTOH, if you use generic widgets then sending them a wx event like this can be done to simulate events.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Because calling ProcessEvent only sends the wxEvent to the wx classes.
It does not cause it to get turned back into the native event and
forwarded on to the native widget as if it was originally sent there.
The only way to do that is to call the native API that does it, such as
SendMessage on Windows.
If I can't distribute an event to the appropriate control under wxPython,
then I can't use CaptureMouse. A mouse click outside the popup window
meant to dismiss the popup window will get picked up by some other control.
I suppose that I will have to add an event handler to the uber parent in
which I check whether the popup is visible and hide it if it is. If it is
not, then perhaps event.Skip() will resume normal propagation of the mouse
click. I don't like this solution because the top-level window has to know
about this control.
OTOH, if you use generic widgets then sending
them a wx event like this can be done to simulate events.
Is that a useful capability? To me it seems as if it would be more useful
for ProcessEvent to propagate the native event as well, but then I have my
nose pressed against this problem.
To me it seems as if it would be more useful
for ProcessEvent to propagate the native event as well, but then I have my
nose pressed against this problem.
Yes it would be very useful, but probably also very difficult to do and to get right for each platform.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!