c1baceb25400a1c98d0c85c9e499a296e9a5579d
[vuplus_dvbapp] / lib / python / Components / ConditionalWidget.py
1 from GUIComponent import GUIComponent
2 from enigma import eTimer
3
4 class ConditionalWidget(GUIComponent):
5         def __init__(self, withTimer = True):
6                 GUIComponent.__init__(self)
7                 
8                 self.setConnect(None)
9                 
10                 if (withTimer):
11                         self.conditionCheckTimer = eTimer()
12                         self.conditionCheckTimer.timeout.get().append(self.update)
13                         self.conditionCheckTimer.start(1000)
14                 
15         def setConnect(self, conditionalFunction):
16                 self.conditionalFunction = conditionalFunction
17                 
18         def activateCondition(self, condition):
19                 if condition:
20                         self.visible = 1
21                 else:
22                         self.visible = 0
23
24         def update(self):
25                 if (self.conditionalFunction != None):
26                         try:
27                                 self.activateCondition(self.conditionalFunction())
28                         except:
29                                 self.conditionalFunction = None
30                                 self.activateCondition(False)
31
32 class BlinkingWidget(GUIComponent):
33         def __init__(self):
34                 GUIComponent.__init__(self)
35                 
36                 self.blinking = True
37                 
38                 self.setBlinkTime(500)
39
40                 self.timer = eTimer()
41                 self.timer.timeout.get().append(self.blink)
42         
43         def setBlinkTime(self, time):
44                 self.blinktime = time
45                 
46         def blink(self):
47                 if self.blinking == True:
48                         self.visible = not self.visible
49                         
50         def startBlinking(self):
51                 self.blinking = True
52                 self.timer.start(self.blinktime)
53                 
54         def stopBlinking(self):
55                 self.blinking = False
56                 if self.visible:
57                         self.hide()
58                 self.timer.stop()
59
60 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
61         def __init__(self):
62                 BlinkingWidget.__init__(self)
63                 ConditionalWidget.__init__(self)
64                 
65         def activateCondition(self, condition):
66                 if (condition):
67                         if not self.blinking: # we are already blinking
68                                 self.startBlinking()
69                 else:
70                         if self.blinking: # we are blinking
71                                 self.stopBlinking()