Просмотр исходного кода

invert the WxGlobal loop: now wx owns the main loop, it seems to like that a lot better.

David Rose 14 лет назад
Родитель
Сommit
93d625845c

+ 27 - 1
direct/src/showbase/ShowBase.py

@@ -175,6 +175,7 @@ class ShowBase(DirectObject.DirectObject):
         self.camLens = None
         self.camFrustumVis = None
         self.direct = None
+        self.wxApp = None
 
         # This is used for syncing multiple PCs in a distributed cluster
         try:
@@ -2713,7 +2714,32 @@ class ShowBase(DirectObject.DirectObject):
             if self.wantWx:
                 initAppForGui()
                 from direct.showbase import WxGlobal
-                WxGlobal.spawnWxLoop()
+                self.spawnWxLoop()
+
+    def spawnWxLoop(self):
+        if self.wxApp:
+            # Don't do this twice.
+            return
+
+        import wx
+        # 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)
+
+        # wx is now the main loop, not us any more.
+        self.run = self.wxRun
+        self.taskMgr.run = self.wxRun
+        __builtin__.run = self.wxRun
+
+    def __wxTimerCallback(self, event):
+        self.taskMgr.step()
+
+    def wxRun(self):
+        self.wxApp.MainLoop()
 
     def startTk(self, fWantTk = True):
         fWantTk = bool(fWantTk)

+ 2 - 20
direct/src/showbase/WxGlobal.py

@@ -1,22 +1,4 @@
-import wx
-from direct.task.Task import Task
-
-def wxLoop(self):
-    # 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.cont
+""" This module is now vestigial.  """
 
 def spawnWxLoop():
-    if not getattr(base, 'wxApp', None):
-        # Create a new base.wxApp, but only if it's not already
-        # created.
-        base.wxApp = wx.PySimpleApp(redirect = False)
-
-    # Spawn this task
-    taskMgr.remove('wxLoop')
-    taskMgr.add(wxLoop, "wxLoop")
+    base.spawnWxLoop()

+ 5 - 3
panda/src/event/asyncTaskChain.cxx

@@ -1268,12 +1268,14 @@ do_poll() {
     return;
   }
 
-#ifndef NDEBUG
   if (_num_busy_threads != 0) {
-    nassert_raise("You may not recursively invoke the TaskManager from within a task");
+    // We are recursively nested within another task.  Return quietly.
+    if (task_cat.is_debug()) {
+      task_cat.debug()
+        << "Ignoring recursive poll() within another task.\n";
+    }
     return;
   }
-#endif
 
   nassertv(!_pickup_mode);