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