I am trying to modify my app to have a variety of TopFrames and I wanted
to move everything they shared into the wxApp part of the app. The catch
is that I want to be able to process arbitrary events but the wxApp
class is not behaving as documented. The key, I think, is that
FilterEvent is not getting called though apparently these events are
getting handled somewhere. What am I missing?
Thanks,
Sam
from wxPython.wx import *
wxEVT_INVOKE = wxNewEventType()
class InvokeEvent(wxPyEvent):
def __init__(self, func, args, kwargs):
wxPyEvent.__init__(self)
self.SetEventType(wxEVT_INVOKE)
self.func = func
self.args = args
self.kwargs = kwargs
class aFrame(wxFrame):
def __init__(self, parent, id, title, func):
wxFrame.__init__(self, parent, -1, title, size = (700, 400),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
EVT_CLOSE(self, self.OnCloseWindow)
self.func = func
menuBar = wxMenuBar()
menu1 = wxMenu()
menuBar.Append(menu1,"&Something")
self.SetMenuBar(menuBar)
def OnCloseWindow(self, event):
self.Destroy()
self.func()
class anApp(wxApp):
def __init__(self):
wxApp.__init__(self)
def OnInit(self):
self.SetExitOnFrameDelete(False)
frame = aFrame(None, -1, "Test Frame", self.DoSomethingLater)
frame.Show(True)
return True
def FilterEvent(self, event):
print '.',
if event.GetEventType == wxEVT_INVOKE:
print 'Event is of EVT_INVOKE TYPE'
apply(event.func, event.args, event.kwargs)
return True
else: return -1
def invokeLater(self, func, args = [], kwargs = {}):
#self.wxPostEvent( InvokeEvent(func, args, kwargs))
print self.ProcessEvent( InvokeEvent(func, args, kwargs))
def DoSomething(self, event):
frame = aFrame(None, -1, "Test Frame 2", self.DoSomethingLater)
frame.Show(True)
self.SetTopWindow(frame)
def DoSomethingLater(self):
self.invokeLater(self.DoSomething)
def main():
print 'init'
app = anApp()
print 'loop'
app.MainLoop()
return
if __name__ == '__main__':
main()