use PixmapConditional for BlinkingPixmap
[enigma2.git] / lib / python / Components / BlinkingPixmap.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from Pixmap import *
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):
15                 Pixmap.__init__(self)
16                 GUIComponent.__init__(self)
17                 
18                 self.state = self.SHOWN
19                 self.blinking = False
20                 
21                 self.setBlinkTime(500)
22
23                 self.timer = eTimer()
24                 self.timer.timeout.get().append(self.blink)
25         
26                 
27         def createWidget(self, parent):
28                 return self.getePixmap(parent)
29
30         def removeWidget(self, w):
31                 pass
32         
33         def showPixmap(self):
34                 print "Show pixmap"
35                 self.state = self.SHOWN
36                 self.instance.show()
37
38         def hidePixmap(self):
39                 print "Hide pixmap"
40                 self.state = self.HIDDEN
41                 self.instance.hide()
42                 
43         def setBlinkTime(self, time):
44                 self.blinktime = time
45                 
46         def blink(self):
47                 if self.blinking == True:
48                         if (self.state == self.SHOWN):
49                                 self.hidePixmap()
50                         elif (self.state == self.HIDDEN):
51                                 self.showPixmap()
52                         
53         def startBlinking(self):
54                 self.blinking = True
55                 self.timer.start(self.blinktime)
56                 
57         def stopBlinking(self):
58                 self.blinking = False
59                 if (self.state == self.SHOWN):
60                         self.hidePixmap()
61                 self.timer.stop()
62                 
63 class BlinkingPixmapConditional(BlinkingPixmap, PixmapConditional):
64         def __init__(self):
65                 BlinkingPixmap.__init__(self)
66                 PixmapConditional.__init__(self)
67                 
68         def activateCondition(self, condition):
69                 if (condition):
70                         if self.blinking: # we are already blinking
71                                 pass
72                         else: # we don't blink
73                                 self.startBlinking()
74                 else:
75                         if self.blinking: # we are blinking
76                                 self.stopBlinking()
77                         else: # we don't blink
78                                 pass