1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import pgm
18 from pgm.graph.group import Group
19 from pgm.graph.image import Image
20 from pgm.timing import implicit
21 import threading
22
25
27
28 - def __init__(self, width=1.0, height=2.0):
29 Group.__init__(self)
30
31
32 self._width = width
33 self._height = height
34
35 self._attributes = []
36 self._widgets = []
37 self._animation_lock = threading.Lock()
38
39 self._current_animated_widget = None
40
41
42 self._drag_zone = Image()
43 Group.add(self, self._drag_zone)
44 self._drag_zone.bg_color = (255, 0, 0, 0)
45 self._drag_zone.size = (width, height)
46 self._drag_zone.visible = True
47
48
49 self._background = Image()
50 Group.add(self, self._background)
51 self._background.bg_color = (0, 255, 0, 0)
52 self._background.layout = pgm.IMAGE_FILLED
53 self._background.interp = pgm.IMAGE_NEAREST
54 self._background.size = (width, height)
55 self._background.visible = True
56
58 x = 0.0
59 y = 0.0
60 z = 0.2
61
62 i = 0
63 for widget in self._widgets[:-1]:
64 if i >= index:
65 break
66 x += widget.static_object.width*0.88
67 z -= 0.02
68 i += 1
69
70 position = (x, y, z)
71 return position
72
75
79
83
85 i = 0
86 for widget in self._widgets:
87 widget.opacity = self._attributes[i][1]
88 widget.position = self._attributes[i][0]
89 i += 1
90
93
99
102
111
115
118
120 return len(self._widgets)
121
123 return self._widgets[index].static_object
124
126 x, y, z = self._compute_position(index)
127 widget_right_corner = x + widget.width
128 list_right_corner = self.x + self.width
129 visible = widget_right_corner <= list_right_corner
130 return visible
131
132 - def insert(self, index, widget):
133
134 k = self._height*0.95 / widget.height
135 widget.height *= k
136 widget.width *= k
137 widget.regenerate()
138
139 if self._animation_lock.locked():
140 settings = {'duration': 50}
141 self._current_animated_widget.update_animation_settings(**settings)
142 self._animation_lock.release()
143
144 self._animation_lock.acquire(False)
145
146 def done(ctrl):
147 if self._animation_lock.locked():
148 self._animation_lock.release()
149 self._current_animated_widget = None
150
151
152 animated_widget = implicit.AnimatedObject(widget)
153 animated_widget.setup_next_animations(duration=300,
154 transformation=implicit.DECELERATE,
155 end_callback=done)
156 self._current_animated_widget = animated_widget
157
158 self._widgets.insert(index, animated_widget)
159
160
161 if self._is_visible(index, widget) or True:
162
163
164
165 Group.add(self, widget)
166
167
168 prev_position = self._compute_position(index-1)
169 if len(self._widgets) == 1:
170 prev_position = (-widget.width, prev_position[1],
171 prev_position[2])
172
173 widget.position = prev_position
174
175
176 if len(self._widgets) == 1:
177 widget.opacity = 0
178
179 self._attributes.insert(index, self._compute_attributes(index))
180
181 animated_widget.opacity = self._attributes[index][1]
182
183 if len(self._widgets) == 1:
184
185 widget.position = self._attributes[index][0]
186 else:
187 widget.y = self._attributes[index][0][1]
188 widget.z = self._attributes[index][0][2]
189 animated_widget.x = self._attributes[index][0][0]
190 else:
191 self._animation_lock.release()
192
193 widget.visible = True
194
196 self.insert(len(self), widget)
197
199 static_widgets = [ w.static_object for w in self._widgets ]
200 index = static_widgets.index(widget)
201 self.pop(index)
202
203
204 - def pop(self, index=None):
205 if self._animation_lock.locked():
206 settings = {'duration': 50}
207 self._current_animated_widget.update_animation_settings(**settings)
208 self._animation_lock.release()
209
210 self._animation_lock.acquire(False)
211
212 if index is None:
213
214 index = len(self._widgets) - 1
215
216 def done(ctrl):
217 static = animated_widget.static_object
218 Group.remove(self, static)
219 if self._animation_lock.locked():
220 self._animation_lock.release()
221 self._current_animated_widget = None
222
223 animated_widget = self._widgets.pop(index)
224 self._current_animated_widget = animated_widget
225
226 settings = {'duration': 300,
227 'transformation': implicit.ACCELERATE,
228 'end_callback': done}
229 animated_widget.setup_next_animations(**settings)
230
231 try:
232 x_offset = self._widgets[index-1].width
233 except IndexError:
234 x_offset = animated_widget.width
235
236 if len(self._widgets) == 0:
237 animated_widget.opacity = 0
238 else:
239 animated_widget.x -= x_offset
240
241 return animated_widget.static_object
242
244 try:
245 widget = self._widgets[-1].static_object
246 except IndexError:
247 widget = None
248 return widget
249
252
253 if __name__ == "__main__":
254 import os
255 import gobject
256 import gst
257 from pgm.timing import implicit
258
259
261 if event.type == pgm.KEY_PRESS:
262
263 if event.keyval in (pgm.keysyms.q, pgm.keysyms.Escape):
264 pgm.main_quit()
265
266 elif event.keyval in (pgm.keysyms.Down, pgm.keysyms.Right):
267 path = Image()
268 path.visible = True
269 widget.append(path)
270
271 elif event.keyval in (pgm.keysyms.Up, pgm.keysyms.Left):
272 widget.pop()
273
276
277
278 factory = pgm.ViewportFactory('opengl')
279 gl = factory.create()
280 gl.title = 'Status bar widget'
281
282
283 canvas = pgm.Canvas()
284
285
286 gl.set_canvas(canvas)
287 gl.show()
288
289 status = StatusBar()
290 status.canvas = canvas
291 status.position = (0.0, 0.0, 0.0)
292 status.width = 3.0
293 status.height = 0.2
294 status.visible = True
295
296
297 gl.connect('key-press-event', on_key_press, status)
298 gl.connect('delete-event', on_delete)
299 pgm.main()
300