don't crash if time is *really* invalid
[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         SHOWN = 0
9         HIDDEN = 1
10         
11         def __init__(self):
12                 self.instance = None
13                 self.state = self.SHOWN
14         
15         def execBegin(self):
16                 pass
17         
18         def execEnd(self):
19                 pass
20         
21         def onShow(self):
22                 pass
23
24         def onHide(self):
25                 pass
26         
27         def destroy(self):
28                 pass
29         
30         # this works only with normal widgets - if you don't have self.instance, override this.
31         def applySkin(self, desktop):
32                 if self.state == self.HIDDEN:
33                         self.instance.hide()
34                 skin.applyAllAttributes(self.instance, desktop, self.skinAttributes)
35
36         def move(self, x, y):
37                 self.instance.move(ePoint(int(x), int(y)))
38
39         def show(self):
40                 self.__state = self.SHOWN
41                 if self.instance is not None:
42                         self.instance.show()
43
44         def hide(self):
45                 self.__state = self.HIDDEN
46                 if self.instance is not None:
47                         self.instance.hide()
48
49         def getState(self):
50                 return self.__state
51         
52         def setState(self, state):
53                 if state == self.SHOWN:
54                         self.show()
55                 elif state == self.HIDDEN:
56                         self.hide()
57
58         state = property(getState, setState)
59
60         def setPosition(self, x, y):
61                 self.instance.move(ePoint(int(x), int(y)))
62
63         def getPosition(self):
64                 p = self.instance.position()
65                 return (p.x(), p.y())
66
67         position = property(getPosition, setPosition)
68
69         # default implementation for only one widget per component
70         # feel free to override!
71         def GUIcreate(self, parent):
72                 self.instance = self.createWidget(parent)
73                 self.postWidgetCreate(self.instance)
74         
75         def GUIdelete(self):
76                 self.preWidgetRemove(self.instance)
77                 self.instance = None
78
79         # default for argumentless widget constructor
80         def createWidget(self, parent):
81                 return self.GUI_WIDGET(parent)
82
83         def postWidgetCreate(self, instance):
84                 pass
85         
86         def preWidgetRemove(self, instance):
87                 pass