extend latitude/longitude range to 359.99 degrees
[enigma2.git] / lib / python / Components / ConditionalWidget.py
1 import skin
2 from GUIComponent import *
3
4 from enigma import *
5
6 class ConditionalWidget(GUIComponent):
7         def __init__(self, withTimer = True):
8                 GUIComponent.__init__(self)
9                 
10                 self.setConnect(None)
11                 
12                 if (withTimer):
13                         self.conditionCheckTimer = eTimer()
14                         self.conditionCheckTimer.timeout.get().append(self.update)
15                         self.conditionCheckTimer.start(1000)
16                 
17         def setConnect(self, conditionalFunction):
18                 self.conditionalFunction = conditionalFunction
19                 
20         def activateCondition(self, condition):
21                 if condition:
22                         self.state = self.SHOWN
23                 else:
24                         self.state = self.HIDDEN
25
26         def update(self):
27                 if (self.conditionalFunction != None):
28                         try:
29                                 self.conditionalFunction() # check, if the conditionalfunction is still valid
30                                 self.activateCondition(self.conditionalFunction())
31                         except:
32                                 self.conditionalFunction = None
33                                 self.activateCondition(False)
34                         
35 import time
36
37 class BlinkingWidget(GUIComponent):
38         def __init__(self):
39                 GUIComponent.__init__(self)
40                 
41                 self.blinking = True
42                 
43                 self.setBlinkTime(500)
44
45                 self.timer = eTimer()
46                 self.timer.timeout.get().append(self.blink)
47         
48         def setBlinkTime(self, time):
49                 self.blinktime = time
50                 
51         def blink(self):
52                 if self.blinking == True:
53                         if self.state == self.SHOWN:
54                                 self.hide()
55                         elif self.state == self.HIDDEN:
56                                 self.show()
57                         
58         def startBlinking(self):
59                 self.blinking = True
60                 self.timer.start(self.blinktime)
61                 
62         def stopBlinking(self):
63                 self.blinking = False
64                 if self.state == self.SHOWN:
65                         self.hide()
66                 self.timer.stop()
67                 
68 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
69         def __init__(self):
70                 BlinkingWidget.__init__(self)
71                 ConditionalWidget.__init__(self)
72                 
73         def activateCondition(self, condition):
74                 if (condition):
75                         if not self.blinking: # we are already blinking
76                                 self.startBlinking()
77                 else:
78                         if self.blinking: # we are blinking
79                                 self.stopBlinking()