add "Blink" option to ConditionalShowHide
[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, type)
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.timeout.get().append(self.blinkFunc)
14
15         def blinkFunc(self):
16                 if self.blinking == True:
17                         for x in self.downstream_elements:
18                                 x.visible = not x.visible
19
20         def startBlinking(self):
21                 self.blinking = True
22                 self.timer.start(self.blinktime)
23
24         def stopBlinking(self):
25                 self.blinking = False
26                 for x in self.downstream_elements:
27                         if x.visible:
28                                 x.hide()
29                 self.timer.stop()
30
31         def calcVisibility(self):
32                 b = self.source.boolean
33                 if b is None:
34                         return True
35                 b ^= self.invert
36                 return b
37
38         def changed(self, what):
39                 vis = self.calcVisibility()
40                 if self.blink:
41                         if vis:
42                                 self.startBlinking()
43                         else:
44                                 self.stopBlinking()
45                 else:
46                         for x in self.downstream_elements:
47                                 x.visible = vis
48
49         def connectDownstream(self, downstream):
50                 Converter.connectDownstream(self, downstream)
51                 vis = self.calcVisibility()
52                 if self.blink:
53                         if vis:
54                                 self.startBlinking()
55                         else:
56                                 self.stopBlinking()
57                 else:
58                         downstream.visible = self.calcVisibility()