rename BlinkingPoint to BlinkingPixmap (is more generic)
[enigma2.git] / lib / python / Components / BlinkingPixmap.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from Pixmap import Pixmap
5
6 from enigma import *
7
8 import time
9
10 class BlinkingPixmap(GUIComponent, Pixmap):
11         SHOWN = 0
12         HIDDEN = 1
13         
14         def __init__(self, filename):
15                 Pixmap.__init__(self)
16                 GUIComponent.__init__(self)
17                 
18                 self.filename = filename
19                 
20                 self.state = self.SHOWN
21                 self.blinking = False
22                 
23                 self.setBlinkTime(500)
24
25                 self.timer = eTimer()
26                 self.timer.timeout.get().append(self.blink)
27         
28                 
29         def createWidget(self, parent):
30                 return self.getePixmap(parent, self.filename)
31
32         def removeWidget(self, w):
33                 pass
34         
35         def showPoint(self):
36                 print "Show point"
37                 self.state = self.SHOWN
38                 self.instance.show()
39
40         def hidePoint(self):
41                 print "Hide point"
42                 self.state = self.HIDDEN
43                 self.instance.hide()
44                 
45         def setBlinkTime(self, time):
46                 self.blinktime = time
47                 
48         def blink(self):
49                 if self.blinking == True:
50                         if (self.state == self.SHOWN):
51                                 self.hidePoint()
52                         elif (self.state == self.HIDDEN):
53                                 self.showPoint()
54                         
55         def startBlinking(self):
56                 self.blinking = True
57                 self.timer.start(self.blinktime)
58                 
59         def stopBlinking(self):
60                 self.blinking = False
61                 if (self.state == self.SHOWN):
62                         self.hidePoint()
63                 self.timer.stop()
64                 
65 class BlinkingPixmapConditional(BlinkingPixmap):
66         def __init__(self, filename):
67                 BlinkingPixmap.__init__(self, filename)
68                 
69                 self.setConnect(None)
70                 
71                 self.conditionCheckTimer = eTimer()
72                 self.conditionCheckTimer.timeout.get().append(self.conditionallyBlink)
73                 self.conditionCheckTimer.start(1000)
74                 
75         def setConnect(self, conditionalFunction):
76                 self.conditionalFunction = conditionalFunction
77                 
78         def conditionallyBlink(self):
79                 try:
80                         self.conditionalFunction() # check, if the conditionalfunction is still valid
81                 except:
82                         self.conditionalFunction = None
83                         self.stopBlinking()
84                         
85                 if self.conditionalFunction != None:
86                         if self.conditionalFunction(): # we shall blink
87                                 if self.blinking: # we are already blinking
88                                         pass
89                                 else: # we don't blink
90                                         self.startBlinking()
91                         else: # we shall not blink
92                                 if self.blinking: # we are blinking
93                                         self.stopBlinking()
94                                 else: # we don't blink
95                                         pass