switch to opkg
[enigma2.git] / lib / python / Components / ConditionalWidget.py
index eec5b4360a8a4b903cf8f8c46cf50f47c4d35770..192813f527654d1976d61531a224bd0f362b6ce2 100644 (file)
@@ -1,66 +1,71 @@
-import skin
-from GUIComponent import *
+from GUIComponent import GUIComponent
+from enigma import eTimer
 
-from enigma import *
-
-class Widget(GUIComponent):
-       
-       SHOWN = 0
-       HIDDEN = 1
-       
-       def __init__(self):
-               GUIComponent.__init__(self)
-               self.instance = None
-               self.state = self.SHOWN
-       
-       def GUIcreate(self, parent):
-               self.instance = self.createWidget(parent)
-       
-       def GUIdelete(self):
-               self.removeWidget(self.instance)
-               self.instance = None
-       
-       def removeWidget(self, w):
-               pass
-       
-       def showWidget(self):
-               self.state = self.SHOWN
-               self.instance.show()
-
-       def hideWidget(self):
-               self.state = self.HIDDEN
-               self.instance.hide()
-       
-class ConditionalWidget(Widget):
+class ConditionalWidget(GUIComponent):
        def __init__(self, withTimer = True):
-               Widget.__init__(self)
+               GUIComponent.__init__(self)
                
                self.setConnect(None)
                
                if (withTimer):
                        self.conditionCheckTimer = eTimer()
-                       self.conditionCheckTimer.timeout.get().append(self.update)
+                       self.conditionCheckTimer.callback.append(self.update)
                        self.conditionCheckTimer.start(1000)
-               
+
+       def postWidgetCreate(self, instance):
+               self.visible = 0
+
        def setConnect(self, conditionalFunction):
                self.conditionalFunction = conditionalFunction
                
        def activateCondition(self, condition):
-               if (condition):
-                       if (self.state == self.HIDDEN):
-                               print "update: " + str(self) + " SHOW"
-                               self.showWidget()
+               if condition:
+                       self.visible = 1
                else:
-                       if (self.state == self.SHOWN):
-                               print "update: " + str(self) + " HIDE"
-                               self.hideWidget()
+                       self.visible = 0
 
        def update(self):
                if (self.conditionalFunction != None):
                        try:
-                               self.conditionalFunction() # check, if the conditionalfunction is still valid
+                               self.activateCondition(self.conditionalFunction())
                        except:
                                self.conditionalFunction = None
                                self.activateCondition(False)
+
+class BlinkingWidget(GUIComponent):
+       def __init__(self):
+               GUIComponent.__init__(self)
+               self.blinking = False
+               self.setBlinkTime(500)
+               self.timer = eTimer()
+               self.timer.callback.append(self.blink)
+       
+       def setBlinkTime(self, time):
+               self.blinktime = time
+               
+       def blink(self):
+               if self.blinking == True:
+                       self.visible = not self.visible
                        
-                       self.activateCondition(self.conditionalFunction())
+       def startBlinking(self):
+               self.blinking = True
+               self.timer.start(self.blinktime)
+               
+       def stopBlinking(self):
+               self.blinking = False
+               if self.visible:
+                       self.hide()
+               self.timer.stop()
+
+class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget):
+       def __init__(self):
+               BlinkingWidget.__init__(self)
+               ConditionalWidget.__init__(self)
+               
+       def activateCondition(self, condition):
+               if (condition):
+                       if not self.blinking: # we are already blinking
+                               self.startBlinking()
+               else:
+                       if self.blinking: # we are blinking
+                               self.stopBlinking()