+from enigma import eTimer
from Converter import Converter
class ConditionalShowHide(Converter, object):
+ 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 __init__(self, type):
- Converter.__init__(self, type)
- self.invert = type == "Invert"
+ def blinkFunc(self):
+ if self.blinking == True:
+ for x in self.downstream_elements:
+ x.visible = not x.visible
- def changed(self, what):
+ 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)