get the file for the BlinkingPixmap from skin.xml
[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):
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):
64         def __init__(self):
65                 BlinkingPixmap.__init__(self)
66                 
67                 self.setConnect(None)
68                 
69                 self.conditionCheckTimer = eTimer()
70                 self.conditionCheckTimer.timeout.get().append(self.conditionallyBlink)
71                 self.conditionCheckTimer.start(1000)
72                 
73         def setConnect(self, conditionalFunction):
74                 self.conditionalFunction = conditionalFunction
75                 
76         def conditionallyBlink(self):
77                 try:
78                         self.conditionalFunction() # check, if the conditionalfunction is still valid
79                 except:
80                         self.conditionalFunction = None
81                         self.stopBlinking()
82                         
83                 if self.conditionalFunction != None:
84                         if self.conditionalFunction(): # we shall blink
85                                 if self.blinking: # we are already blinking
86                                         pass
87                                 else: # we don't blink
88                                         self.startBlinking()
89                         else: # we shall not blink
90                                 if self.blinking: # we are blinking
91                                         self.stopBlinking()
92                                 else: # we don't blink
93                                         pass