fix typo
[enigma2.git] / lib / python / Components / Converter / ConditionalShowHide.py
1 from enigma import eTimer
2 from Converter import Converter
3
4 class ConditionalShowHide(Converter, object):
5         def __init__(self, argstr):
6                 Converter.__init__(self, argstr)
7                 args = argstr.split(',')
8                 self.invert = "Invert" in args
9                 self.blink = "Blink" in args
10                 if self.blink:
11                         self.blinktime = 500
12                         self.timer = eTimer()
13                         self.timer.callback.append(self.blinkFunc)
14                 else:
15                         self.timer = None
16
17         def blinkFunc(self):
18                 if self.blinking == True:
19                         for x in self.downstream_elements:
20                                 x.visible = not x.visible
21
22         def startBlinking(self):
23                 self.blinking = True
24                 self.timer.start(self.blinktime)
25
26         def stopBlinking(self):
27                 self.blinking = False
28                 for x in self.downstream_elements:
29                         if x.visible:
30                                 x.hide()
31                 self.timer.stop()
32
33         def calcVisibility(self):
34                 b = self.source.boolean
35                 if b is None:
36                         return True
37                 b ^= self.invert
38                 return b
39
40         def changed(self, what):
41                 vis = self.calcVisibility()
42                 if self.blink:
43                         if vis:
44                                 self.startBlinking()
45                         else:
46                                 self.stopBlinking()
47                 else:
48                         for x in self.downstream_elements:
49                                 x.visible = vis
50
51         def connectDownstream(self, downstream):
52                 Converter.connectDownstream(self, downstream)
53                 vis = self.calcVisibility()
54                 if self.blink:
55                         if vis:
56                                 self.startBlinking()
57                         else:
58                                 self.stopBlinking()
59                 else:
60                         downstream.visible = self.calcVisibility()
61
62         def destroy(self):
63                 if self.timer:
64                         self.timer.callback.remove(self.blinkFunc)