Reputation: 151
I want to invoke OnstaticDown
, and use event.Skip()
to invoke it's parent widget onPanelDown
.
But only OnstaticDown
is invoked, and I don't understand why. Why isn't static
s parent panel receiving the event?
My code:
self.panel.Bind(wx.EVT_LEFT_DOWN,self.onPanelDown)
self.static = wx.StaticText(self.panel, wx.NewId(), "First Name",pos=(10, 50),size=(100,100))
self.static.Bind(wx.EVT_LEFT_DOWN, self.OnstaticDown)
def onPanelDown(self,event):
print 'panel-------------22'
def OnstaticDown(self,event):
print 'static============11'
event.Skip()
Upvotes: 3
Views: 2512
Reputation: 6730
event.Skip()
will invoke the controls default handler (ie StaticText). I don't believe static text has a default handler, though, as it's not designed to be interacted with, it's just a label for displaying text.
you could post the event to the panel after dealing with it in static down, wx.PostEvent(self.panel,event)
or I don't think it'd be bad practice just to pass it self.onPanelDown(event)
although it wouldn't be as well suited to change.
you could always make a function to pass/post an event to the controls parent
def PostToParent(control,event):
wx.PostEvent(control.GetParent(),event)
event.Skip()
will just mark the event and allow to to propagate to other bindings after running your handler, if you dont it wont, and nothing more will happen with the event.
The most obvious example of this is if you close a window the frame emits an EVT_CLOSE
event which wx will pick up and close the window. If you bind a method to EVT_CLOSE
it will trigger before the underlying wx event handler. If you don't call event.Skip
the event will never get to the wx handler and the frame wont close when you try to close it, but if you do call event.Skip
it will get handled by the wx event handler after yours, and close the frame.
wx.PostEvent
on the other hand is a way to send an event to a specific widget, and have any bindings bound to that specific event, process the event. In this case forwarding on the left down event to the panel has the same effect as clicking on the panel yourself.
Upvotes: 4