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.
This commit is contained in:
rdb 2019-08-14 13:13:40 +02:00
parent acb0a41049
commit 43a5719bac
8 changed files with 21 additions and 13 deletions

View File

@ -3,6 +3,7 @@
__all__ = ['findDialog', 'cleanupDialog', 'DirectDialog', 'OkDialog', 'OkCancelDialog', 'YesNoDialog', 'YesNoCancelDialog', 'RetryCancelDialog'] __all__ = ['findDialog', 'cleanupDialog', 'DirectDialog', 'OkDialog', 'OkCancelDialog', 'YesNoDialog', 'YesNoCancelDialog', 'RetryCancelDialog']
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal
from . import DirectGuiGlobals as DGG from . import DirectGuiGlobals as DGG
from .DirectFrame import * from .DirectFrame import *
from .DirectButton import * from .DirectButton import *
@ -207,7 +208,7 @@ class DirectDialog(DirectFrame):
image = None image = None
# Get size of text/geom without image (for state 0) # Get size of text/geom without image (for state 0)
if image: if image:
image.reparentTo(hidden) image.reparentTo(ShowBaseGlobal.hidden)
bounds = self.stateNodePath[0].getTightBounds() bounds = self.stateNodePath[0].getTightBounds()
if image: if image:
image.reparentTo(self.stateNodePath[0]) image.reparentTo(self.stateNodePath[0])

View File

@ -4,6 +4,7 @@ text entered using the keyboard."""
__all__ = ['DirectEntry'] __all__ = ['DirectEntry']
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal
from . import DirectGuiGlobals as DGG from . import DirectGuiGlobals as DGG
from .DirectFrame import * from .DirectFrame import *
from .OnscreenText import OnscreenText from .OnscreenText import OnscreenText
@ -94,7 +95,7 @@ class DirectEntry(DirectFrame):
self.onscreenText = self.createcomponent( self.onscreenText = self.createcomponent(
'text', (), None, 'text', (), None,
OnscreenText, OnscreenText,
(), parent = hidden, (), parent = ShowBaseGlobal.hidden,
# Pass in empty text to avoid extra work, since its really # Pass in empty text to avoid extra work, since its really
# The PGEntry which will use the TextNode to generate geometry # The PGEntry which will use the TextNode to generate geometry
text = '', text = '',

View File

@ -81,7 +81,6 @@ __all__ = ['DirectGuiBase', 'DirectGuiWidget']
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal 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 *
@ -634,7 +633,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 ShowBase.config.GetBool('debug-directgui-msgs', False): if ShowBaseGlobal.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())
@ -663,7 +662,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 = ShowBase.config.GetBool('direct-gui-edit', False) guiEdit = ShowBaseGlobal.config.GetBool('direct-gui-edit', False)
if guiEdit: if guiEdit:
inactiveInitState = DGG.NORMAL inactiveInitState = DGG.NORMAL
else: else:
@ -729,7 +728,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
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 ShowBase.config.GetBool('track-gui-items', False): if ShowBaseGlobal.config.GetBool('track-gui-items', False):
if not hasattr(ShowBase, 'guiItems'): if not hasattr(ShowBase, 'guiItems'):
ShowBase.guiItems = {} ShowBase.guiItems = {}
if self.guiId in ShowBase.guiItems: if self.guiId in ShowBase.guiItems:

View File

@ -3,6 +3,7 @@
__all__ = ['DirectScrolledListItem', 'DirectScrolledList'] __all__ = ['DirectScrolledListItem', 'DirectScrolledList']
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal
from . import DirectGuiGlobals as DGG from . import DirectGuiGlobals as DGG
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.task.Task import Task from direct.task.Task import Task
@ -369,7 +370,7 @@ class DirectScrolledList(DirectFrame):
del self.currentSelected del self.currentSelected
self["items"].remove(item) self["items"].remove(item)
if type(item) != type(''): if type(item) != type(''):
item.reparentTo(hidden) item.reparentTo(ShowBaseGlobal.hidden)
self.refresh() self.refresh()
return 1 return 1
else: else:
@ -387,7 +388,7 @@ class DirectScrolledList(DirectFrame):
item.destroy() item.destroy()
self["items"].remove(item) self["items"].remove(item)
if type(item) != type(''): if type(item) != type(''):
item.reparentTo(hidden) item.reparentTo(ShowBaseGlobal.hidden)
self.refresh() self.refresh()
return 1 return 1
else: else:
@ -410,7 +411,7 @@ class DirectScrolledList(DirectFrame):
self["items"].remove(item) self["items"].remove(item)
if type(item) != type(''): if type(item) != type(''):
#RAU possible leak here, let's try to do the right thing #RAU possible leak here, let's try to do the right thing
#item.reparentTo(hidden) #item.reparentTo(ShowBaseGlobal.hidden)
item.removeNode() item.removeNode()
retval = 1 retval = 1
@ -435,7 +436,7 @@ class DirectScrolledList(DirectFrame):
self["items"].remove(item) self["items"].remove(item)
if type(item) != type(''): if type(item) != type(''):
#RAU possible leak here, let's try to do the right thing #RAU possible leak here, let's try to do the right thing
#item.reparentTo(hidden) #item.reparentTo(ShowBaseGlobal.hidden)
item.removeNode() item.removeNode()
retval = 1 retval = 1
if (refresh): if (refresh):

View File

@ -207,7 +207,10 @@ class ShowBase(DirectObject.DirectObject):
# Has the clusterSyncFlag been set via a config variable # Has the clusterSyncFlag been set via a config variable
self.clusterSyncFlag = self.config.GetBool('cluster-sync', 0) 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() ## The global graphics engine, ie. GraphicsEngine.getGlobalPtr()
self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.graphicsEngine = GraphicsEngine.getGlobalPtr()

View File

@ -25,6 +25,7 @@ pandaSystem = PandaSystem.getGlobalPtr()
# This is defined here so GUI elements can be instantiated before ShowBase. # This is defined here so GUI elements can be instantiated before ShowBase.
aspect2d = NodePath(PGTop("aspect2d")) aspect2d = NodePath(PGTop("aspect2d"))
hidden = NodePath("hidden")
# Set direct notify categories now that we have config # Set direct notify categories now that we have config
directNotify.setDconfigLevels() directNotify.setDconfigLevels()

View File

@ -5,6 +5,7 @@ a particular color."""
__all__ = ['Transitions'] __all__ = ['Transitions']
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal
from direct.gui.DirectGui import DirectFrame from direct.gui.DirectGui import DirectFrame
from direct.gui import DirectGuiGlobals as DGG from direct.gui import DirectGuiGlobals as DGG
from direct.interval.LerpInterval import LerpColorScaleInterval, LerpColorInterval, LerpScaleInterval, LerpPosInterval 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 # so that it will also obscure mouse events for objects
# positioned behind it. # positioned behind it.
self.fade = DirectFrame( self.fade = DirectFrame(
parent = hidden, parent = ShowBaseGlobal.hidden,
guiId = 'fade', guiId = 'fade',
relief = None, relief = None,
image = self.fadeModel, image = self.fadeModel,

View File

@ -4,6 +4,7 @@ __all__ = ['MopathRecorder']
# Import Tkinter, Pmw, and the dial code from this directory tree. # Import Tkinter, Pmw, and the dial code from this directory tree.
from panda3d.core import * from panda3d.core import *
from direct.showbase import ShowBaseGlobal
from direct.showbase.DirectObject import DirectObject from direct.showbase.DirectObject import DirectObject
from direct.showbase.TkGlobal import * from direct.showbase.TkGlobal import *
from direct.tkwidgets.AppShell import * from direct.tkwidgets.AppShell import *
@ -852,7 +853,7 @@ class MopathRecorder(AppShell, DirectObject):
if self.getVariable('Style', 'Marker').get(): if self.getVariable('Style', 'Marker').get():
self.playbackMarker.reparentTo(self.recorderNodePath) self.playbackMarker.reparentTo(self.recorderNodePath)
else: else:
self.playbackMarker.reparentTo(hidden) self.playbackMarker.reparentTo(ShowBaseGlobal.hidden)
def setNumSegs(self, value): def setNumSegs(self, value):
self.numSegs = int(value) self.numSegs = int(value)