load cutlist on initial create
[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.visible = 1
23                 else:
24                         self.visible = 0
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                         self.visible = not self.visible
54                         
55         def startBlinking(self):
56                 self.blinking = True
57                 self.timer.start(self.blinktime)
58                 
59         def stopBlinking(self):
60                 self.blinking = False
61                 if self.visible:
62                         self.hide()
63                 self.timer.stop()
64                 
65 class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
66         def __init__(self):
67                 BlinkingWidget.__init__(self)
68                 ConditionalWidget.__init__(self)
69                 
70         def activateCondition(self, condition):
71                 if (condition):
72                         if not self.blinking: # we are already blinking
73                                 self.startBlinking()
74                 else:
75                         if self.blinking: # we are blinking
76                                 self.stopBlinking()