1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import gobject
18 import pgm
19 from pgm.timing import implicit
20 from pgm.graph.group import Group
21 from pgm.graph.text import Text
22 from pgm.graph.image import Image
23 from pgm.utils import image as image_utils
24
25 from pgm.widgets import const
26
27 NONE_FOCUSED=-1
28 BACK_FOCUSED=0
29 ZOOM_OUT_FOCUSED=1
30 ZOOM_IN_FOCUSED=2
31
33 attr_focus_map = {BACK_FOCUSED: 'back',
34 ZOOM_IN_FOCUSED: 'zoom_in',
35 ZOOM_OUT_FOCUSED: 'zoom_out'}
36
37
38 __gsignals__ = {
39 'focus-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
40 (gobject.TYPE_INT,))
41 }
42
43
44 - def __init__(self, canvas=None, layer=pgm.DRAWABLE_MIDDLE,
45 width=1.0, height=2.0,
46 background=None, main_text="", sub_text="",
47 back_button=None, back_button_focused=None,
48 zoom_in_button=None, zoom_in_button_focused=None,
49 zoom_out_button=None, zoom_out_button_focused=None):
68
72
101
102 - def _create_text(self):
103 txt = Text()
104 txt.font_family = "Nimbus Sans L Bold"
105 txt.bg_color = (0, 0, 0, 0)
106 txt.alignment = pgm.TEXT_ALIGN_CENTER
107 txt.ellipsize = pgm.TEXT_ELLIPSIZE_MIDDLE
108 txt.opacity = 255
109 txt.visible = True
110 return txt
111
113 mouse_zone = Image()
114 mouse_zone.bg_color = (0, 0, 0, 0)
115 mouse_zone.visible = True
116 mouse_zone.connect("clicked", self._img_clicked)
117 return mouse_zone
118
145
194
196 name = '_%s_img' % attr
197 focused_name = '_%s_focused_img' % attr
198 getattr(self, name).visible = True
199 getattr(self, focused_name).visible = False
200
202 name = '_%s_img' % attr
203 focused_name = '_%s_focused_img' % attr
204 getattr(self, name).visible = False
205 getattr(self, focused_name).visible = True
206
224
225 - def _set_image(self, img, image_file, visible=True):
226 if img is not None:
227 img.clear()
228 if image_file is not None:
229 img.visible = visible
230 img.connect("pixbuf-loaded", self._img_loaded)
231 img.set_from_file(image_file)
232
237
238 - def _img_clicked(self, mouse_zone, x, y, z, time, button_type):
239 img_name = mouse_zone.get_name()
240 for const, name in self.attr_focus_map.iteritems():
241 if name == img_name:
242 self._focused_button = const
243 break
244 self._focus_buttons(emit_signal=True)
245
246
247 return True
248
252
255
257 self._background_img.interp = pgm.IMAGE_NEAREST
258 self._set_image(self._background_img, image_file)
259
261 return self._background_img
262
263 - def main_text__set(self, text):
264 self._main_text.label = text
265 self._layout()
266
267 - def main_text__get(self):
268 return self._main_text
269
270 - def sub_text__set(self, text):
271 self._sub_text.label = text
272 self._layout()
273
274 - def sub_text__get(self):
275 return self._sub_text
276
279
282
285
288
291
294
297
300
303
306
309
312
313 if __name__ == "__main__":
314 import pgm
315 from pgm.widgets.grid_ng import Grid
316
317 from pgm.graph.group import Group
318
320
321 if event.keyval == pgm.keysyms.q or \
322 event.keyval == pgm.keysyms.Escape:
323 pgm.main_quit()
324
325 elif event.keyval == pgm.keysyms.a:
326 canvas = viewport.get_canvas()
327 canvas.regenerate()
328
329 elif event.keyval == pgm.keysyms.f:
330 viewport.fullscreen = not viewport.fullscreen
331
332 elif event.keyval == pgm.keysyms.Right:
333 new_value = widget.focused_button + 1
334 if new_value < ZOOM_IN_FOCUSED + 1:
335 widget.focused_button = new_value
336
337 elif event.keyval == pgm.keysyms.Left:
338 new_value = widget.focused_button - 1
339 if new_value >= NONE_FOCUSED:
340 widget.focused_button = new_value
341
344
345
346 factory = pgm.ViewportFactory('opengl')
347 gl = factory.create()
348 gl.title = 'GridBar widget'
349
350
351 canvas = pgm.Canvas()
352
353
354 gl.set_canvas(canvas)
355 gl.show()
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371 bar_height = 0.35
372 bar_y = canvas.height - bar_height
373
374 bar_x = 0.
375
376 bar = GridBar()
377 bar.visible = True
378
379 bar.canvas = canvas
380
381
382 bar.position = (bar_x, bar_y, 0.0)
383 bar.size = (canvas.width, bar_height)
384
385 bar.background = 'theme/bottom-grid-bar.png'
386 bar.zoom_in_button = 'theme/grid-morebutton.png'
387 bar.zoom_out_button = 'theme/grid-lessbutton.png'
388 bar.back_button = 'theme/grid-backbutton.png'
389
390 bar.zoom_in_button_focused = 'theme/grid-morebutton-focused.png'
391 bar.zoom_out_button_focused = 'theme/grid-lessbutton-focused.png'
392 bar.back_button_focused = 'theme/grid-backbutton-focused.png'
393
394
395 bar.main_text = "Quelqu'un m'a dit que tu m'aimes encore"
396 bar.sub_text = 'Carla Bruni'
397
398
399 gl.connect('key-press-event', on_key_press, bar)
400 gl.connect('delete-event', on_delete)
401 pgm.main()
402