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