1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import pgm
23 from pgm.graph.group import Group
24 from pgm.graph.image import Image
25 from pgm.timing import implicit
26
27 import os
28
29
31
32 - def __init__(self, canvas, layer, length, bg_image, fg_image):
33
34 Group.__init__(self, canvas, layer)
35
36 if length > 0:
37 self._length = length
38 else:
39
40 self._length = 100
41 self._cursor_position = 0
42
43 self._bg = Image()
44 self._bg.set_from_file(bg_image)
45 self._bg.layout = pgm.IMAGE_FILLED
46 self._bg.alignment = pgm.IMAGE_LEFT
47 self._bg.height = 1.0
48 self._bg.width = 4.0
49 self._bg.bg_color = (0, 0, 0, 0)
50 self._bg.visible = True
51
52 self._bar = Image()
53 self._bar.set_from_file(fg_image)
54 self._bar.layout = pgm.IMAGE_FILLED
55 self._bar.alignment = pgm.IMAGE_LEFT
56 self._bar.height = 1.0
57 self._bar.width = 4.0
58 self._bar.size = (0, 0)
59 self._bar.bg_color = (0, 0, 0, 0)
60 self._bar.visible = True
61 self._animated_bar = implicit.AnimatedObject(self._bar)
62 self._animated_bar.mode = implicit.REPLACE
63 self._animated_bar.setup_next_animations(duration = 200)
64
65 self.add(self._bg)
66 self.add(self._bar)
67
68 self._offset = 0.16
69 self.visible = True
70
71
73 """
74 Set the size of the bar. The bar is automatically new painted
75 """
76 self._bg.size = size
77
78 self._bar.height = size[1]
79 self._paint_bar(animated = False)
80
82 """
83 Set the length. The bar is automatically new painted
84 @param length: the length of the process
85 @type length: as above: something to do mathematic stuff
86 """
87 self._length = length
88 if self._length <= 0:
89 self._length = 1
90 if self._cursor_position > self._length:
91 self._cursor_position = self._length
92 self._paint_bar()
93
95 """
96 to get the length:
97 @return: returns the length
98 """
99 return self._length
100
102 """
103 Here the position is calculated and the bar is painted
104 """
105 next_pos = self._bg.size[0] / self.length * \
106 self._cursor_position
107 if animated:
108 self._animated_bar.width = next_pos
109 else:
110 self._animated_bar.stop_animations()
111 self._bar.width = next_pos
112
114 """
115 Set the position of the cursor. The bar is automatically new painted
116 (with animation)
117 @param position: the position to set to
118 @type position: something to do mathematic stuff with
119 """
120 self._cursor_position = position
121 self._cursor_position = max(0,
122 min(self._cursor_position, self._length)
123 )
124
125 self._paint_bar()
126
128 """
129 returns the position of the cursor
130 @return : the position of the cursor
131 """
132 return self._cursor_position
133
135 """
136 Jump to this position. This means that the cursor doesn't go there
137 with animationm but that it is there immediatly
138 @param position: the position to jump to
139 @type position: something to do mathematic stuff with
140 """
141 self._cursor_position = position
142 self._cursor_position = max(0,
143 min(self._cursor_position, self.length)
144 )
145 self._paint_bar(animated=False)
146
148 """
149 Set the background color. The bar is automatically new painted
150 @param color: color of the background
151 """
152 self._bg.bg_color = color
153
155 """
156 returns the current background color
157 """
158 return self._bg.bg_color
159
161 """
162 Set the color of the bar. The bar is automatically new painted
163 @param color: color of the bar
164 """
165 self._bar.bg_color = color
166
168 """
169 return the current color of the bar
170 """
171 return self._bar.bg_color
172