Merge commit 'origin/bug_478_Listbox_ScrollbarMode'
[enigma2.git] / lib / python / Components / Converter / ConditionalShowHide.py
index d72447d91047b184b38ad2217c8eca78b7fb9924..4860e17fc5400791db4160893bd248ca057ea39d 100644 (file)
@@ -1,10 +1,64 @@
+from enigma import eTimer
 from Converter import Converter
 
 class ConditionalShowHide(Converter, object):
-       def __init__(self, type):
-               Converter.__init__(self, type)
-               self.invert = type == "Invert"
+       def __init__(self, argstr):
+               Converter.__init__(self, argstr)
+               args = argstr.split(',')
+               self.invert = "Invert" in args
+               self.blink = "Blink" in args
+               if self.blink:
+                       self.blinktime = 500
+                       self.timer = eTimer()
+                       self.timer.callback.append(self.blinkFunc)
+               else:
+                       self.timer = None
 
-       def changed(self, what):
+       def blinkFunc(self):
+               if self.blinking == True:
+                       for x in self.downstream_elements:
+                               x.visible = not x.visible
+
+       def startBlinking(self):
+               self.blinking = True
+               self.timer.start(self.blinktime)
+
+       def stopBlinking(self):
+               self.blinking = False
                for x in self.downstream_elements:
-                       x.visible = self.source.boolean
+                       if x.visible:
+                               x.hide()
+               self.timer.stop()
+
+       def calcVisibility(self):
+               b = self.source.boolean
+               if b is None:
+                       return True
+               b ^= self.invert
+               return b
+
+       def changed(self, what):
+               vis = self.calcVisibility()
+               if self.blink:
+                       if vis:
+                               self.startBlinking()
+                       else:
+                               self.stopBlinking()
+               else:
+                       for x in self.downstream_elements:
+                               x.visible = vis
+
+       def connectDownstream(self, downstream):
+               Converter.connectDownstream(self, downstream)
+               vis = self.calcVisibility()
+               if self.blink:
+                       if vis:
+                               self.startBlinking()
+                       else:
+                               self.stopBlinking()
+               else:
+                       downstream.visible = self.calcVisibility()
+
+       def destroy(self):
+               if self.timer:
+                       self.timer.callback.remove(self.blinkFunc)