add ability to append normal funktions to Screen.onLayoutFinish call list
[enigma2.git] / lib / python / Components / ConditionalWidget.py
1 import skin
2 from GUIComponent import *
3
4 from enigma import *
5
6 class Widget(GUIComponent):
7         
8         SHOWN = 0
9         HIDDEN = 1
10         
11         def __init__(self):
12                 GUIComponent.__init__(self)
13                 self.instance = None
14                 self.state = self.SHOWN
15         
16         def GUIcreate(self, parent):
17                 self.instance = self.createWidget(parent)
18         
19         def GUIdelete(self):
20                 self.removeWidget(self.instance)
21                 self.instance = None
22         
23         def removeWidget(self, w):
24                 pass
25         
26         def showWidget(self):
27                 self.state = self.SHOWN
28                 self.instance.show()
29
30         def hideWidget(self):
31                 self.state = self.HIDDEN
32                 self.instance.hide()
33         
34 class ConditionalWidget(Widget):
35         def __init__(self, withTimer = True):
36                 Widget.__init__(self)
37                 
38                 self.setConnect(None)
39                 
40                 if (withTimer):
41                         self.conditionCheckTimer = eTimer()
42                         self.conditionCheckTimer.timeout.get().append(self.update)
43                         self.conditionCheckTimer.start(500)
44                 
45         def setConnect(self, conditionalFunction):
46                 self.conditionalFunction = conditionalFunction
47                 
48         def activateCondition(self, condition):
49                 if (condition):
50                         if (self.state == self.HIDDEN):
51                                 self.showWidget()
52                 else:
53                         if (self.state == self.SHOWN):
54                                 self.hideWidget()
55
56         def update(self):
57                 if (self.conditionalFunction != None):
58                         try:
59                                 self.conditionalFunction() # check, if the conditionalfunction is still valid
60                                 self.activateCondition(self.conditionalFunction())
61                         except:
62                                 self.conditionalFunction = None
63                                 self.activateCondition(False)
64                         
65
66
67                         
68                         
69 import time
70
71 class BlinkingWidget(Widget):
72         def __init__(self):
73                 Widget.__init__(self)
74                 
75                 self.blinking = True
76                 
77                 self.setBlinkTime(500)
78
79                 self.timer = eTimer()
80                 self.timer.timeout.get().append(self.blink)
81         
82         def setBlinkTime(self, time):
83                 self.blinktime = time
84                 
85         def blink(self):
86                 if self.blinking == True:
87                         if (self.state == self.SHOWN):
88                                 self.hideWidget()
89                         elif (self.state == self.HIDDEN):
90                                 self.showWidget()
91                         
92         def startBlinking(self):
93                 self.blinking = True
94                 self.timer.start(self.blinktime)
95                 
96         def stopBlinking(self):
97                 self.blinking = False
98                 if (self.state == self.SHOWN):
99                         self.hideWidget()
100                 self.timer.stop()
101                 
102 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
103         def __init__(self):
104                 BlinkingWidget.__init__(self)
105                 ConditionalWidget.__init__(self)
106                 
107         def activateCondition(self, condition):
108                 if (condition):
109                         if not self.blinking: # we are already blinking
110                                 self.startBlinking()
111                 else:
112                         if self.blinking: # we are blinking
113                                 self.stopBlinking()