add possibility to get frontend type and frontend number
[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.visible = 1
11                 self.skinAttributes = None
12         
13         def execBegin(self):
14                 pass
15         
16         def execEnd(self):
17                 pass
18         
19         def onShow(self):
20                 pass
21
22         def onHide(self):
23                 pass
24         
25         def destroy(self):
26                 self.__dict__.clear()
27         
28         # this works only with normal widgets - if you don't have self.instance, override this.
29         def applySkin(self, desktop):
30                 if not self.visible:
31                         self.instance.hide()
32                 
33                 if self.skinAttributes is None:
34                         return False
35
36                 skin.applyAllAttributes(self.instance, desktop, self.skinAttributes)
37                 return True
38
39         def move(self, x, y = None):
40                 # we assume, that x is already an ePoint
41                 if y is None:
42                         self.instance.move(x)
43                 else:
44                         self.instance.move(ePoint(int(x), int(y)))
45                 
46         def resize(self, size):
47                 self.instance.resize(size)
48                 
49         def setZPosition(self, z):
50                 self.instance.setZPosition(z)
51
52         def show(self):
53                 self.__visible = 1
54                 if self.instance is not None:
55                         self.instance.show()
56
57         def hide(self):
58                 self.__visible = 0
59                 if self.instance is not None:
60                         self.instance.hide()
61
62         def getVisible(self):
63                 return self.__visible
64         
65         def setVisible(self, visible):
66                 if visible:
67                         self.show()
68                 else:
69                         self.hide()
70
71         visible = property(getVisible, setVisible)
72
73         def setPosition(self, x, y):
74                 self.instance.move(ePoint(int(x), int(y)))
75
76         def getPosition(self):
77                 p = self.instance.position()
78                 return (p.x(), p.y())
79
80         position = property(getPosition, setPosition)
81
82         # default implementation for only one widget per component
83         # feel free to override!
84         def GUIcreate(self, parent):
85                 self.instance = self.createWidget(parent)
86                 self.postWidgetCreate(self.instance)
87         
88         def GUIdelete(self):
89                 self.preWidgetRemove(self.instance)
90                 self.instance = None
91
92         # default for argumentless widget constructor
93         def createWidget(self, parent):
94                 return self.GUI_WIDGET(parent)
95
96         def postWidgetCreate(self, instance):
97                 pass
98         
99         def preWidgetRemove(self, instance):
100                 pass