LUISpriteButton.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from LUIObject import LUIObject
  2. from LUISprite import LUISprite
  3. from LUIInitialState import LUIInitialState
  4. class LUISpriteButton(LUIObject):
  5. """ Simple button that uses only two images: Default and focus. """
  6. def __init__(self, template="ButtonDefault", **kwargs):
  7. LUIObject.__init__(self, x=0, y=0, solid=True)
  8. self._template = template
  9. self._button_sprite = LUISprite(self, template, "skin")
  10. if 'width' in kwargs:
  11. self._button_sprite.width = kwargs['width']
  12. if 'height' in kwargs:
  13. self._button_sprite.height = kwargs['height']
  14. LUIInitialState.init(self, kwargs)
  15. def on_mousedown(self, event):
  16. """ Internal on_mousedown handler. Do not override """
  17. self._button_sprite.set_texture(self.template + "Focus", "skin", resize=False)
  18. def on_mouseup(self, event):
  19. """ Internal on_mouseup handler. Do not override """
  20. self._button_sprite.set_texture(self.template, "skin", resize=False)
  21. def on_click(self, event):
  22. """ Internal onclick handler. Do not override """
  23. self.trigger_event("changed")