update scrollbar in timerlist when a entry is removed
[enigma2.git] / 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 postWidgetCreate(self, instance):
16                 self.visible = 0
17
18         def setConnect(self, conditionalFunction):
19                 self.conditionalFunction = conditionalFunction
20                 
21         def activateCondition(self, condition):
22                 if condition:
23                         self.visible = 1
24                 else:
25                         self.visible = 0
26
27         def update(self):
28                 if (self.conditionalFunction != None):
29                         try:
30                                 self.activateCondition(self.conditionalFunction())
31                         except:
32                                 self.conditionalFunction = None
33                                 self.activateCondition(False)
34
35 class BlinkingWidget(GUIComponent):
36         def __init__(self):
37                 GUIComponent.__init__(self)
38                 self.blinking = False
39                 self.setBlinkTime(500)
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()