"finished" message also when skipping configuration backup
[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 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
7 from os import path
8 from skin import loadPixmap
9
10 class Pixmap(GUIComponent):
11         GUI_WIDGET = ePixmap
12
13 class PixmapConditional(ConditionalWidget, Pixmap):
14         def __init__(self, withTimer = True):
15                 ConditionalWidget.__init__(self)
16                 Pixmap.__init__(self)
17
18 class MovingPixmap(Pixmap):
19         def __init__(self):
20                 Pixmap.__init__(self)
21                 
22                 self.moving = False
23                 
24                 # TODO: get real values
25                 self.x = 0.0
26                 self.y = 0.0
27                 
28                 self.clearPath()
29                 
30                 self.moveTimer = eTimer()
31                 self.moveTimer.callback.append(self.doMove)
32                 
33         def clearPath(self, repeated = False):
34                 if (self.moving):
35                         self.moving = False
36                         self.moveTimer.stop()
37                         
38                 self.path = []
39                 self.currDest = 0
40                 self.repeated = repeated
41                 
42         def addMovePoint(self, x, y, time = 20):
43                 self.path.append((x, y, time))
44         
45         def moveTo(self, x, y, time = 20):
46                 self.clearPath()
47                 self.addMovePoint(x, y, time)
48                 
49         def startMoving(self):
50                 if not self.moving:
51                         self.time = self.path[self.currDest][2]
52                         self.stepX = (self.path[self.currDest][0] - self.x) / float(self.time)
53                         self.stepY = (self.path[self.currDest][1] - self.y) / float(self.time)
54
55                         self.moving = True
56                         self.moveTimer.start(100)
57                         
58         def stopMoving(self):
59                 self.moving = False
60                 self.moveTimer.stop()
61                 
62         def doMove(self):
63                 self.x += self.stepX
64                 self.y += self.stepY
65                 self.time -= 1
66                 try:
67                         self.move(int(self.x), int(self.y))
68                 except: # moving not possible... widget not there any more... stop moving
69                         self.stopMoving()
70                         
71                 if (self.time == 0):
72                         self.currDest += 1
73                         self.moveTimer.stop()
74                         self.moving = False
75                         if (self.currDest >= len(self.path)): # end of path
76                                 if (self.repeated):
77                                         self.currDest = 0
78                                         self.moving = False
79                                         self.startMoving()
80                         else:
81                                 self.moving = False
82                                 self.startMoving()
83
84 class MultiPixmap(Pixmap):
85         def __init__(self):
86                 Pixmap.__init__(self)
87                 self.pixmaps = []
88
89         def applySkin(self, desktop, screen):
90                 if self.skinAttributes is not None:
91                         skin_path_prefix = getattr(screen, "skin_path", path)
92                         pixmap = None
93                         attribs = [ ]
94                         for (attrib, value) in self.skinAttributes:
95                                 if attrib == "pixmaps":
96                                         pixmaps = value.split(',')
97                                         for p in pixmaps:
98                                                 self.pixmaps.append(loadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, p, path_prefix=skin_path_prefix), desktop) )
99                                         if not pixmap:
100                                                 pixmap = resolveFilename(SCOPE_SKIN_IMAGE, pixmaps[0], path_prefix=skin_path_prefix)
101                                 elif attrib == "pixmap":
102                                         pixmap = resolveFilename(SCOPE_SKIN_IMAGE, value, path_prefix=skin_path_prefix)
103                                 else:
104                                         attribs.append((attrib,value))
105                         if pixmap:
106                                 attribs.append(("pixmap", pixmap))
107                         self.skinAttributes = attribs
108                 return GUIComponent.applySkin(self, desktop, screen)
109
110         def setPixmapNum(self, x):
111                 if self.instance:
112                         if len(self.pixmaps) > x:
113                                 self.instance.setPixmap(self.pixmaps[x])
114                         else:
115                                 print "setPixmapNum(%d) failed! defined pixmaps:" %(x), self.pixmaps