Hello all,
I have recently upgraded an application to wxPython 2.5.3.1 (ansi) and hit a large snag:
I need to interleave the wx event system with calls to another component's. I used to do this by replacing app.MainLoop() with:
while not app.isDone:
while app.Pending(): app.Dispatch()
othercomponent.doStuff()
But now this no longer works (in my app the window is created and the mouse works, but there is no keyboard input. In a simpler test app the window components never even become visible).
Is there still a method of avoiding MainLoop I can use?
Failing that, I have hacked out a workaround by calling MainLoop and then using wx.FutureCall with a 1ms timeout and a Restart() inside the callback - which then executes my other component. Is there a faster/better method I can use?
TIA for any help,
Mike
Mike,
I have my own hack-like controllable event loop for unittesting purposes. It
does not fit your need but can give (maybe) some ideas. Here is my function:
def loop( delay=0 ):
app = wx.GetApp()
if app is None:
return
if delay == 0:
while True:
wx.CallAfter( app.ExitMainLoop )
app.MainLoop()
if not app.Pending():
break
else:
wx.FutureCall( delay, app.ExitMainLoop )
app.MainLoop()
···
------------------------------
Vladimir Ignatov,
KMI Software
Thanks Vladimir,
I also just found this: http://cvs.wxwidgets.org/viewcvs.cgi/wxWidgets/wxPython/samples/mainloop/mainloop.py?rev=1.1&content-type=text/vnd.viewcvs-markup
(and ActiveState Community - Boosting coder and team productivity with ready-to-use open source languages and tools. from just two weeks ago...)
Anyway, so a cleanish solution is:
class MyApp(wx.App):
def MainLoop(self):
evtloop = wx.EventLoop()
wx.EventLoop.SetActive(evtloop)
while not self.done:
while evtloop.Pending(): evtloop.Dispatch()
myothercomponents.doStuff()
...
gui=MyApp()
gui.MainLoop()
best wishes
Mike
Vladimir Ignatov wrote:
···
Mike,
I have my own hack-like controllable event loop for unittesting purposes. It
does not fit your need but can give (maybe) some ideas. Here is my function:
def loop( delay=0 ):
app = wx.GetApp()
if app is None:
return
if delay == 0:
while True:
wx.CallAfter( app.ExitMainLoop )
app.MainLoop()
if not app.Pending():
break
else:
wx.FutureCall( delay, app.ExitMainLoop )
app.MainLoop()
------------------------------
Vladimir Ignatov,
KMI Software
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org