DirectLabel.py 1.7 KB

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