d25530ea71e8ca9980e37aedb31ba980c3e8d195
[vuplus_dvbapp] / lib / python / Components / Pixmap.py
1 from ConditionalWidget import *
2
3 from enigma import *
4
5 class Pixmap(Widget):
6         def __init__(self):
7                 Widget.__init__(self)
8
9         def getePixmap(self, parent):
10                 #pixmap = ePixmap(parent)
11                 #pixmap.setPixmapFromFile(self.filename)
12                 return ePixmap(parent)
13         
14         def createWidget(self, parent):
15                 return self.getePixmap(parent)
16
17         def removeWidget(self, w):
18                 pass
19
20         def move(self, x, y):
21                 self.instance.move(ePoint(int(x), int(y)))
22
23 class PixmapConditional(ConditionalWidget, Pixmap):
24         def __init__(self, withTimer = True):
25                 ConditionalWidget.__init__(self)
26                 Pixmap.__init__(self)
27
28 class MovingPixmap(Pixmap):
29         def __init__(self):
30                 Pixmap.__init__(self)
31                 
32                 self.moving = False
33                 
34                 # TODO: get real values
35                 self.x = 0.0
36                 self.y = 0.0
37                 
38                 self.clearPath()
39                 
40                 self.moveTimer = eTimer()
41                 self.moveTimer.timeout.get().append(self.doMove)
42                 
43         def clearPath(self, repeated = False):
44                 if (self.moving):
45                         self.moving = False
46                         self.moveTimer.stop()
47                         
48                 self.path = []
49                 self.currDest = 0
50                 self.repeated = repeated
51                 
52         def addMovePoint(self, x, y, time = 20):
53                 self.path.append((x, y, time))
54         
55         def moveTo(self, x, y, time = 20):
56                 self.clearPath()
57                 self.addMovePoint(x, y, time)
58                 
59         def startMoving(self):
60                 if not self.moving:
61                         self.time = self.path[self.currDest][2]
62                         self.stepX = (self.path[self.currDest][0] - self.x) / float(self.time)
63                         self.stepY = (self.path[self.currDest][1] - self.y) / float(self.time)
64
65                         self.moving = True
66                         self.moveTimer.start(100)
67                         
68         def stopMoving(self):
69                 self.moving = False
70                 self.moveTimer.stop()
71                 
72         def doMove(self):
73                 self.x += self.stepX
74                 self.y += self.stepY
75                 self.time -= 1
76                 try:
77                         self.move(int(self.x), int(self.y))
78                 except: # moving not possible... widget not there any more... stop moving
79                         self.stopMoving()
80                         
81                 if (self.time == 0):
82                         self.currDest += 1
83                         self.moveTimer.stop()
84                         self.moving = False
85                         if (self.currDest >= len(self.path)): # end of path
86                                 if (self.repeated):
87                                         self.currDest = 0
88                                         self.moving = False
89                                         self.startMoving()
90                         else:
91                                 self.moving = False
92                                 self.startMoving()