Enigma2 plugin to to play various online streams (mostly Latvian).

GUIComponent.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import skin
  2. from enigma import ePoint, eSize
  3. class GUIComponent(object):
  4. """ GUI component """
  5. def __init__(self):
  6. self.instance = None
  7. self.onVisibilityChange = [ ]
  8. self.__visible = 0
  9. self.visible = 1
  10. self.skinAttributes = None
  11. self.deprecationInfo = None
  12. def execBegin(self):
  13. pass
  14. def execEnd(self):
  15. pass
  16. def onShow(self):
  17. pass
  18. def onHide(self):
  19. pass
  20. def destroy(self):
  21. self.__dict__.clear()
  22. # this works only with normal widgets - if you don't have self.instance, override this.
  23. def applySkin(self, desktop, parent):
  24. if not self.visible:
  25. self.instance.hide()
  26. if self.skinAttributes is None:
  27. return False
  28. skin.applyAllAttributes(self.instance, desktop, self.skinAttributes, parent.scale)
  29. return True
  30. def move(self, x, y = None):
  31. # we assume, that x is already an ePoint
  32. if y is None:
  33. self.instance.move(x)
  34. else:
  35. self.instance.move(ePoint(int(x), int(y)))
  36. def resize(self, x, y = None):
  37. self.width = x
  38. self.height = y
  39. if y is None:
  40. self.instance.resize(x)
  41. else:
  42. self.instance.resize(eSize(int(x), int(y)))
  43. def setZPosition(self, z):
  44. self.instance.setZPosition(z)
  45. def show(self):
  46. old = self.__visible
  47. self.__visible = 1
  48. if self.instance is not None:
  49. self.instance.show()
  50. if old != self.__visible:
  51. for fnc in self.onVisibilityChange:
  52. fnc(True)
  53. def hide(self):
  54. old = self.__visible
  55. self.__visible = 0
  56. if self.instance is not None:
  57. self.instance.hide()
  58. if old != self.__visible:
  59. for fnc in self.onVisibilityChange:
  60. fnc(False)
  61. def getVisible(self):
  62. return self.__visible
  63. def setVisible(self, visible):
  64. if visible:
  65. self.show()
  66. else:
  67. self.hide()
  68. visible = property(getVisible, setVisible)
  69. def setPosition(self, x, y):
  70. self.instance.move(ePoint(int(x), int(y)))
  71. def getPosition(self):
  72. p = self.instance.position()
  73. return p.x(), p.y()
  74. def getWidth(self):
  75. return self.width
  76. def getHeight(self):
  77. return self.height
  78. position = property(getPosition, setPosition)
  79. # default implementation for only one widget per component
  80. # feel free to override!
  81. def GUIcreate(self, parent):
  82. self.instance = self.createWidget(parent)
  83. self.postWidgetCreate(self.instance)
  84. def GUIdelete(self):
  85. self.preWidgetRemove(self.instance)
  86. self.instance = None
  87. # default for argumentless widget constructor
  88. def createWidget(self, parent):
  89. return self.GUI_WIDGET(parent)
  90. def postWidgetCreate(self, instance):
  91. pass
  92. def preWidgetRemove(self, instance):
  93. pass