LUILabel.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from panda3d.lui import LUIText
  2. from LUIObject import LUIObject
  3. from LUIInitialState import LUIInitialState
  4. __all__ = ["LUILabel"]
  5. class LUILabel(LUIObject):
  6. """ A simple label, displaying text. """
  7. # Default variables which can be overridden by skins
  8. DEFAULT_COLOR = (0.9, 0.9, 0.9, 1)
  9. DEFAULT_USE_SHADOW = True
  10. def __init__(self, text=u"Label", shadow=None, font_size=14, font="label", color=None, wordwrap=False, **kwargs):
  11. """ Creates a new label. If shadow is True, a small text shadow will be
  12. rendered below the actual text. """
  13. LUIObject.__init__(self)
  14. LUIInitialState.init(self, kwargs)
  15. self._text = LUIText(
  16. self,
  17. (text),
  18. font,
  19. font_size,
  20. 0,
  21. 0,
  22. wordwrap
  23. )
  24. self._text.z_offset = 1
  25. if color is None:
  26. self.color = LUILabel.DEFAULT_COLOR
  27. else:
  28. self.color = color
  29. if shadow is None:
  30. shadow = LUILabel.DEFAULT_USE_SHADOW
  31. self._have_shadow = shadow
  32. if self._have_shadow:
  33. self._shadow_text = LUIText(
  34. self,
  35. (text),
  36. font,
  37. font_size,
  38. 0,
  39. 0,
  40. wordwrap
  41. )
  42. self._shadow_text.top = 1
  43. self._shadow_text.color = (0,0,0,0.6)
  44. def get_text_handle(self):
  45. """ Returns a handle to the internal used LUIText object """
  46. return self._text
  47. text_handle = property(get_text_handle)
  48. def get_text(self):
  49. """ Returns the current text of the label """
  50. return self._text.text
  51. def set_text(self, text):
  52. """ Sets the text of the label """
  53. self._text.text = (text)
  54. if self._have_shadow:
  55. self._shadow_text.text = (text)
  56. text = property(get_text, set_text)
  57. def get_color(self):
  58. """ Returns the current color of the label's text """
  59. return self._text.color
  60. def set_color(self, color):
  61. """ Sets the color of the label's text """
  62. self._text.color = color
  63. color = property(get_color, set_color)