Răsfoiți Sursa

Added support for wxPython

Gyedo Jeon 17 ani în urmă
părinte
comite
0268785c91
2 a modificat fișierele cu 28 adăugiri și 3 ștergeri
  1. 13 3
      direct/src/showbase/ShowBase.py
  2. 15 0
      direct/src/showbase/WxGlobal.py

+ 13 - 3
direct/src/showbase/ShowBase.py

@@ -2215,6 +2215,14 @@ class ShowBase(DirectObject.DirectObject):
     def finalizeExit(self):
         sys.exit()
 
+    # [gjeon] start wxPyhton
+    def startWx(self, fWantWx = 1):
+        self.wantWx = fWantWx
+        if self.wantWx:
+            import WxGlobal
+            taskMgr.remove('wxLoop')
+            WxGlobal.spawnWxLoop()
+
     def startTk(self, fWantTk = 1):
         self.wantTk = fWantTk
         if self.wantTk:
@@ -2222,8 +2230,9 @@ class ShowBase(DirectObject.DirectObject):
             taskMgr.remove('tkLoop')
             TkGlobal.spawnTkLoop()
 
-    def startDirect(self, fWantDirect = 1, fWantTk = 1):
+    def startDirect(self, fWantDirect = 1, fWantTk = 1, fWantWx = 0):
         self.startTk(fWantTk)
+        self.startWx(fWantWx)
         self.wantDirect = fWantDirect
         if self.wantDirect:
             from direct.directtools import DirectSession
@@ -2236,13 +2245,14 @@ class ShowBase(DirectObject.DirectObject):
             return
         self.__directStarted = False
         
-        # Start Tk and DIRECT if specified by Config.prc
+        # Start Tk, Wx and DIRECT if specified by Config.prc
         fTk = self.config.GetBool('want-tk', 0)
+        fWx = self.config.GetBool('want-wx', 0)
         # Start DIRECT if specified in Config.prc or in cluster mode
         fDirect = (self.config.GetBool('want-directtools', 0) or
                    (self.config.GetString("cluster-mode", '') != ''))
         # Set fWantTk to 0 to avoid starting Tk with this call
-        self.startDirect(fWantDirect = fDirect, fWantTk = fTk)
+        self.startDirect(fWantDirect = fDirect, fWantTk = fTk, fWantWx = fWx)
 
     def profileFrames(self, num=1):
         # profile the next 'num' frames and log the results

+ 15 - 0
direct/src/showbase/WxGlobal.py

@@ -0,0 +1,15 @@
+import wx
+from direct.task.Task import Task
+
+def wxLoop(self):
+    # Do all the wxPython events waiting on this frame
+    while base.wxApp.Pending():
+        base.wxApp.Dispatch()
+    return Task.cont
+
+def spawnWxLoop():
+    if hasattr(base, 'wxApp') and base.wxApp:
+        base.wxApp.Exit()
+    base.wxApp = wx.App(False)
+    # Spawn this task
+    taskMgr.add(wxLoop, "wxLoop")