From fcd3df851a5cdf33b0eaeecd4dee036b40db1a69 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 9 Jan 2003 20:31:14 +0000 Subject: [PATCH] preparation for new window code --- direct/src/ffi/FFIExternalObject.py | 27 +++++++++++++++++++++++ direct/src/gui/OnscreenGeom.py | 4 +++- direct/src/gui/OnscreenImage.py | 4 +++- direct/src/gui/OnscreenText.py | 4 +++- direct/src/showbase/PandaObject.py | 1 - direct/src/showbase/ShowBase.py | 33 ++++++++++++++++++++++++++++- 6 files changed, 68 insertions(+), 5 deletions(-) diff --git a/direct/src/ffi/FFIExternalObject.py b/direct/src/ffi/FFIExternalObject.py index c63d491c47..dbd26588d2 100644 --- a/direct/src/ffi/FFIExternalObject.py +++ b/direct/src/ffi/FFIExternalObject.py @@ -94,12 +94,39 @@ class FFIExternalObject: # % (downcastFuncName, globmod.__name__)) downcastFunctionList.append(func) return downcastFunctionList + + def lookUpNewType(self, typeHandle, rootType): + # We tried to downcast to an unknown type. Try to figure out + # the lowest type we *do* know, so we can downcast to that + # type instead. + if typeHandle.getNumParentClasses() == 0: + # This type has no parents! That shouldn't happen. + FFIConstants.notify.warning("Unknown class type: %s has no parents!" % (typeHandle.getName())) + return None + + parentType = typeHandle.getParentTowards(rootType, self) + parentIndex = parentType.getIndex() + parentWrapperClass = WrapperClassMap.get(parentIndex) + if parentWrapperClass == None: + parentWrapperClass = self.lookUpNewType(parentType, rootType) + + if parentWrapperClass != None: + # If the parent class is known, then record that this + # class is a derivation of that parent class. + WrapperClassMap[typeHandle.getIndex()] = parentWrapperClass + + return parentWrapperClass def setPointer(self): # See what type it really is and downcast to that type (if necessary) # Look up the TypeHandle in the dict. get() returns None if it is not there index = self.getTypeIndex() exactWrapperClass = WrapperClassMap.get(index) + if exactWrapperClass == None: + # This is an unknown class type. Perhaps it derives from + # a class type we know. + exactWrapperClass = self.lookUpNewType(self.getType(), self.getClassType()) + # We do not need to downcast if we already have the same class if (exactWrapperClass and (exactWrapperClass != self.__class__)): # Create a new wrapper class instance diff --git a/direct/src/gui/OnscreenGeom.py b/direct/src/gui/OnscreenGeom.py index d8580bd489..82a7e136d2 100644 --- a/direct/src/gui/OnscreenGeom.py +++ b/direct/src/gui/OnscreenGeom.py @@ -9,7 +9,7 @@ class OnscreenGeom(PandaObject, NodePath): hpr = None, scale = None, color = None, - parent = aspect2d, + parent = None, sort = 0): """__init__(self, ...) @@ -40,6 +40,8 @@ class OnscreenGeom(PandaObject, NodePath): """ # We ARE a node path. Initially, we're an empty node path. NodePath.__init__(self) + if parent == None: + parent = aspect2d self.parent = parent # Assign geometry self.sort = sort diff --git a/direct/src/gui/OnscreenImage.py b/direct/src/gui/OnscreenImage.py index 23849015bb..8698d89760 100644 --- a/direct/src/gui/OnscreenImage.py +++ b/direct/src/gui/OnscreenImage.py @@ -9,7 +9,7 @@ class OnscreenImage(PandaObject, NodePath): hpr = None, scale = None, color = None, - parent = aspect2d, + parent = None, sort = 0): """__init__(self, ...) @@ -40,6 +40,8 @@ class OnscreenImage(PandaObject, NodePath): """ # We ARE a node path. Initially, we're an empty node path. NodePath.__init__(self) + if parent == None: + parent = aspect2d # Assign geometry if isinstance(image, NodePath): self.assign(image.copyTo(parent, sort)) diff --git a/direct/src/gui/OnscreenText.py b/direct/src/gui/OnscreenText.py index 8c9c8a5b9c..ab16bdd322 100644 --- a/direct/src/gui/OnscreenText.py +++ b/direct/src/gui/OnscreenText.py @@ -29,7 +29,7 @@ class OnscreenText(PandaObject, NodePath): wordwrap = None, drawOrder = None, font = None, - parent = aspect2d, + parent = None, sort = 0, mayChange = 0): """__init__(self, ...) @@ -90,6 +90,8 @@ class OnscreenText(PandaObject, NodePath): created (which leads to better memory optimization). """ + if parent == None: + parent = aspect2d # make a text node textNode = TextNode('') diff --git a/direct/src/showbase/PandaObject.py b/direct/src/showbase/PandaObject.py index 38127cdc6c..ffbaa37c72 100644 --- a/direct/src/showbase/PandaObject.py +++ b/direct/src/showbase/PandaObject.py @@ -1,6 +1,5 @@ from DirectObject import * from PandaModules import * -from ShowBaseGlobal import * class PandaObject(DirectObject): """ diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 0a43953736..f152da7abe 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -22,11 +22,15 @@ import Loader import time import FSM import State +import DirectObject __builtins__["FADE_SORT_INDEX"] = 1000 __builtins__["NO_FADE_SORT_INDEX"] = 2000 -class ShowBase: +# Now ShowBase is a DirectObject. We need this so ShowBase can hang +# hooks on messages, particularly on window-event. This doesn't +# *seem* to cause anyone any problems. +class ShowBase(DirectObject.DirectObject): notify = directNotify.newCategory("ShowBase") @@ -93,6 +97,7 @@ class ShowBase: # base.win is the main, or only window; base.winList is a list of # *all* windows. Similarly with base.pipeList and base.camList. self.win = None + self.mainWinMinimized = 0 self.winList = [] self.pipe = None self.pipeList = [] @@ -154,6 +159,11 @@ class ShowBase: __builtins__["globalClock"] = ClockObject.getGlobalClock() __builtins__["vfs"] = vfs + # Now hang a hook on the window-event from Panda. This allows + # us to detect when the user resizes, minimizes, or closes the + # main window. + self.accept('window-event', self.__windowEvent) + # Transition effects (fade, iris, etc) import Transitions self.transitions = Transitions.Transitions(self.loader) @@ -967,7 +977,28 @@ class ShowBase: state.frameIndex += 1 return Task.cont + def __windowEvent(self, win): + properties = win.getProperties() + if win == self.win: + if not properties.getOpen(): + # If the user closes the main window, we should exit. + self.notify.info("User closed main window, exiting.") + sys.exit() + + if properties.getMinimized() and not self.mainWinMinimized: + # If the main window is minimized, throw an event to + # stop the music. + self.mainWinMinimized = 1 + messenger.send('PandaPaused') + + elif not properties.getMinimized() and self.mainWinMinimized: + # If the main window is restored, throw an event to + # restart the music. + self.mainWinMinimized = 0 + messenger.send('PandaRestarted') + def run(self): self.taskMgr.run() +