|
@@ -80,7 +80,8 @@ __all__ = ['DirectGuiBase', 'DirectGuiWidget']
|
|
|
|
|
|
|
|
|
|
|
|
|
from panda3d.core import *
|
|
from panda3d.core import *
|
|
|
-from panda3d.direct import get_config_showbase
|
|
|
|
|
|
|
+from direct.showbase import ShowBaseGlobal
|
|
|
|
|
+from direct.showbase.ShowBase import ShowBase
|
|
|
from . import DirectGuiGlobals as DGG
|
|
from . import DirectGuiGlobals as DGG
|
|
|
from .OnscreenText import *
|
|
from .OnscreenText import *
|
|
|
from .OnscreenGeom import *
|
|
from .OnscreenGeom import *
|
|
@@ -633,7 +634,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|
|
"""
|
|
"""
|
|
|
# Need to tack on gui item specific id
|
|
# Need to tack on gui item specific id
|
|
|
gEvent = event + self.guiId
|
|
gEvent = event + self.guiId
|
|
|
- if get_config_showbase().GetBool('debug-directgui-msgs', False):
|
|
|
|
|
|
|
+ if ShowBase.config.GetBool('debug-directgui-msgs', False):
|
|
|
from direct.showbase.PythonUtil import StackTrace
|
|
from direct.showbase.PythonUtil import StackTrace
|
|
|
print(gEvent)
|
|
print(gEvent)
|
|
|
print(StackTrace())
|
|
print(StackTrace())
|
|
@@ -662,7 +663,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|
|
# Determine the default initial state for inactive (or
|
|
# Determine the default initial state for inactive (or
|
|
|
# unclickable) components. If we are in edit mode, these are
|
|
# unclickable) components. If we are in edit mode, these are
|
|
|
# actually clickable by default.
|
|
# actually clickable by default.
|
|
|
- guiEdit = get_config_showbase().GetBool('direct-gui-edit', 0)
|
|
|
|
|
|
|
+ guiEdit = ShowBase.config.GetBool('direct-gui-edit', False)
|
|
|
if guiEdit:
|
|
if guiEdit:
|
|
|
inactiveInitState = DGG.NORMAL
|
|
inactiveInitState = DGG.NORMAL
|
|
|
else:
|
|
else:
|
|
@@ -723,21 +724,24 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|
|
if self['guiId']:
|
|
if self['guiId']:
|
|
|
self.guiItem.setId(self['guiId'])
|
|
self.guiItem.setId(self['guiId'])
|
|
|
self.guiId = self.guiItem.getId()
|
|
self.guiId = self.guiItem.getId()
|
|
|
- if __dev__:
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if ShowBaseGlobal.__dev__:
|
|
|
guiObjectCollector.addLevel(1)
|
|
guiObjectCollector.addLevel(1)
|
|
|
guiObjectCollector.flushLevel()
|
|
guiObjectCollector.flushLevel()
|
|
|
# track gui items by guiId for tracking down leaks
|
|
# track gui items by guiId for tracking down leaks
|
|
|
- if hasattr(base, 'guiItems'):
|
|
|
|
|
- if self.guiId in base.guiItems:
|
|
|
|
|
- base.notify.warning('duplicate guiId: %s (%s stomping %s)' %
|
|
|
|
|
- (self.guiId, self,
|
|
|
|
|
- base.guiItems[self.guiId]))
|
|
|
|
|
- base.guiItems[self.guiId] = self
|
|
|
|
|
- if hasattr(base, 'printGuiCreates'):
|
|
|
|
|
- printStack()
|
|
|
|
|
|
|
+ if ShowBase.config.GetBool('track-gui-items', True):
|
|
|
|
|
+ if not hasattr(ShowBase, 'guiItems'):
|
|
|
|
|
+ ShowBase.guiItems = {}
|
|
|
|
|
+ if self.guiId in ShowBase.guiItems:
|
|
|
|
|
+ ShowBase.notify.warning('duplicate guiId: %s (%s stomping %s)' %
|
|
|
|
|
+ (self.guiId, self,
|
|
|
|
|
+ ShowBase.guiItems[self.guiId]))
|
|
|
|
|
+ ShowBase.guiItems[self.guiId] = self
|
|
|
|
|
+
|
|
|
# Attach button to parent and make that self
|
|
# Attach button to parent and make that self
|
|
|
- if (parent == None):
|
|
|
|
|
- parent = aspect2d
|
|
|
|
|
|
|
+ if parent is None:
|
|
|
|
|
+ parent = ShowBaseGlobal.aspect2d
|
|
|
|
|
+
|
|
|
self.assign(parent.attachNewNode(self.guiItem, self['sortOrder']))
|
|
self.assign(parent.attachNewNode(self.guiItem, self['sortOrder']))
|
|
|
# Update pose to initial values
|
|
# Update pose to initial values
|
|
|
if self['pos']:
|
|
if self['pos']:
|
|
@@ -1024,17 +1028,12 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|
|
|
|
|
|
|
def destroy(self):
|
|
def destroy(self):
|
|
|
if hasattr(self, "frameStyle"):
|
|
if hasattr(self, "frameStyle"):
|
|
|
- if __dev__:
|
|
|
|
|
|
|
+ if ShowBaseGlobal.__dev__:
|
|
|
guiObjectCollector.subLevel(1)
|
|
guiObjectCollector.subLevel(1)
|
|
|
guiObjectCollector.flushLevel()
|
|
guiObjectCollector.flushLevel()
|
|
|
- if hasattr(base, 'guiItems'):
|
|
|
|
|
- if self.guiId in base.guiItems:
|
|
|
|
|
- del base.guiItems[self.guiId]
|
|
|
|
|
- else:
|
|
|
|
|
- base.notify.warning(
|
|
|
|
|
- 'DirectGuiWidget.destroy(): '
|
|
|
|
|
- 'gui item %s not in base.guiItems' %
|
|
|
|
|
- self.guiId)
|
|
|
|
|
|
|
+ if hasattr(ShowBase, 'guiItems'):
|
|
|
|
|
+ ShowBase.guiItems.pop(self.guiId, None)
|
|
|
|
|
+
|
|
|
# Destroy children
|
|
# Destroy children
|
|
|
for child in self.getChildren():
|
|
for child in self.getChildren():
|
|
|
childGui = self.guiDict.get(child.getName())
|
|
childGui = self.guiDict.get(child.getName())
|