Pārlūkot izejas kodu

remove-callback-window

David Rose 14 gadi atpakaļ
vecāks
revīzija
38de5011e1
2 mainītis faili ar 27 papildinājumiem un 20 dzēšanām
  1. 6 3
      direct/src/showbase/ShowBase.py
  2. 21 17
      direct/src/wxwidgets/WxPandaWindow.py

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

@@ -792,12 +792,14 @@ class ShowBase(DirectObject.DirectObject):
 
         return win
 
-    def closeWindow(self, win, keepCamera = 0):
+    def closeWindow(self, win, keepCamera = False, removeWindow = True):
         """
         Closes the indicated window and removes it from the list of
         windows.  If it is the main window, clears the main window
         pointer to None.
         """
+        win.setActive(False)
+        
         # First, remove all of the cameras associated with display
         # regions on the window.
         numRegions = win.getNumDisplayRegions()        
@@ -838,7 +840,8 @@ class ShowBase(DirectObject.DirectObject):
                 self.winControls.remove(winCtrl)
                 break
         # Now we can actually close the window.
-        self.graphicsEngine.removeWindow(win)
+        if removeWindow:
+            self.graphicsEngine.removeWindow(win)
         self.winList.remove(win)
 
         mainWindow = False
@@ -896,7 +899,7 @@ class ShowBase(DirectObject.DirectObject):
         which case base.win may be either None, or the previous,
         closed window).
         """
-        keepCamera = kw.get('keepCamera', 0)
+        keepCamera = kw.get('keepCamera', False)
         
         success = 1
         oldWin = self.win

+ 21 - 17
direct/src/wxwidgets/WxPandaWindow.py

@@ -54,13 +54,12 @@ class EmbeddedPandaWindow(wx.Window):
         event.Skip()
 
     def cleanup(self):
-        """ Parent windows should call cleanp() to clean up the
+        """ Parent windows should call cleanup() to clean up the
         wxPandaWindow explicitly (since we can't catch EVT_CLOSE
         directly). """
         if self.win:
             base.closeWindow(self.win)
             self.win = None
-        self.Destroy()
 
     def onSize(self, event):
         wp = WindowProperties()
@@ -77,6 +76,8 @@ else:
         within the wx GLCanvas object.  It is supported whenever OpenGL is
         Panda's rendering engine, and GLCanvas is available in wx. """
 
+        removeCallbackWindow = ConfigVariableBool('remove-callback-window', True)
+
         Keymap = {
             wx.WXK_BACK : KeyboardButton.backspace(),
             wx.WXK_TAB : KeyboardButton.tab(),
@@ -204,13 +205,15 @@ else:
             event.Skip()
 
         def cleanup(self):
-            """ Parent windows should call cleanp() to clean up the
+            """ Parent windows should call cleanup() to clean up the
             wxPandaWindow explicitly (since we can't catch EVT_CLOSE
             directly). """
             if self.win:
-                base.closeWindow(self.win)
+                self.win.clearEventsCallback()
+                self.win.clearPropertiesCallback()
+                self.win.clearRenderCallback()
+                base.closeWindow(self.win, removeWindow = self.removeCallbackWindow)
                 self.win = None
-            self.Destroy()
 
         def __buttonDown(self, button):
             self.inputDevice.buttonDown(button)
@@ -304,7 +307,7 @@ else:
             event.Skip()
 
         def onPaint(self, event):
-            """ This is called whenever we get the fisrt paint event,
+            """ This is called whenever we get the first paint event,
             at which point we can conclude that the window has
             actually been manifested onscreen.  (In X11, there appears
             to be no way to know this otherwise.) """
@@ -315,17 +318,18 @@ else:
             #event.Skip()
 
         def onIdle(self, event):
-            size = None
-            properties = self.win.getProperties()
-            if properties.hasSize():
-                size = (properties.getXSize(), properties.getYSize())
-
-            if tuple(self.GetClientSize()) != size:
-                # The window has changed size during the idle call.
-                # This seems to be possible in Linux.
-                wp = WindowProperties()
-                wp.setSize(*self.GetClientSize())
-                self.win.requestProperties(wp)
+            if self.win:
+                size = None
+                properties = self.win.getProperties()
+                if properties.hasSize():
+                    size = (properties.getXSize(), properties.getYSize())
+
+                if tuple(self.GetClientSize()) != size:
+                    # The window has changed size during the idle call.
+                    # This seems to be possible in Linux.
+                    wp = WindowProperties()
+                    wp.setSize(*self.GetClientSize())
+                    self.win.requestProperties(wp)
 
             event.Skip()