From 340a3c4bd314e93cbe0c06b5b6906821c8f55d9a Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Tue, 9 Oct 2001 03:21:33 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/gui/DirectDialog.py | 106 +++++++++++++++++++++++++++ direct/src/gui/DirectGuiGlobals.py | 11 +++ direct/src/gui/DirectScrolledList.py | 18 ++--- 3 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 direct/src/gui/DirectDialog.py diff --git a/direct/src/gui/DirectDialog.py b/direct/src/gui/DirectDialog.py new file mode 100644 index 0000000000..69bb84218d --- /dev/null +++ b/direct/src/gui/DirectDialog.py @@ -0,0 +1,106 @@ +from DirectGuiGlobals import * +from DirectFrame import * +from DirectButton import * + +class DirectDialog(DirectFrame): + def __init__(self, parent = guiTop, **kw): + # Inherits from DirectFrame + optiondefs = ( + # Define type of DirectGuiWidget + ('pad', (0.4, 0.4), None), + ('text', '', None), + ('text_align', TMALIGNCENTER, None), + ('geom', getDefaultDialogGeom(), None), + ('relief', None, None), + ('buttons', [], INITOPT), + ('buttonOffset', 0.2, None), + ('button_pad', (.1,.1), None), + ('button_relief', RAISED, None), + ('button_frameSize', (-1,1,-.2,.9), None), + ('command', None, None), + ('extraArgs', [], None), + ) + # Merge keyword options with default options + self.defineoptions(kw, optiondefs, dynamicGroups = ("button",)) + + # Initialize superclasses + DirectFrame.__init__(self, parent) + + self.numButtons = len(self['buttons']) + self.buttonList = [] + for button in self['buttons']: + name = button + 'Button' + button = self.createcomponent( + name, (), "button", + DirectButton, (self,), + text = button, + command = lambda s = self, b = button: s.__buttonCommand(b) + ) + self.buttonList.append(button) + self.numButtons += 1 + self.initialiseoptions(DirectDialog) + + # Position buttons and text + # Get size of text + text = self.component('text0') + bounds = text.getTightBounds() + pad = self['pad'] + l = bounds[0][0] - pad[0] + r = bounds[1][0] + pad[0] + b = bounds[0][2] - pad[1] + t = bounds[1][2] + pad[1] + text.setPos((l+r)/2.0, (b+t)/2.0) + # Move buttons + if self['button_frameSize']: + frameSize = self['button_frameSize'] + bl = frameSize[0] + br = frameSize[1] + bb = frameSize[2] + bt = frameSize[3] + else: + # Get bounds of union of buttons + bl = br = bb = bt = 0 + for button in self.buttonList: + bounds = button.stateNodePath[0].getTightBounds() + bl = min(bl, bounds[0][0]) + br = max(br, bounds[1][0]) + bb = min(bb, bounds[0][2]) + bt = max(bt, bounds[1][2]) + bWidth = br - bl + bSpacing = 1.1 * bWidth + bHeight = bt - bb + index = 0 + if self.numButtons == 0: + return + bPos = bSpacing * (self.numButtons - 1)/2.0 + for button in self.buttonList: + button.setPos(bPos + index * bSpacing, 0, + b - self['buttonOffset'] - bt) + index += 1 + # Resize frame + b = b - self['buttonOffset'] - bHeight - pad[1] + frame = self.component('geom0') + frame.setScale(r - l, 1, t - b) + frame.setPos((l+r)/2.0, 0.0, (b+t)/2.0) + self.resetFrameSize() + + def __buttonCommand(self, button): + if self['command']: + self['command'](button) + + def destroy(self): + DirectFrame.destroy(self) + + +class YesNoDialog(DirectDialog): + def __init__(self, parent = guiTop, **kw): + # Inherits from DirectFrame + optiondefs = ( + # Define type of DirectGuiWidget + ('buttons', ['Yes', 'No'], INITOPT), + ('text', 'Yes or No?', None), + ) + # Merge keyword options with default options + self.defineoptions(kw, optiondefs) + apply(DirectDialog.__init__, (self, parent), kw) + self.initialiseoptions(YesNoDialog) diff --git a/direct/src/gui/DirectGuiGlobals.py b/direct/src/gui/DirectGuiGlobals.py index c8148be428..1eba2d66d8 100644 --- a/direct/src/gui/DirectGuiGlobals.py +++ b/direct/src/gui/DirectGuiGlobals.py @@ -63,6 +63,7 @@ TEXT_SORT_INDEX = 30 defaultFont = None defaultClickSound = None defaultRolloverSound = None +defaultDialogGeom = None def getDefaultRolloverSound(): global defaultRolloverSound @@ -91,3 +92,13 @@ def getDefaultFont(): def setDefaultFont(newFont): global defaultFont defaultFont = newFont + +def getDefaultDialogGeom(): + global defaultDialogGeom + if defaultDialogGeom == None: + defaultDialogGeom = loader.loadModelOnce('phase_3/models/props/panel') + return defaultDialogGeom + +def setDefaultDialogGeom(newDialogGeom): + global defaultDialogGeom + defaultDialogGeom = newDialogGeom diff --git a/direct/src/gui/DirectScrolledList.py b/direct/src/gui/DirectScrolledList.py index df48d9eca8..8531b72c93 100644 --- a/direct/src/gui/DirectScrolledList.py +++ b/direct/src/gui/DirectScrolledList.py @@ -1,6 +1,5 @@ from DirectFrame import * from DirectButton import * -import GuiGlobals import Task class DirectScrolledList(DirectFrame): @@ -18,26 +17,23 @@ class DirectScrolledList(DirectFrame): ('scrollSpeed', 8, self.setScrollSpeed), ) # Merge keyword options with default options - self.defineoptions(kw, optiondefs, dynamicGroups = ("items",)) + self.defineoptions(kw, optiondefs) # Initialize superclasses DirectFrame.__init__(self, parent) - self.incButton = self.createcomponent("incButton", (), "incButton", - DirectButton, (), - parent = self, + self.incButton = self.createcomponent("incButton", (), None, + DirectButton, (self,), ) self.incButton.bind(B1PRESS, self.__incButtonDown) self.incButton.bind(B1RELEASE, self.__buttonUp) - self.decButton = self.createcomponent("decButton", (), "decButton", - DirectButton, (), - parent = self, + self.decButton = self.createcomponent("decButton", (), None, + DirectButton, (self,), ) self.decButton.bind(B1PRESS, self.__decButtonDown) self.decButton.bind(B1RELEASE, self.__buttonUp) - self.itemFrame = self.createcomponent("itemFrame", (), "itemFrame", - DirectFrame, (), - parent = self, + self.itemFrame = self.createcomponent("itemFrame", (), None, + DirectFrame, (self,), ) for item in self["items"]: item.reparentTo(self.itemFrame)