add support for multi angle dvds
[enigma2.git] / lib / python / Components / GUIComponent.py
1 import skin
2
3 from enigma import ePoint, eSize
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, parent):
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, parent.scale)
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, x, y = None):
50                 self.width = x
51                 self.height = y
52                 if y is None:
53                         self.instance.resize(x)
54                 else:
55                         self.instance.resize(eSize(int(x), int(y)))
56
57         def setZPosition(self, z):
58                 self.instance.setZPosition(z)
59
60         def show(self):
61                 old = self.__visible
62                 self.__visible = 1
63                 if self.instance is not None:
64                         self.instance.show()
65                 if old != self.__visible:
66                         for fnc in self.onVisibilityChange:
67                                 fnc(True)
68
69         def hide(self):
70                 old = self.__visible
71                 self.__visible = 0
72                 if self.instance is not None:
73                         self.instance.hide()
74                 if old != self.__visible:
75                         for fnc in self.onVisibilityChange:
76                                 fnc(False)
77
78         def getVisible(self):
79                 return self.__visible
80         
81         def setVisible(self, visible):
82                 if visible:
83                         self.show()
84                 else:
85                         self.hide()
86
87         visible = property(getVisible, setVisible)
88
89         def setPosition(self, x, y):
90                 self.instance.move(ePoint(int(x), int(y)))
91
92         def getPosition(self):
93                 p = self.instance.position()
94                 return (p.x(), p.y())
95         
96         def getWidth(self):
97                 return self.width
98         
99         def getHeight(self):
100                 return self.height
101
102         position = property(getPosition, setPosition)
103
104         # default implementation for only one widget per component
105         # feel free to override!
106         def GUIcreate(self, parent):
107                 self.instance = self.createWidget(parent)
108                 self.postWidgetCreate(self.instance)
109         
110         def GUIdelete(self):
111                 self.preWidgetRemove(self.instance)
112                 self.instance = None
113
114         # default for argumentless widget constructor
115         def createWidget(self, parent):
116                 return self.GUI_WIDGET(parent)
117
118         def postWidgetCreate(self, instance):
119                 pass
120         
121         def preWidgetRemove(self, instance):
122                 pass