replace software update plugin with a more user friendly approach
[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                         print "warning, skin is missing some elements."
35                         return
36
37                 skin.applyAllAttributes(self.instance, desktop, self.skinAttributes)
38
39         def move(self, x, y):
40                 self.instance.move(ePoint(int(x), int(y)))
41
42         def show(self):
43                 self.__visible = 1
44                 if self.instance is not None:
45                         self.instance.show()
46
47         def hide(self):
48                 self.__visible = 0
49                 if self.instance is not None:
50                         self.instance.hide()
51
52         def getVisible(self):
53                 return self.__visible
54         
55         def setVisible(self, visible):
56                 if visible:
57                         self.show()
58                 else:
59                         self.hide()
60
61         visible = property(getVisible, setVisible)
62
63         def setPosition(self, x, y):
64                 self.instance.move(ePoint(int(x), int(y)))
65
66         def getPosition(self):
67                 p = self.instance.position()
68                 return (p.x(), p.y())
69
70         position = property(getPosition, setPosition)
71
72         # default implementation for only one widget per component
73         # feel free to override!
74         def GUIcreate(self, parent):
75                 self.instance = self.createWidget(parent)
76                 self.postWidgetCreate(self.instance)
77         
78         def GUIdelete(self):
79                 self.preWidgetRemove(self.instance)
80                 self.instance = None
81
82         # default for argumentless widget constructor
83         def createWidget(self, parent):
84                 return self.GUI_WIDGET(parent)
85
86         def postWidgetCreate(self, instance):
87                 pass
88         
89         def preWidgetRemove(self, instance):
90                 pass