__init__.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!./bin/python3
  2. import os
  3. EVENT_UP = "event_up"
  4. EVENT_DOWN = "event_down"
  5. EVENT_LEFT = "event_left"
  6. EVENT_RIGHT = "event_right"
  7. class HandlerExit(Exception):
  8. pass
  9. class BaseHandler:
  10. def __init__(self, config, display):
  11. self.display = display
  12. self.config = config
  13. def setPlaylistItem(self, item):
  14. '''
  15. Called with the selected item.
  16. '''
  17. self.item = item
  18. def update(self, text=None, highlight=-1, title=None, img=None):
  19. '''
  20. Called when the handler should update the display.
  21. '''
  22. self.display.update(text, highlight, title, img)
  23. def stop(self):
  24. '''
  25. Called when the handler should stop.
  26. '''
  27. pass
  28. def emitEvent(self, event):
  29. '''
  30. Called when an event has happened.
  31. '''
  32. if event == EVENT_LEFT:
  33. self.stop()
  34. raise HandlerExit
  35. def toDisplayName(self, s):
  36. s = os.path.splitext(s)[0]
  37. return s.replace("_", " ").title()