From fb71b744a998cc6f0c943ed09f505343ee453d07 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 16 Jan 2012 01:56:48 +0000 Subject: [PATCH] add wx-main-loop --- direct/src/showbase/ShowBase.py | 41 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 5540f8d485..35e0568a80 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -2736,17 +2736,38 @@ class ShowBase(DirectObject.DirectObject): # Create a new base.wxApp. self.wxApp = wx.PySimpleApp(redirect = False) - # Set a timer to run the Panda frame 60 times per second. - self.wxTimer = wx.Timer(self.wxApp) - self.wxTimer.Start(1000.0/60.0) - self.wxApp.Bind(wx.EVT_TIMER, self.__wxTimerCallback) + if ConfigVariableBool('wx-main-loop', True): + # Put wxPython in charge of the main loop. It really + # seems to like this better; some features of wx don't + # work properly unless this is true. + + # Set a timer to run the Panda frame 60 times per second. + self.wxTimer = wx.Timer(self.wxApp) + self.wxTimer.Start(1000.0/60.0) + self.wxApp.Bind(wx.EVT_TIMER, self.__wxTimerCallback) - # wx is now the main loop, not us any more. - self.run = self.wxRun - self.taskMgr.run = self.wxRun - __builtin__.run = self.wxRun - if self.appRunner: - self.appRunner.run = self.wxRun + # wx is now the main loop, not us any more. + self.run = self.wxRun + self.taskMgr.run = self.wxRun + __builtin__.run = self.wxRun + if self.appRunner: + self.appRunner.run = self.wxRun + + else: + # Leave Panda in charge of the main loop. This is + # friendlier for IDE's and interactive editing in general. + def wxLoop(task): + # First we need to ensure that the OS message queue is + # processed. + base.wxApp.Yield() + + # Now do all the wxPython events waiting on this frame. + while base.wxApp.Pending(): + base.wxApp.Dispatch() + + return task.again + + taskMgr.add(wxLoop, 'wxLoop') def __wxTimerCallback(self, event): if Thread.getCurrentThread().getCurrentTask():