Browse Source

*** empty log message ***

Joe Shochet 24 years ago
parent
commit
3a79e9709d

+ 2 - 0
direct/src/directtools/DirectSession.py

@@ -710,3 +710,5 @@ class DisplayRegionContext:
         # Continue the task
         # Continue the task
         return Task.cont
         return Task.cont
 
 
+# Create one
+__builtin__.direct = base.direct = DirectSession()

+ 1 - 0
direct/src/extensions/NodePath-extensions.py

@@ -784,6 +784,7 @@
         base.wantDIRECT = 1
         base.wantDIRECT = 1
         base.wantTk = 1
         base.wantTk = 1
         from ShowBaseGlobal import *
         from ShowBaseGlobal import *
+        from DirectSession import *
         import TkGlobal
         import TkGlobal
         import Placer
         import Placer
         return Placer.place(self)
         return Placer.place(self)

+ 3 - 0
direct/src/fsm/FSM.py

@@ -104,6 +104,9 @@ class FSM(DirectObject):
     def setFinalState(self, finalStateName):
     def setFinalState(self, finalStateName):
         """setFinalState(self, string)"""
         """setFinalState(self, string)"""
         self.__finalState = self.getStateNamed(finalStateName)
         self.__finalState = self.getStateNamed(finalStateName)
+
+    def requestFinalState(self):
+        self.request(self.__finalState.getName())
         
         
     def getCurrentState(self):
     def getCurrentState(self):
         """getCurrentState(self)"""
         """getCurrentState(self)"""

+ 14 - 7
direct/src/gui/Button.py

@@ -9,6 +9,9 @@ class Button(DirectObject):
 
 
     def __init__(self, name,
     def __init__(self, name,
                  label = None,
                  label = None,
+                 # If you have labels you want to use for the
+                 # various states, pass them as a list in labels
+                 labels = None,
                  scale = 0.1,
                  scale = 0.1,
                  width = None,
                  width = None,
                  align = None,
                  align = None,
@@ -27,7 +30,7 @@ class Button(DirectObject):
         self.width = width
         self.width = width
 
 
         # if no label given, use the button name
         # if no label given, use the button name
-        if (label == None):
+        if (label == None) and (labels == None):
             label = self.name
             label = self.name
 
 
         self.inactive = inactive
         self.inactive = inactive
@@ -60,7 +63,7 @@ class Button(DirectObject):
             self.lUp = Label.modelLabel(label,
             self.lUp = Label.modelLabel(label,
                                         geomRect = geomRect,
                                         geomRect = geomRect,
                                         style = upStyle,
                                         style = upStyle,
-                                        scale = scale,
+                                        scale = (scale, scale),
                                         drawOrder = drawOrder)
                                         drawOrder = drawOrder)
 
 
             if width == None:
             if width == None:
@@ -70,23 +73,27 @@ class Button(DirectObject):
             self.lLit = Label.modelLabel(label,
             self.lLit = Label.modelLabel(label,
                                          geomRect = geomRect,
                                          geomRect = geomRect,
                                          style = litStyle,
                                          style = litStyle,
-                                         scale = scale,
+                                         scale = (scale, scale),
                                          drawOrder = drawOrder)
                                          drawOrder = drawOrder)
             self.lDown = Label.modelLabel(label,
             self.lDown = Label.modelLabel(label,
                                           geomRect = geomRect,
                                           geomRect = geomRect,
                                           style = downStyle,
                                           style = downStyle,
-                                          scale = scale,
+                                          scale = (scale, scale),
                                           drawOrder = drawOrder)
                                           drawOrder = drawOrder)
             if supportInactive:
             if supportInactive:
                 self.lInactive = Label.modelLabel(label,
                 self.lInactive = Label.modelLabel(label,
                                                   geomRect = geomRect,
                                                   geomRect = geomRect,
                                                   style = inactiveStyle,
                                                   style = inactiveStyle,
-                                                  scale = scale,
+                                                  scale = (scale, scale),
                                                   drawOrder = drawOrder)
                                                   drawOrder = drawOrder)
 
 
         else:
         else:
-            # label provided, use it for all labels
-            self.lUp = self.lLit = self.lDown = self.lInactive = label
+            if labels:
+                # label provided, use it for all labels
+                self.lUp, self.lLit, self.lDown, self.lInactive = labels
+            else:
+                # label provided, use it for all labels
+                self.lUp = self.lLit = self.lDown = self.lInactive = label
             if width == None:
             if width == None:
                 width = self.lUp.getWidth()
                 width = self.lUp.getWidth()
 
 

+ 12 - 21
direct/src/gui/Label.py

@@ -157,56 +157,47 @@ def textLabelAndText(string, style,
 def modelLabel(model,
 def modelLabel(model,
                geomRect = None,
                geomRect = None,
                style = None,
                style = None,
-               scale = 0.1,
+               scale = (0.1, 0.1),
                drawOrder = getDefaultDrawOrder()):
                drawOrder = getDefaultDrawOrder()):
-
     # Preserve transitions on the arc by creating an intervening node.
     # Preserve transitions on the arc by creating an intervening node.
     topnode = NamedNode('model')
     topnode = NamedNode('model')
     topnp = NodePath(topnode)
     topnp = NodePath(topnode)
     mi = model.instanceTo(topnp)
     mi = model.instanceTo(topnp)
-    mi.setScale(scale)
+    mi.setScale(scale[0], scale[0], scale[1])
     mi.setBin('fixed', drawOrder)
     mi.setBin('fixed', drawOrder)
-
     if style != None:
     if style != None:
         # For a modelLabel, the style determines the color that may be
         # For a modelLabel, the style determines the color that may be
         # applied.
         # applied.
-        color = None
-        
+        color = None        
         # The style might *itself* be a four-component color.
         # The style might *itself* be a four-component color.
         if (isinstance(style, types.TupleType) or
         if (isinstance(style, types.TupleType) or
             isinstance(style, VBase4)):
             isinstance(style, VBase4)):
             color = style
             color = style
-
         # Otherwise, there might be a predefined default color for one
         # Otherwise, there might be a predefined default color for one
         # of the canned styles.  Most don't have a default color,
         # of the canned styles.  Most don't have a default color,
         # though.
         # though.
         elif style == ButtonInactive:
         elif style == ButtonInactive:
-            color = (0.5, 0.5, 0.5, 1.0)
-            
+            color = (0.5, 0.5, 0.5, 1.0)            
         if color != None:
         if color != None:
             mi.setColor(color[0], color[1], color[2], color[3])
             mi.setColor(color[0], color[1], color[2], color[3])
             if color[3] != 1.0:
             if color[3] != 1.0:
-                mi.setTransparency(1)
-        
-
+                mi.setTransparency(1)        
     if geomRect == None:
     if geomRect == None:
         geomRect = (1, 1)
         geomRect = (1, 1)
-
     if len(geomRect) == 2:
     if len(geomRect) == 2:
         # If we got only two parameters, it's height and width.
         # If we got only two parameters, it's height and width.
         label = GuiLabel.makeModelLabel(topnode,
         label = GuiLabel.makeModelLabel(topnode,
-                                        geomRect[0] * scale,
-                                        geomRect[1] * scale)
+                                        geomRect[0] * scale[0],
+                                        geomRect[1] * scale[1])
     elif len(geomRect) == 4:
     elif len(geomRect) == 4:
         # If we got four, they're left, right, bottom, top.
         # If we got four, they're left, right, bottom, top.
         label = GuiLabel.makeModelLabel(topnode,
         label = GuiLabel.makeModelLabel(topnode,
-                                        geomRect[0] * scale,
-                                        geomRect[1] * scale,
-                                        geomRect[2] * scale,
-                                        geomRect[3] * scale)
+                                        geomRect[0] * scale[0],
+                                        geomRect[1] * scale[0],
+                                        geomRect[2] * scale[1],
+                                        geomRect[3] * scale[1])
     else:
     else:
-        raise ValueError
-    
+        raise ValueError    
     label.setDrawOrder(drawOrder)
     label.setDrawOrder(drawOrder)
     return label
     return label
                                     
                                     

+ 30 - 12
direct/src/gui/ScrollingLabel.py

@@ -19,7 +19,10 @@ class ScrollingLabel(PandaObject.PandaObject):
                  width = None,
                  width = None,
                  drawOrder = getDefaultDrawOrder(),
                  drawOrder = getDefaultDrawOrder(),
                  font = getDefaultFont(),
                  font = getDefaultFont(),
-                 showLabels = 1):
+                 showLabels = 1,
+                 leftLabels = None,
+                 rightLabels = None,
+                 ):
 
 
         self.name = name
         self.name = name
         if (label == None):
         if (label == None):
@@ -65,22 +68,37 @@ class ScrollingLabel(PandaObject.PandaObject):
                             self.title)
                             self.title)
         
         
         # create the scroll buttons
         # create the scroll buttons
-        self.leftButton = Button.Button(self.eventName + "-left",
-                                        label = " < ",
-                                        scale = scale,
-                                        drawOrder = drawOrder,
-                                        font = font, event = "left-button")
+        if leftLabels:
+            self.leftButton = Button.Button(self.eventName + "-left",
+                                            labels = leftLabels,
+                                            scale = scale,
+                                            drawOrder = drawOrder,
+                                            font = font, event = "left-button")
+        else:
+            self.leftButton = Button.Button(self.eventName + "-left",
+                                            label = " < ",
+                                            scale = scale,
+                                            drawOrder = drawOrder,
+                                            font = font, event = "left-button")
         self.leftButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
         self.leftButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
         self.frame.addItem(self.leftButton)
         self.frame.addItem(self.leftButton)
         self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.UNDER,
         self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.UNDER,
                             self.title)
                             self.title)
         self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT,
         self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT,
-                            self.title)        
-        self.rightButton = Button.Button(self.eventName + "-right",
-                                         label = " > ",
-                                         scale = scale,
-                                         drawOrder = drawOrder,
-                                         font = font, event = "right-button")
+                            self.title)
+
+        if rightLabels:
+            self.rightButton = Button.Button(self.eventName + "-right",
+                                             labels = rightLabels,
+                                             scale = scale,
+                                             drawOrder = drawOrder,
+                                             font = font, event = "right-button")
+        else:
+            self.rightButton = Button.Button(self.eventName + "-right",
+                                             label = " > ",
+                                             scale = scale,
+                                             drawOrder = drawOrder,
+                                             font = font, event = "right-button")            
         self.rightButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
         self.rightButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
         self.frame.addItem(self.rightButton)
         self.frame.addItem(self.rightButton)
         self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.UNDER,
         self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.UNDER,

+ 6 - 6
direct/src/showbase/DirectObject.py

@@ -6,16 +6,16 @@ class DirectObject:
     """
     """
     This is the class that all Direct/SAL classes should inherit from
     This is the class that all Direct/SAL classes should inherit from
     """
     """
-    def __del__(self):
+    #def __del__(self):
         # print "Destructing: ", self.__class__.__name__
         # print "Destructing: ", self.__class__.__name__
         
         
         # This is really old and we really should not be relying on it
         # This is really old and we really should not be relying on it
         # One day I'll see if anybody still needs this
         # One day I'll see if anybody still needs this
-	try: 
-	    self.cleanup()
-	except AttributeError:
-	    # No cleanup() method defined
-            pass
+	#try: 
+	#    self.cleanup()
+	#except AttributeError:
+	#    # No cleanup() method defined
+        #    pass
 
 
     # Event Handling
     # Event Handling
 
 

+ 3 - 4
direct/src/showbase/Messenger.py

@@ -122,7 +122,7 @@ class Messenger:
 
 
         if self.dict.has_key(event):
         if self.dict.has_key(event):
             acceptorDict = self.dict[event]
             acceptorDict = self.dict[event]
-            for object in acceptorDict.keys():
+            for object in self.dict[event].keys():
                 # We have to make this apparently redundant check, because
                 # We have to make this apparently redundant check, because
                 # it is possible that one object removes its own hooks
                 # it is possible that one object removes its own hooks
                 # in response to a handler called by a previous object.
                 # in response to a handler called by a previous object.
@@ -136,10 +136,9 @@ class Messenger:
                         # have done an ignore.
                         # have done an ignore.
                         if acceptorDict.has_key(object):
                         if acceptorDict.has_key(object):
                             del acceptorDict[object]
                             del acceptorDict[object]
-                        # If this dictionary is now empty, remove the event
+                        # If the dictionary at this event is now empty, remove the event
                         # entry from the Messenger alltogether
                         # entry from the Messenger alltogether
-                        if ((len(acceptorDict) == 0) and
-                            (self.dict.has_key(event))):
+                        if (self.dict.has_key(event) and (len(self.dict[event]) == 0)):
                             del self.dict[event]
                             del self.dict[event]
 
 
     def clear(self):
     def clear(self):

+ 0 - 1
direct/src/showbase/ShowBaseGlobal.py

@@ -23,7 +23,6 @@ __builtin__.directNotify = directNotify
 # Initialize DIRECT
 # Initialize DIRECT
 if base.wantDIRECT:
 if base.wantDIRECT:
     from DirectSession import *
     from DirectSession import *
-    __builtin__.direct = base.direct = DirectSession()
     direct.enable()
     direct.enable()
 else:
 else:
     # Otherwise set the values to None
     # Otherwise set the values to None