fix a small logic-problem
[enigma2.git] / lib / python / Components / Pixmap.py
1 import skin
2 from GUIComponent import *
3
4 from enigma import *
5
6 class Pixmap(GUIComponent):
7         """Pixmap can be used for components which diplay a pixmap"""
8         
9         SHOWN = 0
10         HIDDEN = 1
11         
12         def __init__(self):
13                 GUIComponent.__init__(self)
14                 self.instance = None
15                 self.state = self.SHOWN
16         
17         def GUIcreate(self, parent):
18                 self.instance = self.createWidget(parent)
19         
20         def GUIdelete(self):
21                 self.removeWidget(self.instance)
22                 self.instance = None
23         
24         def getePixmap(self, parent):
25                 #pixmap = ePixmap(parent)
26                 #pixmap.setPixmapFromFile(self.filename)
27                 return ePixmap(parent)
28         
29         def createWidget(self, parent):
30                 return self.getePixmap(parent)
31
32         def removeWidget(self, w):
33                 pass
34         
35         def showPixmap(self):
36                 self.state = self.SHOWN
37                 self.instance.show()
38
39         def hidePixmap(self):
40                 self.state = self.HIDDEN
41                 self.instance.hide()
42         
43         def removeWidget(self, instance):
44                 pass
45
46 class PixmapConditional(Pixmap):
47         def __init__(self, withTimer = True):
48                 Pixmap.__init__(self)
49                 
50                 self.setConnect(None)
51                 
52                 if (withTimer):
53                         self.conditionCheckTimer = eTimer()
54                         self.conditionCheckTimer.timeout.get().append(self.update)
55                         self.conditionCheckTimer.start(1000)
56                 
57         def setConnect(self, conditionalFunction):
58                 self.conditionalFunction = conditionalFunction
59                 
60         def activateCondition(self, condition):
61                 if (condition):
62                         if (self.state == self.HIDDEN):
63                                 self.showPixmap()
64                 else:
65                         if (self.state == self.SHOWN):
66                                 self.hidePixmap()
67
68         def update(self):
69                 if (self.conditionalFunction != None):
70                         try:
71                                 self.conditionalFunction() # check, if the conditionalfunction is still valid
72                         except:
73                                 self.conditionalFunction = None
74                                 self.activateCondition(False)
75                         
76                         self.activateCondition(self.conditionalFunction())