我担心我的应用程序堆积事件,我想知道是否有一种方法可以监视当前事件队列中的事件数量。像pendingEvents = wx.GetEvents()
之类的东西,或者可能获得当前待定的特定类型的事件。即pendingFooEvents = wx.GetEvents('EVT_FOO')
。
下面是一些虚拟代码,当我点击一个按钮时会发布几个事件,然后打印输出以便我可以监控。有一个睡眠声明,以便他们不会立即完成。我想知道我的程序是否有一种方式可以识别这些事件已经发布,但它们还没有完成。
import wx
import wx.lib.newevent
import threading
import time
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, pos=(150, 150), size=(350, 200))
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
m_text = wx.StaticText(panel, -1, "Hello World!")
m_text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text.SetSize(m_text.GetBestSize())
box.Add(m_text, 0, wx.ALL, 10)
m_foo = wx.Button(panel, -1, "Foo")
m_foo.Bind(wx.EVT_BUTTON, self.OnPostEvent)
box.Add(m_foo, 0, wx.ALL, 10)
panel.SetSizer(box)
panel.Layout()
self.fooEvent, EVT_FOO = wx.lib.newevent.NewEvent()
self.Bind(EVT_FOO, self.MyEvent)
def OnPostEvent(self, event):
thread0 = threading.Thread(target=self.PostThings, args=(0,))
thread1 = threading.Thread(target=self.PostThings, args=(1,))
thread2 = threading.Thread(target=self.PostThings, args=(2,))
thread0.start()
thread1.start()
thread2.start()
def PostThings(self, arg):
wx.PostEvent(self, self.fooEvent(foo=arg))
def MyEvent(self, event):
time.sleep(1)
print(event.foo)
app = wx.App() # Error messages go to popup window
top = Frame("<<project>>")
top.Show()
app.MainLoop()