Here is the sample code (If it didn't come out right: I had trouble figuring out the code block system for the forum):
Code: Select all
import wx
class MainFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title,
wx.DefaultPosition, wx.Size(200, 100))
Panel = wx.Panel(self, -1)
TopSizer = wx.BoxSizer(wx.VERTICAL)
Panel.SetSizer(TopSizer)
Text = wx.TextCtrl(Panel, -1, "Type text here")
TopSizer.Add(Text, 1, wx.EXPAND)
Text.Bind(wx.EVT_KEY_DOWN,self.OnKeyText)
Text.Bind(wx.EVT_KEY_DOWN, self.OnKeyText2)
def OnKeyText(self, event):
print "OnKeyText"
event.Skip()
def OnKeyText2(self, event):
print "OnKeyText2"
event.Skip()
class MyApp(wx.App):
def OnInit(self):
Frame = MainFrame(None, -1, "Event Order Demo")
Frame.Show(True)
self.SetTopWindow(Frame)
return True
if __name__ == '__main__':
App = MyApp(0)
App.MainLoop()
Even though I understand this, it has become a real pain in my application because I have subclasses of a class where the base class functions bind some events, then the subclasses bind their additional events afterwords.
I feel like the events get put into the "event stack" backwards (bind the event you want to have happen last first). Is there a way to have the events append to the "event stack" and not be inserted in the beginning?
If I am misunderstanding the event.Skip() command or am missing something, please let me know! Is there a better way to do what I am trying to do? I don't want to have the events strung together (For example: have OnKeyText(), once done, call OnKeyText2()) because in my app one of the event handlers is shared by all subclasses and the other is not.
If the answer is that "it just needs to be done in reverse order" then I will have to accept that and make the changes to my app.
If the answer is that I should use event propagation between the control and the panels to control the order of event handlers, I feel like I run into the same problem unless I keep the number of event handlers to one for each propagation level.
Thanks in advance! Benjamin