- remove some comments
[enigma2.git] / lib / python / Components / Pixmap.py
1 from ConditionalWidget import ConditionalWidget
2 from GUIComponent import GUIComponent
3
4 from enigma import ePixmap, eTimer
5
6 class Pixmap(GUIComponent):
7         GUI_WIDGET = ePixmap
8
9 class PixmapConditional(ConditionalWidget, Pixmap):
10         def __init__(self, withTimer = True):
11                 ConditionalWidget.__init__(self)
12                 Pixmap.__init__(self)
13
14 class MovingPixmap(Pixmap):
15         def __init__(self):
16                 Pixmap.__init__(self)
17                 
18                 self.moving = False
19                 
20                 # TODO: get real values
21                 self.x = 0.0
22                 self.y = 0.0
23                 
24                 self.clearPath()
25                 
26                 self.moveTimer = eTimer()
27                 self.moveTimer.callback.append(self.doMove)
28                 
29         def clearPath(self, repeated = False):
30                 if (self.moving):
31                         self.moving = False
32                         self.moveTimer.stop()
33                         
34                 self.path = []
35                 self.currDest = 0
36                 self.repeated = repeated
37                 
38         def addMovePoint(self, x, y, time = 20):
39                 self.path.append((x, y, time))
40         
41         def moveTo(self, x, y, time = 20):
42                 self.clearPath()
43                 self.addMovePoint(x, y, time)
44                 
45         def startMoving(self):
46                 if not self.moving:
47                         self.time = self.path[self.currDest][2]
48                         self.stepX = (self.path[self.currDest][0] - self.x) / float(self.time)
49                         self.stepY = (self.path[self.currDest][1] - self.y) / float(self.time)
50
51                         self.moving = True
52                         self.moveTimer.start(100)
53                         
54         def stopMoving(self):
55                 self.moving = False
56                 self.moveTimer.stop()
57                 
58         def doMove(self):
59                 self.x += self.stepX
60                 self.y += self.stepY
61                 self.time -= 1
62                 try:
63                         self.move(int(self.x), int(self.y))
64                 except: # moving not possible... widget not there any more... stop moving
65                         self.stopMoving()
66                         
67                 if (self.time == 0):
68                         self.currDest += 1
69                         self.moveTimer.stop()
70                         self.moving = False
71                         if (self.currDest >= len(self.path)): # end of path
72                                 if (self.repeated):
73                                         self.currDest = 0
74                                         self.moving = False
75                                         self.startMoving()
76                         else:
77                                 self.moving = False
78                                 self.startMoving()