From 43a5719bacbd46f5119530dd9d77040522f591e5 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 14 Aug 2019 13:13:40 +0200 Subject: [PATCH] dgui: allow using various GUI items without instantiating ShowBase This is done by eliminating dependency on the `hidden` built-in, which can now instead be imported from ShowBaseGlobal. --- direct/src/gui/DirectDialog.py | 3 ++- direct/src/gui/DirectEntry.py | 3 ++- direct/src/gui/DirectGuiBase.py | 7 +++---- direct/src/gui/DirectScrolledList.py | 9 +++++---- direct/src/showbase/ShowBase.py | 5 ++++- direct/src/showbase/ShowBaseGlobal.py | 1 + direct/src/showbase/Transitions.py | 3 ++- direct/src/tkpanels/MopathRecorder.py | 3 ++- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/direct/src/gui/DirectDialog.py b/direct/src/gui/DirectDialog.py index 33852dc504..ba56fdbfa0 100644 --- a/direct/src/gui/DirectDialog.py +++ b/direct/src/gui/DirectDialog.py @@ -3,6 +3,7 @@ __all__ = ['findDialog', 'cleanupDialog', 'DirectDialog', 'OkDialog', 'OkCancelDialog', 'YesNoDialog', 'YesNoCancelDialog', 'RetryCancelDialog'] from panda3d.core import * +from direct.showbase import ShowBaseGlobal from . import DirectGuiGlobals as DGG from .DirectFrame import * from .DirectButton import * @@ -207,7 +208,7 @@ class DirectDialog(DirectFrame): image = None # Get size of text/geom without image (for state 0) if image: - image.reparentTo(hidden) + image.reparentTo(ShowBaseGlobal.hidden) bounds = self.stateNodePath[0].getTightBounds() if image: image.reparentTo(self.stateNodePath[0]) diff --git a/direct/src/gui/DirectEntry.py b/direct/src/gui/DirectEntry.py index e345c526e9..f7ad164798 100644 --- a/direct/src/gui/DirectEntry.py +++ b/direct/src/gui/DirectEntry.py @@ -4,6 +4,7 @@ text entered using the keyboard.""" __all__ = ['DirectEntry'] from panda3d.core import * +from direct.showbase import ShowBaseGlobal from . import DirectGuiGlobals as DGG from .DirectFrame import * from .OnscreenText import OnscreenText @@ -94,7 +95,7 @@ class DirectEntry(DirectFrame): self.onscreenText = self.createcomponent( 'text', (), None, OnscreenText, - (), parent = hidden, + (), parent = ShowBaseGlobal.hidden, # Pass in empty text to avoid extra work, since its really # The PGEntry which will use the TextNode to generate geometry text = '', diff --git a/direct/src/gui/DirectGuiBase.py b/direct/src/gui/DirectGuiBase.py index 3180d0dfce..e654c455c2 100644 --- a/direct/src/gui/DirectGuiBase.py +++ b/direct/src/gui/DirectGuiBase.py @@ -81,7 +81,6 @@ __all__ = ['DirectGuiBase', 'DirectGuiWidget'] from panda3d.core import * from direct.showbase import ShowBaseGlobal -from direct.showbase.ShowBase import ShowBase from . import DirectGuiGlobals as DGG from .OnscreenText import * from .OnscreenGeom import * @@ -634,7 +633,7 @@ class DirectGuiBase(DirectObject.DirectObject): """ # Need to tack on gui item specific id gEvent = event + self.guiId - if ShowBase.config.GetBool('debug-directgui-msgs', False): + if ShowBaseGlobal.config.GetBool('debug-directgui-msgs', False): from direct.showbase.PythonUtil import StackTrace print(gEvent) print(StackTrace()) @@ -663,7 +662,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath): # Determine the default initial state for inactive (or # unclickable) components. If we are in edit mode, these are # actually clickable by default. - guiEdit = ShowBase.config.GetBool('direct-gui-edit', False) + guiEdit = ShowBaseGlobal.config.GetBool('direct-gui-edit', False) if guiEdit: inactiveInitState = DGG.NORMAL else: @@ -729,7 +728,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath): guiObjectCollector.addLevel(1) guiObjectCollector.flushLevel() # track gui items by guiId for tracking down leaks - if ShowBase.config.GetBool('track-gui-items', False): + if ShowBaseGlobal.config.GetBool('track-gui-items', False): if not hasattr(ShowBase, 'guiItems'): ShowBase.guiItems = {} if self.guiId in ShowBase.guiItems: diff --git a/direct/src/gui/DirectScrolledList.py b/direct/src/gui/DirectScrolledList.py index a89b691576..661b09f13d 100644 --- a/direct/src/gui/DirectScrolledList.py +++ b/direct/src/gui/DirectScrolledList.py @@ -3,6 +3,7 @@ __all__ = ['DirectScrolledListItem', 'DirectScrolledList'] from panda3d.core import * +from direct.showbase import ShowBaseGlobal from . import DirectGuiGlobals as DGG from direct.directnotify import DirectNotifyGlobal from direct.task.Task import Task @@ -369,7 +370,7 @@ class DirectScrolledList(DirectFrame): del self.currentSelected self["items"].remove(item) if type(item) != type(''): - item.reparentTo(hidden) + item.reparentTo(ShowBaseGlobal.hidden) self.refresh() return 1 else: @@ -387,7 +388,7 @@ class DirectScrolledList(DirectFrame): item.destroy() self["items"].remove(item) if type(item) != type(''): - item.reparentTo(hidden) + item.reparentTo(ShowBaseGlobal.hidden) self.refresh() return 1 else: @@ -410,7 +411,7 @@ class DirectScrolledList(DirectFrame): self["items"].remove(item) if type(item) != type(''): #RAU possible leak here, let's try to do the right thing - #item.reparentTo(hidden) + #item.reparentTo(ShowBaseGlobal.hidden) item.removeNode() retval = 1 @@ -435,7 +436,7 @@ class DirectScrolledList(DirectFrame): self["items"].remove(item) if type(item) != type(''): #RAU possible leak here, let's try to do the right thing - #item.reparentTo(hidden) + #item.reparentTo(ShowBaseGlobal.hidden) item.removeNode() retval = 1 if (refresh): diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 0dd8a05b3b..f79d1a68c5 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -207,7 +207,10 @@ class ShowBase(DirectObject.DirectObject): # Has the clusterSyncFlag been set via a config variable self.clusterSyncFlag = self.config.GetBool('cluster-sync', 0) - self.hidden = NodePath('hidden') + # We've already created aspect2d in ShowBaseGlobal, for the + # benefit of creating DirectGui elements before ShowBase. + from . import ShowBaseGlobal + self.hidden = ShowBaseGlobal.hidden ## The global graphics engine, ie. GraphicsEngine.getGlobalPtr() self.graphicsEngine = GraphicsEngine.getGlobalPtr() diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index 487524dd6a..845e1cccdc 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -25,6 +25,7 @@ pandaSystem = PandaSystem.getGlobalPtr() # This is defined here so GUI elements can be instantiated before ShowBase. aspect2d = NodePath(PGTop("aspect2d")) +hidden = NodePath("hidden") # Set direct notify categories now that we have config directNotify.setDconfigLevels() diff --git a/direct/src/showbase/Transitions.py b/direct/src/showbase/Transitions.py index 54d7bd2baa..e67ad68292 100644 --- a/direct/src/showbase/Transitions.py +++ b/direct/src/showbase/Transitions.py @@ -5,6 +5,7 @@ a particular color.""" __all__ = ['Transitions'] from panda3d.core import * +from direct.showbase import ShowBaseGlobal from direct.gui.DirectGui import DirectFrame from direct.gui import DirectGuiGlobals as DGG from direct.interval.LerpInterval import LerpColorScaleInterval, LerpColorInterval, LerpScaleInterval, LerpPosInterval @@ -73,7 +74,7 @@ class Transitions: # so that it will also obscure mouse events for objects # positioned behind it. self.fade = DirectFrame( - parent = hidden, + parent = ShowBaseGlobal.hidden, guiId = 'fade', relief = None, image = self.fadeModel, diff --git a/direct/src/tkpanels/MopathRecorder.py b/direct/src/tkpanels/MopathRecorder.py index e829ce233f..8ff2341865 100644 --- a/direct/src/tkpanels/MopathRecorder.py +++ b/direct/src/tkpanels/MopathRecorder.py @@ -4,6 +4,7 @@ __all__ = ['MopathRecorder'] # Import Tkinter, Pmw, and the dial code from this directory tree. from panda3d.core import * +from direct.showbase import ShowBaseGlobal from direct.showbase.DirectObject import DirectObject from direct.showbase.TkGlobal import * from direct.tkwidgets.AppShell import * @@ -852,7 +853,7 @@ class MopathRecorder(AppShell, DirectObject): if self.getVariable('Style', 'Marker').get(): self.playbackMarker.reparentTo(self.recorderNodePath) else: - self.playbackMarker.reparentTo(hidden) + self.playbackMarker.reparentTo(ShowBaseGlobal.hidden) def setNumSegs(self, value): self.numSegs = int(value)