DirectLabel.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from DirectFrame import *
  2. class DirectLabel(DirectFrame):
  3. """
  4. DirectLabel(parent) - Create a DirectGuiWidget which has multiple
  5. states. User explicitly chooses a state to display
  6. """
  7. def __init__(self, parent = aspect2d, **kw):
  8. # Inherits from DirectFrame
  9. # A Direct Frame can have:
  10. # - A background texture (pass in path to image, or Texture Card)
  11. # - A midground geometry item (pass in geometry)
  12. # - A foreground text Node (pass in text string or Onscreen Text)
  13. # For a direct label:
  14. # Each label has 1 or more states
  15. # The same image/geom/text can be used for all states or each
  16. # state can have a different text/geom/image
  17. # State transitions happen under user control
  18. optiondefs = (
  19. # Define type of DirectGuiWidget
  20. ('pgFunc', PGItem, None),
  21. ('numStates', 1, None),
  22. ('state', self.inactiveInitState, None),
  23. ('activeState', 0, self.setActiveState),
  24. )
  25. # Merge keyword options with default options
  26. self.defineoptions(kw, optiondefs)
  27. # Initialize superclasses
  28. DirectFrame.__init__(self, parent)
  29. # Call option initialization functions
  30. self.initialiseoptions(DirectLabel)
  31. def setActiveState(self):
  32. """ setActiveState - change label to specifed state """
  33. self.guiItem.setState(self['activeState'])