properly handle negative time values
[enigma2.git] / lib / python / Components / ConditionalWidget.py
1 from GUIComponent import *
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.conditionalFunction() # check, if the conditionalfunction is still valid
28                                 self.activateCondition(self.conditionalFunction())
29                         except:
30                                 self.conditionalFunction = None
31                                 self.activateCondition(False)
32                         
33 import time
34
35 class BlinkingWidget(GUIComponent):
36         def __init__(self):
37                 GUIComponent.__init__(self)
38                 
39                 self.blinking = True
40                 
41                 self.setBlinkTime(500)
42
43                 self.timer = eTimer()
44                 self.timer.timeout.get().append(self.blink)
45         
46         def setBlinkTime(self, time):
47                 self.blinktime = time
48                 
49         def blink(self):
50                 if self.blinking == True:
51                         self.visible = not self.visible
52                         
53         def startBlinking(self):
54                 self.blinking = True
55                 self.timer.start(self.blinktime)
56                 
57         def stopBlinking(self):
58                 self.blinking = False
59                 if self.visible:
60                         self.hide()
61                 self.timer.stop()
62
63 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
64         def __init__(self):
65                 BlinkingWidget.__init__(self)
66                 ConditionalWidget.__init__(self)
67                 
68         def activateCondition(self, condition):
69                 if (condition):
70                         if not self.blinking: # we are already blinking
71                                 self.startBlinking()
72                 else:
73                         if self.blinking: # we are blinking
74                                 self.stopBlinking()