Example #1
0
 def __init__(self, parent = None, **kw):
     optiondefs = (('pgFunc', PGButton, None),
      ('numStates', 4, None),
      ('state', DGG.NORMAL, None),
      ('relief', DGG.RAISED, None),
      ('invertedFrames', (1,), None),
      ('command', None, None),
      ('extraArgs', [], None),
      ('commandButtons', (DGG.LMB,), self.setCommandButtons),
      ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
      ('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
      ('pressEffect', 1, DGG.INITOPT))
     self.defineoptions(kw, optiondefs)
     DirectFrame.__init__(self, parent)
     pressEffectNP = None
     if self['pressEffect']:
         pressEffectNP = self.stateNodePath[1].attachNewNode('pressEffect', 1)
         self.stateNodePath[1] = pressEffectNP
     self.initialiseoptions(DirectButton)
     if pressEffectNP:
         bounds = self.getBounds()
         centerX = (bounds[0] + bounds[1]) / 2
         centerY = (bounds[2] + bounds[3]) / 2
         mat = Mat4.translateMat(-centerX, 0, -centerY) * Mat4.scaleMat(0.98) * Mat4.translateMat(centerX, 0, centerY)
         pressEffectNP.setMat(mat)
     return
Example #2
0
 def __init__(self, parent=None, **kw):
     optiondefs = (('pgFunc', PGButton, None), ('numStates', 4, None),
                   ('state', DGG.NORMAL, None), ('relief', DGG.RAISED,
                                                 None), ('invertedFrames',
                                                         (1, ), None),
                   ('command', None, None), ('extraArgs', [], None),
                   ('commandButtons', (DGG.LMB, ),
                    self.setCommandButtons), ('rolloverSound',
                                              DGG.getDefaultRolloverSound(),
                                              self.setRolloverSound),
                   ('clickSound', DGG.getDefaultClickSound(),
                    self.setClickSound), ('pressEffect', 1, DGG.INITOPT))
     self.defineoptions(kw, optiondefs)
     DirectFrame.__init__(self, parent)
     pressEffectNP = None
     if self['pressEffect']:
         pressEffectNP = self.stateNodePath[1].attachNewNode(
             'pressEffect', 1)
         self.stateNodePath[1] = pressEffectNP
     self.initialiseoptions(DirectButton)
     if pressEffectNP:
         bounds = self.getBounds()
         centerX = (bounds[0] + bounds[1]) / 2
         centerY = (bounds[2] + bounds[3]) / 2
         mat = Mat4.translateMat(-centerX, 0, -centerY) * Mat4.scaleMat(
             0.98) * Mat4.translateMat(centerX, 0, centerY)
         pressEffectNP.setMat(mat)
     return
Example #3
0
    def __init__(self, parent = None, **kw):
        optiondefs = (('pgFunc', PGEntry, None),
         ('numStates', 3, None),
         ('state', DGG.NORMAL, None),
         ('entryFont', None, DGG.INITOPT),
         ('width', 10, self.setup),
         ('numLines', 1, self.setup),
         ('focus', 0, self.setFocus),
         ('cursorKeys', 1, self.setCursorKeysActive),
         ('obscured', 0, self.setObscureMode),
         ('backgroundFocus', 0, self.setBackgroundFocus),
         ('initialText', '', DGG.INITOPT),
         ('command', None, None),
         ('extraArgs', [], None),
         ('failedCommand', None, None),
         ('failedExtraArgs', [], None),
         ('focusInCommand', None, None),
         ('focusInExtraArgs', [], None),
         ('focusOutCommand', None, None),
         ('focusOutExtraArgs', [], None),
         ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
         ('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
         ('autoCapitalize', 0, self.autoCapitalizeFunc),
         ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None),
         ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None))
        self.defineoptions(kw, optiondefs)
        DirectFrame.__init__(self, parent)
        if self['entryFont'] == None:
            font = DGG.getDefaultFont()
        else:
            font = self['entryFont']
        self.onscreenText = self.createcomponent('text', (), None, OnscreenText, (), parent=hidden, text='', align=TextNode.ALeft, font=font, scale=1, mayChange=1)
        self.onscreenText.removeNode()
        self.bind(DGG.ACCEPT, self.commandFunc)
        self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)
        self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
        self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)
        self._autoCapListener = DirectObject()
        self.initialiseoptions(DirectEntry)
        if not hasattr(self, 'autoCapitalizeAllowPrefixes'):
            self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes
        if not hasattr(self, 'autoCapitalizeForcePrefixes'):
            self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes
        for i in range(self['numStates']):
            self.guiItem.setTextDef(i, self.onscreenText.textNode)

        self.setup()
        self.unicodeText = 0
        if self['initialText']:
            self.enterText(self['initialText'])
        return None
Example #4
0
 def initNametagGlobals(self):
     arrow = loader.loadModel('phase_3/models/props/arrow')
     card = loader.loadModel('phase_3/models/props/panel')
     speech3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox'))
     thought3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_thought_cutout'))
     speech2d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_noarrow'))
     chatButtonGui = loader.loadModelOnce('phase_3/models/gui/chat_button_gui')
     NametagGlobals.setCamera(base.cam)
     NametagGlobals.setArrowModel(arrow)
     NametagGlobals.setNametagCard(card, VBase4(-0.5, 0.5, -0.5, 0.5))
     NametagGlobals.setMouseWatcher(base.mouseWatcherNode)
     NametagGlobals.setSpeechBalloon3d(speech3d)
     NametagGlobals.setThoughtBalloon3d(thought3d)
     NametagGlobals.setSpeechBalloon2d(speech2d)
     NametagGlobals.setThoughtBalloon2d(thought3d)
     NametagGlobals.setPageButton(PGButton.SReady, chatButtonGui.find('**/Horiz_Arrow_UP'))
     NametagGlobals.setPageButton(PGButton.SDepressed, chatButtonGui.find('**/Horiz_Arrow_DN'))
     NametagGlobals.setPageButton(PGButton.SRollover, chatButtonGui.find('**/Horiz_Arrow_Rllvr'))
     NametagGlobals.setQuitButton(PGButton.SReady, chatButtonGui.find('**/CloseBtn_UP'))
     NametagGlobals.setQuitButton(PGButton.SDepressed, chatButtonGui.find('**/CloseBtn_DN'))
     NametagGlobals.setQuitButton(PGButton.SRollover, chatButtonGui.find('**/CloseBtn_Rllvr'))
     arrow.removeNode()
     card.removeNode()
     chatButtonGui.removeNode()
     rolloverSound = DirectGuiGlobals.getDefaultRolloverSound()
     if rolloverSound:
         NametagGlobals.setRolloverSound(rolloverSound)
     
     clickSound = DirectGuiGlobals.getDefaultClickSound()
     if clickSound:
         NametagGlobals.setClickSound(clickSound)
     
     NametagGlobals.setToon(base.cam)
     self.marginManager = MarginManager()
     self.margins = base.aspect2d.attachNewNode(self.marginManager, DirectGuiGlobals.MIDGROUND_SORT_INDEX + 1)
     mm = self.marginManager
     self.leftCells = [
         mm.addGridCell(0, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(0, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(0, 3, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
     self.bottomCells = [
         mm.addGridCell(0.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(1.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(2.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(3.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(4.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
     self.rightCells = [
         mm.addGridCell(5, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop),
         mm.addGridCell(5, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
Example #5
0
 def initNametagGlobals(self):
     arrow = loader.loadModel('phase_3/models/props/arrow')
     card = loader.loadModel('phase_3/models/props/panel')
     speech3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox'))
     thought3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_thought_cutout'))
     speech2d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_noarrow'))
     chatButtonGui = loader.loadModelOnce('phase_3/models/gui/chat_button_gui')
     NametagGlobals.setCamera(base.cam)
     NametagGlobals.setArrowModel(arrow)
     NametagGlobals.setNametagCard(card, VBase4(-0.5, 0.5, -0.5, 0.5))
     NametagGlobals.setMouseWatcher(base.mouseWatcherNode)
     NametagGlobals.setSpeechBalloon3d(speech3d)
     NametagGlobals.setThoughtBalloon3d(thought3d)
     NametagGlobals.setSpeechBalloon2d(speech2d)
     NametagGlobals.setThoughtBalloon2d(thought3d)
     NametagGlobals.setPageButton(PGButton.SReady, chatButtonGui.find('**/Horiz_Arrow_UP'))
     NametagGlobals.setPageButton(PGButton.SDepressed, chatButtonGui.find('**/Horiz_Arrow_DN'))
     NametagGlobals.setPageButton(PGButton.SRollover, chatButtonGui.find('**/Horiz_Arrow_Rllvr'))
     NametagGlobals.setQuitButton(PGButton.SReady, chatButtonGui.find('**/CloseBtn_UP'))
     NametagGlobals.setQuitButton(PGButton.SDepressed, chatButtonGui.find('**/CloseBtn_DN'))
     NametagGlobals.setQuitButton(PGButton.SRollover, chatButtonGui.find('**/CloseBtn_Rllvr'))
     arrow.removeNode()
     card.removeNode()
     chatButtonGui.removeNode()
     rolloverSound = DirectGuiGlobals.getDefaultRolloverSound()
     if rolloverSound:
         NametagGlobals.setRolloverSound(rolloverSound)
     clickSound = DirectGuiGlobals.getDefaultClickSound()
     if clickSound:
         NametagGlobals.setClickSound(clickSound)
     NametagGlobals.setToon(base.cam)
     self.marginManager = MarginManager()
     self.margins = base.aspect2d.attachNewNode(self.marginManager, DirectGuiGlobals.MIDGROUND_SORT_INDEX + 1)
     mm = self.marginManager
     self.leftCells = [mm.addGridCell(0, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 3, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
     self.bottomCells = [
      mm.addGridCell(0.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(1.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(2.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(3.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(4.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
     self.rightCells = [
      mm.addGridCell(5, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(5, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
    def __init__(self, parent=None, **kw):
        # Inherits from DirectFrame
        # A Direct Frame can have:
        # - A background texture (pass in path to image, or Texture Card)
        # - A midground geometry item (pass in geometry)
        # - A foreground text Node (pass in text string or Onscreen Text)
        # For a direct entry:
        # Each button has 3 states (focus, noFocus, disabled)
        # The same image/geom/text can be used for all three states or each
        # state can have a different text/geom/image
        # State transitions happen automatically based upon mouse interaction
        optiondefs = (
            # Define type of DirectGuiWidget
            ('pgFunc', PGEntry, None),
            ('numStates', 3, None),
            ('state', DGG.NORMAL, None),
            ('entryFont', None, DGG.INITOPT),
            ('width', 10, self.setup),
            ('numLines', 1, self.setup),
            ('focus', 0, self.setFocus),
            ('cursorKeys', 1, self.setCursorKeysActive),
            ('obscured', 0, self.setObscureMode),
            # Setting backgroundFocus allows the entry box to get keyboard
            # events that are not handled by other things (i.e. events that
            # fall through to the background):
            ('backgroundFocus', 0, self.setBackgroundFocus),
            # Text used for the PGEntry text node
            # NOTE: This overrides the DirectFrame text option
            ('initialText', '', DGG.INITOPT),
            # Command to be called on hitting Enter
            ('command', None, None),
            ('extraArgs', [], None),
            # Command to be called when enter is hit but we fail to submit
            ('failedCommand', None, None),
            ('failedExtraArgs', [], None),
            # commands to be called when focus is gained or lost
            ('focusInCommand', None, None),
            ('focusInExtraArgs', [], None),
            ('focusOutCommand', None, None),
            ('focusOutExtraArgs', [], None),
            # Sounds to be used for button events
            ('rolloverSound', DGG.getDefaultRolloverSound(),
             self.setRolloverSound),
            ('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
            ('autoCapitalize', 0, self.autoCapitalizeFunc),
            ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes,
             None),
            ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes,
             None),
        )
        # Merge keyword options with default options
        self.defineoptions(kw, optiondefs)

        # Initialize superclasses
        DirectFrame.__init__(self, parent)

        if self['entryFont'] == None:
            font = DGG.getDefaultFont()
        else:
            font = self['entryFont']

        # Create Text Node Component
        self.onscreenText = self.createcomponent(
            'text',
            (),
            None,
            OnscreenText,
            (),
            parent=hidden,
            # Pass in empty text to avoid extra work, since its really
            # The PGEntry which will use the TextNode to generate geometry
            text='',
            align=TextNode.ALeft,
            font=font,
            scale=1,
            # Don't get rid of the text node
            mayChange=1)

        # We can get rid of the node path since we're just using the
        # onscreenText as an easy way to access a text node as a
        # component
        self.onscreenText.removeNode()

        # Bind command function
        self.bind(DGG.ACCEPT, self.commandFunc)
        self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)

        self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
        self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)

        # listen for auto-capitalize events on a separate object to prevent
        # clashing with other parts of the system
        self._autoCapListener = DirectObject()

        # Call option initialization functions
        self.initialiseoptions(DirectEntry)

        if not hasattr(self, 'autoCapitalizeAllowPrefixes'):
            self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes
        if not hasattr(self, 'autoCapitalizeForcePrefixes'):
            self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes

        # Update TextNodes for each state
        for i in range(self['numStates']):
            self.guiItem.setTextDef(i, self.onscreenText.textNode)

        # Now we should call setup() again to make sure it has the
        # right font def.
        self.setup()

        # Update initial text
        self.unicodeText = 0
        if self['initialText']:
            self.enterText(self['initialText'])
    def __init__(self, parent = None, **kw):
        # Inherits from DirectFrame
        # A Direct Frame can have:
        # - A background texture (pass in path to image, or Texture Card)
        # - A midground geometry item (pass in geometry)
        # - A foreground text Node (pass in text string or Onscreen Text)
        # For a direct entry:
        # Each button has 3 states (focus, noFocus, disabled)
        # The same image/geom/text can be used for all three states or each
        # state can have a different text/geom/image
        # State transitions happen automatically based upon mouse interaction
        optiondefs = (
            # Define type of DirectGuiWidget
            ('pgFunc',          PGEntry,          None),
            ('numStates',       3,                None),
            ('state',           DGG.NORMAL,       None),
            ('entryFont',       None,             DGG.INITOPT),
            ('width',           10,               self.setup),
            ('numLines',        1,                self.setup),
            ('focus',           0,                self.setFocus),
            ('cursorKeys',      1,                self.setCursorKeysActive),
            ('obscured',        0,                self.setObscureMode),
            # Setting backgroundFocus allows the entry box to get keyboard
            # events that are not handled by other things (i.e. events that
            # fall through to the background):
            ('backgroundFocus', 0,                self.setBackgroundFocus),
            # Text used for the PGEntry text node
            # NOTE: This overrides the DirectFrame text option
            ('initialText',     '',               DGG.INITOPT),
            # Command to be called on hitting Enter
            ('command',        None,              None),
            ('extraArgs',      [],                None),
            # Command to be called when enter is hit but we fail to submit
            ('failedCommand',  None,              None),
            ('failedExtraArgs',[],                None),
            # commands to be called when focus is gained or lost
            ('focusInCommand', None,              None),
            ('focusInExtraArgs', [],              None),
            ('focusOutCommand', None,             None),
            ('focusOutExtraArgs', [],             None),
            # Sounds to be used for button events
            ('rolloverSound',   DGG.getDefaultRolloverSound(), self.setRolloverSound),
            ('clickSound',      DGG.getDefaultClickSound(),    self.setClickSound),
            ('autoCapitalize',  0,                self.autoCapitalizeFunc),
            ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None),
            ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None),
            )
        # Merge keyword options with default options
        self.defineoptions(kw, optiondefs)

        # Initialize superclasses
        DirectFrame.__init__(self, parent)

        if self['entryFont'] == None:
            font = DGG.getDefaultFont()
        else:
            font = self['entryFont']

        # Create Text Node Component
        self.onscreenText = self.createcomponent(
            'text', (), None,
            OnscreenText,
            (), parent = hidden,
            # Pass in empty text to avoid extra work, since its really
            # The PGEntry which will use the TextNode to generate geometry
            text = '',
            align = TextNode.ALeft,
            font = font,
            scale = 1,
            # Don't get rid of the text node
            mayChange = 1)

        # We can get rid of the node path since we're just using the
        # onscreenText as an easy way to access a text node as a
        # component
        self.onscreenText.removeNode()

        # Bind command function
        self.bind(DGG.ACCEPT, self.commandFunc)
        self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)

        self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
        self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)

        # listen for auto-capitalize events on a separate object to prevent
        # clashing with other parts of the system
        self._autoCapListener = DirectObject()

        # Call option initialization functions
        self.initialiseoptions(DirectEntry)

        if not hasattr(self, 'autoCapitalizeAllowPrefixes'):
            self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes
        if not hasattr(self, 'autoCapitalizeForcePrefixes'):
            self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes

        # Update TextNodes for each state
        for i in range(self['numStates']):
            self.guiItem.setTextDef(i, self.onscreenText.textNode)

        # Now we should call setup() again to make sure it has the
        # right font def.
        self.setup()

        # Update initial text
        self.unicodeText = 0
        if self['initialText']:
            self.enterText(self['initialText'])
    def __init__(self, parent=None, **kw):
        optiondefs = (
         (
          'pgFunc', PGEntry, None),
         ('numStates', 3, None),
         (
          'state', DGG.NORMAL, None),
         (
          'entryFont', None, DGG.INITOPT),
         (
          'width', 10, self.setup),
         (
          'numLines', 1, self.setup),
         (
          'focus', 0, self.setFocus),
         (
          'cursorKeys', 1, self.setCursorKeysActive),
         (
          'obscured', 0, self.setObscureMode),
         (
          'backgroundFocus', 0, self.setBackgroundFocus),
         (
          'initialText', '', DGG.INITOPT),
         ('command', None, None),
         (
          'extraArgs', [], None),
         ('failedCommand', None, None),
         (
          'failedExtraArgs', [], None),
         ('focusInCommand', None, None),
         (
          'focusInExtraArgs', [], None),
         ('focusOutCommand', None, None),
         (
          'focusOutExtraArgs', [], None),
         (
          'rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
         (
          'clickSound', DGG.getDefaultClickSound(), self.setClickSound),
         (
          'autoCapitalize', 0, self.autoCapitalizeFunc),
         (
          'autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None),
         (
          'autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None))
        self.defineoptions(kw, optiondefs)
        DirectFrame.__init__(self, parent)
        if self['entryFont'] == None:
            font = DGG.getDefaultFont()
        else:
            font = self['entryFont']
        self.onscreenText = self.createcomponent('text', (), None, OnscreenText, (), parent=hidden, text='', align=TextNode.ALeft, font=font, scale=1, mayChange=1)
        self.onscreenText.removeNode()
        self.bind(DGG.ACCEPT, self.commandFunc)
        self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)
        self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
        self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)
        self._autoCapListener = DirectObject()
        self.initialiseoptions(DirectEntry)
        if not hasattr(self, 'autoCapitalizeAllowPrefixes'):
            self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes
        if not hasattr(self, 'autoCapitalizeForcePrefixes'):
            self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes
        for i in range(self['numStates']):
            self.guiItem.setTextDef(i, self.onscreenText.textNode)

        self.setup()
        self.unicodeText = 0
        if self['initialText']:
            self.enterText(self['initialText'])
        return
Example #9
0
    def __init__(self, parent = None, **kw):
        # Inherits from DirectFrame
        # A Direct Frame can have:
        # - A background texture (pass in path to image, or Texture Card)
        # - A midground geometry item (pass in geometry)
        # - A foreground text Node (pass in text string or Onscreen Text)
        # For a direct button:
        # Each button has 4 states (ready, press, rollover, disabled)
        # The same image/geom/text can be used for all four states or each
        # state can have a different text/geom/image
        # State transitions happen automatically based upon mouse interaction
        # Responds to click event and calls command if None
        optiondefs = (
            # Define type of DirectGuiWidget
            ('pgFunc',         PGButton,   None),
            ('numStates',      4,          None),
            ('state',          DGG.NORMAL, None),
            ('relief',         DGG.RAISED, None),
            ('invertedFrames', (1,),       None),
            # Command to be called on button click
            ('command',        None,       None),
            ('extraArgs',      [],         None),
            # Which mouse buttons can be used to click the button
            ('commandButtons', (DGG.LMB,),     self.setCommandButtons),
            # Sounds to be used for button events
            ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
            ('clickSound',    DGG.getDefaultClickSound(),    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,         DGG.INITOPT),
            )
        # Merge keyword options with default options
        self.defineoptions(kw, optiondefs)

        # Initialize superclasses
        DirectFrame.__init__(self, parent)

        # If specifed, add scaling to the pressed state to make it
        # look like the button is moving when you press it.  We have
        # to set up the node first, before we call initialise options;
        # but we can't actually apply the scale until we have the
        # bounding volume (which happens during initialise options).
        pressEffectNP = None
        if self['pressEffect']:
            pressEffectNP = self.stateNodePath[1].attachNewNode('pressEffect', 1)
            self.stateNodePath[1] = pressEffectNP

        # Call option initialization functions
        self.initialiseoptions(DirectButton)

        # Now apply the scale.
        if pressEffectNP:
            bounds = self.getBounds()
            centerX = (bounds[0] + bounds[1]) / 2
            centerY = (bounds[2] + bounds[3]) / 2

            # Make a matrix that scales about the point
            mat = Mat4.translateMat(-centerX, 0, -centerY) * \
                  Mat4.scaleMat(0.98) * \
                  Mat4.translateMat(centerX, 0, centerY)
            pressEffectNP.setMat(mat)
    def __init__(self, parent=None, **kw):
        # Inherits from DirectFrame
        # A Direct Frame can have:
        # - A background texture (pass in path to image, or Texture Card)
        # - A midground geometry item (pass in geometry)
        # - A foreground text Node (pass in text string or Onscreen Text)
        # For a direct button:
        # Each button has 4 states (ready, press, rollover, disabled)
        # The same image/geom/text can be used for all four states or each
        # state can have a different text/geom/image
        # State transitions happen automatically based upon mouse interaction
        # Responds to click event and calls command if None
        optiondefs = (
            # Define type of DirectGuiWidget
            ('pgFunc', PGButton, None),
            ('numStates', 4, None),
            ('state', DGG.NORMAL, None),
            ('relief', DGG.RAISED, None),
            ('invertedFrames', (1, ), None),
            # Command to be called on button click
            ('command', None, None),
            ('extraArgs', [], None),
            # Which mouse buttons can be used to click the button
            ('commandButtons', (DGG.LMB, ), self.setCommandButtons),
            # Sounds to be used for button events
            ('rolloverSound', DGG.getDefaultRolloverSound(),
             self.setRolloverSound),
            ('clickSound', DGG.getDefaultClickSound(), 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, DGG.INITOPT),
        )
        # Merge keyword options with default options
        self.defineoptions(kw, optiondefs)

        # Initialize superclasses
        DirectFrame.__init__(self, parent)

        # If specifed, add scaling to the pressed state to make it
        # look like the button is moving when you press it.  We have
        # to set up the node first, before we call initialise options;
        # but we can't actually apply the scale until we have the
        # bounding volume (which happens during initialise options).
        pressEffectNP = None
        if self['pressEffect']:
            pressEffectNP = self.stateNodePath[1].attachNewNode(
                'pressEffect', 1)
            self.stateNodePath[1] = pressEffectNP

        # Call option initialization functions
        self.initialiseoptions(DirectButton)

        # Now apply the scale.
        if pressEffectNP:
            bounds = self.getBounds()
            centerX = (bounds[0] + bounds[1]) / 2
            centerY = (bounds[2] + bounds[3]) / 2

            # Make a matrix that scales about the point
            mat = Mat4.translateMat(-centerX, 0, -centerY) * \
                  Mat4.scaleMat(0.98) * \
                  Mat4.translateMat(centerX, 0, centerY)
            pressEffectNP.setMat(mat)
Example #11
0
    # 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 = 'models/maps/noise.rgb',
                          geom = smiley,
                          text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
                          scale = .15, relief = 'raised',
                          # Here we set an option for a component of the button
                          geom1_color = (1, 0, 0, 1),
                          # Here is an example of a component group option
                          text_pos = (.6, -.8),
                          # Set audio characteristics
                          clickSound = DirectGuiGlobals.getDefaultClickSound(),
                          rolloverSound = DirectGuiGlobals.getDefaultRolloverSound()
                          )

        # You can set component or component group options after a gui item
        # has been created
        db['text_scale'] = 0.5
        db['command'] = lambda i = i: dummyCmd(i)

        # Bind the commands
        db.bind(DirectGuiGlobals.ENTER, lambda x, db = db: shrink(db))
        db.bind(DirectGuiGlobals.EXIT, lambda x, db = db: expand(db))
        db.bind(DirectGuiGlobals.B1PRESS, lambda x, db = db: ouch(db))
        # Pop up placer when button 2 is pressed
        db.bind(DirectGuiGlobals.B3PRESS, lambda x, db = db: db.place())
Example #12
0
    # (normal, press, rollover, and disabled), set scale = .15, and relief raised
    dbArray = []
    for i in range(10):
        db = DirectButton(
            parent=dl,
            image='models/maps/noise.rgb',
            geom=smiley,
            text=('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
            scale=.15,
            relief='raised',
            # Here we set an option for a component of the button
            geom1_color=(1, 0, 0, 1),
            # Here is an example of a component group option
            text_pos=(.6, -.8),
            # Set audio characteristics
            clickSound=DirectGuiGlobals.getDefaultClickSound(),
            rolloverSound=DirectGuiGlobals.getDefaultRolloverSound())

        # You can set component or component group options after a gui item
        # has been created
        db['text_scale'] = 0.5
        db['command'] = lambda i=i: dummyCmd(i)

        # Bind the commands
        db.bind(DirectGuiGlobals.ENTER, lambda x, db=db: shrink(db))
        db.bind(DirectGuiGlobals.EXIT, lambda x, db=db: expand(db))
        db.bind(DirectGuiGlobals.B1PRESS, lambda x, db=db: ouch(db))
        # Pop up placer when button 2 is pressed
        db.bind(DirectGuiGlobals.B3PRESS, lambda x, db=db: db.place())

        dbArray.append(db)