improved destroy interface

This commit is contained in:
Joe Shochet 2003-10-13 00:34:22 +00:00
parent e996fb620f
commit 10c7f2a18e

View File

@ -96,8 +96,6 @@ class DirectGuiBase(PandaObject.PandaObject):
def __init__(self): def __init__(self):
# Default id of all gui object, subclasses should override this # Default id of all gui object, subclasses should override this
self.guiId = 'guiObject' self.guiId = 'guiObject'
# List of all active hooks
self._hookDict = {}
# List of all post initialization functions # List of all post initialization functions
self.postInitialiseFuncList = [] self.postInitialiseFuncList = []
# To avoid doing things redundantly during initialisation # To avoid doing things redundantly during initialisation
@ -617,10 +615,8 @@ class DirectGuiBase(PandaObject.PandaObject):
def destroy(self): def destroy(self):
# Clean out any hooks # Clean out any hooks
for event in self._hookDict.keys(): self.ignoreAll()
self.ignore(event)
del(self._optionInfo) del(self._optionInfo)
del(self._hookDict)
del(self.__componentInfo) del(self.__componentInfo)
del self.postInitialiseFuncList del self.postInitialiseFuncList
@ -633,8 +629,6 @@ class DirectGuiBase(PandaObject.PandaObject):
# Need to tack on gui item specific id # Need to tack on gui item specific id
gEvent = event + self.guiId gEvent = event + self.guiId
self.accept(gEvent, command, extraArgs = extraArgs) self.accept(gEvent, command, extraArgs = extraArgs)
# Keep track of all events you're accepting
self._hookDict[gEvent] = command
def unbind(self, event): def unbind(self, event):
""" """
@ -643,8 +637,6 @@ class DirectGuiBase(PandaObject.PandaObject):
# Need to tack on gui item specific id # Need to tack on gui item specific id
gEvent = event + self.guiId gEvent = event + self.guiId
self.ignore(gEvent) self.ignore(gEvent)
if self._hookDict.has_key(gEvent):
del(self._hookDict[gEvent])
def toggleGuiGridSnap(): def toggleGuiGridSnap():
DirectGuiWidget.snapToGrid = 1 - DirectGuiWidget.snapToGrid DirectGuiWidget.snapToGrid = 1 - DirectGuiWidget.snapToGrid
@ -666,6 +658,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
else: else:
inactiveInitState = DISABLED inactiveInitState = DISABLED
guiDict = {}
def __init__(self, parent = aspect2d, **kw): def __init__(self, parent = aspect2d, **kw):
# Direct gui widgets are node paths # Direct gui widgets are node paths
@ -771,7 +764,8 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
self.guiItem.setSuppressFlags(suppressFlags) self.guiItem.setSuppressFlags(suppressFlags)
# Bind destroy hook # Bind destroy hook
self.bind(DESTROY, self.destroy) self.guiDict[self.guiId] = self
# self.bind(DESTROY, self.destroy)
# Update frame when everything has been initialized # Update frame when everything has been initialized
self.postInitialiseFuncList.append(self.frameInitialiseFunc) self.postInitialiseFuncList.append(self.frameInitialiseFunc)
@ -979,7 +973,10 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
def destroy(self): def destroy(self):
# Destroy children # Destroy children
for child in self.getChildrenAsList(): for child in self.getChildrenAsList():
messenger.send(DESTROY + child.getName()) childGui = self.guiDict.get(child.getName())
if childGui: childGui.destroy()
# messenger.send(DESTROY + child.getName())
del self.guiDict[self.guiId]
del self.frameStyle del self.frameStyle
# Get rid of node path # Get rid of node path
self.removeNode() self.removeNode()