# -.- coding:utf-8 -.-
import wx
class MyFrame(wx.Frame):
# 原意
# event.Skip() can be used inside an event handler to control
# whether further event handlers bound to this event will be
# called after the current one returns.
# 翻译:
# event.Skip() 函数 只能在 绑定了事件的函数中 使用; 例如:
# self.Third 绑定了 menuTwice 事件, 因此 self.Second 函数可以使用 event.Skip() 方法.
#
# 对于那些被多个函数绑定的事件, event.Skip() 可以在
# 执行完当前函数后继续去执行其他绑定到该事件的函数; 例如:
# menuTwice 被 self.First 和 self.Second 和 self.Third 函数 都绑定了,
# 触发 menuTwice 事件时, wxpython 只会执行 self.Third 函数,
# 因为 self.First 和 self.Second 都被 self.Third "覆盖" 了.
# 但是如果在 self.Third 中使用 event.Skip() , 那么wxpython 会在执行完
# self.Third 函数后, 继续去执行 self.Second 函数;
# 如果在 self.Second 中还调用 event.Skip(), 那么 wxpython 会在执行完
# self.Second 函数后, 继续去执行 self.First 函数.
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(400, 500))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar() # the status bar in the bottom
menuBar = wx.MenuBar()
testMenu = wx.Menu()
menuOnce = testMenu.Append(wx.ID_ANY, "Once", "print something")
menuTwice = testMenu.Append(wx.ID_ANY, "Twice",
"print something and another thing")
menuBar.Append(testMenu, "Test")
self.Bind(wx.EVT_MENU, self.First, menuOnce)
# 这里的 menuTwice 菜单被三个函数绑定.
self.Bind(wx.EVT_MENU, self.First, menuTwice)
self.Bind(wx.EVT_MENU, self.Second, menuTwice)
self.Bind(wx.EVT_MENU, self.Third, menuTwice)
self.SetMenuBar(menuBar)
self.Show(True)
def First(self, event):
print "First"
def Second(self, event):
print "Second"
event.Skip()
def Third(self, event):
print("Third")
event.Skip()
print("Third2") # 执行完当前函数后才会去执行 self.Second.
app = wx.App(False)
frame = MyFrame(None, 'Small editor')
app.MainLoop()
参考:
gizzzle的博客
wx.Event