X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/fd07ec4a3d617bb1ee1f7ebdf6791014586efd84..d186d7e6752018badb476ab0d4b87aa9dcea8aac:/lib/python/Components/GUIComponent.py diff --git a/lib/python/Components/GUIComponent.py b/lib/python/Components/GUIComponent.py index b84cf8c2..deb8b34a 100644 --- a/lib/python/Components/GUIComponent.py +++ b/lib/python/Components/GUIComponent.py @@ -2,11 +2,15 @@ import skin from enigma import ePoint -class GUIComponent: +class GUIComponent(object): """ GUI component """ def __init__(self): - pass + self.instance = None + self.onVisibilityChange = [ ] + self.__visible = 0 + self.visible = 1 + self.skinAttributes = None def execBegin(self): pass @@ -14,9 +18,93 @@ class GUIComponent: def execEnd(self): pass + def onShow(self): + pass + + def onHide(self): + pass + + def destroy(self): + self.__dict__.clear() + # this works only with normal widgets - if you don't have self.instance, override this. def applySkin(self, desktop): + if not self.visible: + self.instance.hide() + + if self.skinAttributes is None: + return False + skin.applyAllAttributes(self.instance, desktop, self.skinAttributes) + return True + + def move(self, x, y = None): + # we assume, that x is already an ePoint + if y is None: + self.instance.move(x) + else: + self.instance.move(ePoint(int(x), int(y))) + + def resize(self, size): + self.instance.resize(size) + + def setZPosition(self, z): + self.instance.setZPosition(z) + + def show(self): + old = self.__visible + self.__visible = 1 + if self.instance is not None: + self.instance.show() + if old != self.__visible: + for fnc in self.onVisibilityChange: + fnc(True) + + def hide(self): + old = self.__visible + self.__visible = 0 + if self.instance is not None: + self.instance.hide() + if old != self.__visible: + for fnc in self.onVisibilityChange: + fnc(False) + + def getVisible(self): + return self.__visible + + def setVisible(self, visible): + if visible: + self.show() + else: + self.hide() + + visible = property(getVisible, setVisible) + + def setPosition(self, x, y): + self.instance.move(ePoint(int(x), int(y))) - def move(self, x, y): - self.instance.move(ePoint(int(x), int(y))) \ No newline at end of file + def getPosition(self): + p = self.instance.position() + return (p.x(), p.y()) + + position = property(getPosition, setPosition) + + # default implementation for only one widget per component + # feel free to override! + def GUIcreate(self, parent): + self.instance = self.createWidget(parent) + self.postWidgetCreate(self.instance) + + def GUIdelete(self): + self.preWidgetRemove(self.instance) + self.instance = None + + # default for argumentless widget constructor + def createWidget(self, parent): + return self.GUI_WIDGET(parent) + + def postWidgetCreate(self, instance): + pass + + def preWidgetRemove(self, instance): + pass