reset the colorformat after av input switch to workaround a bug in the avs driver
[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         def move(self, x, y):
35                 self.instance.move(ePoint(int(x), int(y)))
36         
37 class ConditionalWidget(Widget):
38         def __init__(self, withTimer = True):
39                 Widget.__init__(self)
40                 
41                 self.setConnect(None)
42                 
43                 if (withTimer):
44                         self.conditionCheckTimer = eTimer()
45                         self.conditionCheckTimer.timeout.get().append(self.update)
46                         self.conditionCheckTimer.start(1000)
47                 
48         def setConnect(self, conditionalFunction):
49                 self.conditionalFunction = conditionalFunction
50                 
51         def activateCondition(self, condition):
52                 if (condition):
53                         if (self.state == self.HIDDEN):
54                                 self.showWidget()
55                 else:
56                         if (self.state == self.SHOWN):
57                                 self.hideWidget()
58
59         def update(self):
60                 if (self.conditionalFunction != None):
61                         try:
62                                 self.conditionalFunction() # check, if the conditionalfunction is still valid
63                                 self.activateCondition(self.conditionalFunction())
64                         except:
65                                 self.conditionalFunction = None
66                                 self.activateCondition(False)
67                         
68
69
70                         
71                         
72 import time
73
74 class BlinkingWidget(Widget):
75         def __init__(self):
76                 Widget.__init__(self)
77                 
78                 self.blinking = True
79                 
80                 self.setBlinkTime(500)
81
82                 self.timer = eTimer()
83                 self.timer.timeout.get().append(self.blink)
84         
85         def setBlinkTime(self, time):
86                 self.blinktime = time
87                 
88         def blink(self):
89                 if self.blinking == True:
90                         if (self.state == self.SHOWN):
91                                 self.hideWidget()
92                         elif (self.state == self.HIDDEN):
93                                 self.showWidget()
94                         
95         def startBlinking(self):
96                 self.blinking = True
97                 self.timer.start(self.blinktime)
98                 
99         def stopBlinking(self):
100                 self.blinking = False
101                 if (self.state == self.SHOWN):
102                         self.hideWidget()
103                 self.timer.stop()
104                 
105 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
106         def __init__(self):
107                 BlinkingWidget.__init__(self)
108                 ConditionalWidget.__init__(self)
109                 
110         def activateCondition(self, condition):
111                 if (condition):
112                         if not self.blinking: # we are already blinking
113                                 self.startBlinking()
114                 else:
115                         if self.blinking: # we are blinking
116                                 self.stopBlinking()