From 2d5494ee4c83760abd131886bc54f74fb7b01f46 Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Thu, 12 Jul 2001 18:02:19 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/gui/DirectButton.py | 28 ++++++++++++++++++++++++++-- direct/src/gui/DirectGuiBase.py | 5 +++++ direct/src/gui/DirectGuiTest.py | 11 ++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/direct/src/gui/DirectButton.py b/direct/src/gui/DirectButton.py index 174c108b71..34238cd455 100644 --- a/direct/src/gui/DirectButton.py +++ b/direct/src/gui/DirectButton.py @@ -28,8 +28,8 @@ class DirectButton(DirectFrame): # Which mouse buttons can be used to click the button ('commandButtons', (LMB,), self.setCommandButtons), # Sounds to be used for button events - ('rolloverSound', None, None), - ('clickSound', None, None), + ('rolloverSound', None, self.setRolloverSound), + ('clickSound', None, self.setClickSound), # Can only be specified at time of widget contruction # Do the text/graphics appear to move when the button is clicked ('pressEffect', 1, INITOPT), @@ -79,3 +79,27 @@ class DirectButton(DirectFrame): # Pass any extra args to command apply(self['command'], self['extraArgs']) + def setClickSound(self): + if base.wantSfx: + clickSound = self['clickSound'] + # Clear out sounds + self.guiItem.clearSound(B1PRESS + self.guiId) + self.guiItem.clearSound(B2PRESS + self.guiId) + self.guiItem.clearSound(B3PRESS + self.guiId) + if clickSound: + if LMB in self['commandButtons']: + self.guiItem.setSound(B1PRESS + self.guiId, clickSound) + if MMB in self['commandButtons']: + self.guiItem.setSound(B2PRESS + self.guiId, clickSound) + if RMB in self['commandButtons']: + self.guiItem.setSound(B3PRESS + self.guiId, clickSound) + + def setRolloverSound(self): + if base.wantSfx: + rolloverSound = self['rolloverSound'] + if rolloverSound: + self.guiItem.setSound(ENTER + self.guiId, rolloverSound) + else: + self.guiItem.clearSound(ENTER + self.guiId) + + diff --git a/direct/src/gui/DirectGuiBase.py b/direct/src/gui/DirectGuiBase.py index 638bf827e4..e5cebebbeb 100644 --- a/direct/src/gui/DirectGuiBase.py +++ b/direct/src/gui/DirectGuiBase.py @@ -664,6 +664,8 @@ class DirectGuiWidget(DirectGuiBase, NodePath): ('frameSize', None, self.setFrameSize), ('frameColor', (.8,.8,.8,1), self.setFrameColor), ('pad', (.25,.15), self.resetFrameSize), + # Override button id (beware! your name may not be unique!) + ('guiId', None, INITOPT), # Initial pos/scale of the widget ('pos', None, INITOPT), ('scale', None, INITOPT), @@ -676,6 +678,9 @@ class DirectGuiWidget(DirectGuiBase, NodePath): NodePath.__init__(self) # Create a button self.guiItem = self['pgFunc']() + # Override automatically generated guiId + if self['guiId']: + self.guiItem.setId(self['guiId']) self.guiId = self.guiItem.getId() # Attach button to parent and make that self self.assign(parent.attachNewNode( self.guiItem ) ) diff --git a/direct/src/gui/DirectGuiTest.py b/direct/src/gui/DirectGuiTest.py index 2d6c13df0e..5dcdc84026 100644 --- a/direct/src/gui/DirectGuiTest.py +++ b/direct/src/gui/DirectGuiTest.py @@ -1,5 +1,7 @@ from DirectGui import * from whrandom import * +from GuiGlobals import getDefaultClickSound +from GuiGlobals import getDefaultRolloverSound # EXAMPLE CODE # Load a model @@ -48,6 +50,7 @@ dl.setScale(.5) # Create a button with a background image, smiley as a geometry element, # and a text overlay, set a different text for the four button states: # (normal, press, rollover, and disabled), set scale = .15, and relief raised +dbArray = [] for i in range(10): db = DirectButton(parent = dl, image = 'phase_4/maps/middayskyB.jpg', @@ -57,7 +60,11 @@ for i in range(10): # Here we set an option for a component of the button geom1_color = Vec4(1,0,0,1), # Here is an example of a component group option - text_pos = (.6, -.8)) + text_pos = (.6, -.8), + # Set audio characteristics + clickSound = getDefaultClickSound(), + rolloverSound = getDefaultRolloverSound() + ) # You can set component or component group options after a gui item # has been created @@ -70,6 +77,8 @@ for i in range(10): db.bind(B1PRESS, lambda x, db = db: ouch(db)) # Pop up placer when button 2 is pressed db.bind(B3PRESS, lambda x, db = db: db.place()) + + dbArray.append(db) # To get rid of button and clear out hooks call: # db.destroy()