1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import pgm
18 from pgm.timing import implicit
19 from pgm.graph.image import Image
20 from pgm.utils import image as image_utils
21
22 from pgm.widgets import list_ng, const
23 import scrolled_list
24
25
181
182
183 if __name__ == "__main__":
184 import pgm
185 import gobject
186 import operator
187 from pgm.graph.group import Group
188 from pgm.graph.image import Image
189 from pgm.graph.text import Text
190 from pgm.timing import implicit
191 from pgm.widgets import sliced_image, scrollbar, const
192 import selector
193
194
196
197 - def __init__(self, thumbnail=None, description=None, arrow=None):
198 Group.__init__(self)
199
200 self.thumbnail = Image()
201
202 self.thumbnail.bg_color = (0, 0, 0, 0)
203 self.thumbnail.layout = pgm.IMAGE_SCALED
204 self.thumbnail.visible = True
205
206 self._description = self._create_text()
207 self._description.bg_color = (255, 0, 0, 255)
208
209 self.add(self.thumbnail)
210 self.add(self._description)
211
212 if thumbnail is not None:
213 self.thumbnail.set_from_file(thumbnail)
214
215 self.description = description
216
217
218
219
220
221 """
222 arrow_x = text_x + text_width
223 arrow_y = 0.4
224 arrow_width = 0.25
225 arrow_height = 0.8
226
227 self.arrow = Image()
228 self.arrow.bg_color = (0, 0, 0, 0)
229 #self.arrow.bg_color = (0, 0, 255, 255)
230 self.arrow.layout = pgm.IMAGE_SCALED
231 self.arrow.size = (arrow_width, arrow_height)
232 self.add(self.arrow)
233 self.arrow.position = (arrow_x, arrow_y, 0)
234
235 if arrow:
236 self.arrow.set_from_file(arrow)
237 """
238
240 canvas = self.canvas
241 vspacing = canvas.width / 35.
242
243 thumbnail_width = canvas.width / 13.
244 thumbnail_height = canvas.height / 8.
245 thumbnail_x = canvas.width / 70.
246 thumbnail_y = canvas.height / 60.
247
248 self.thumbnail.position = (thumbnail_x, thumbnail_y, 0)
249 self.thumbnail.size = (thumbnail_width, thumbnail_height)
250
251 text_x = thumbnail_width + vspacing
252 text_y = canvas.height / 45.
253 text_width = canvas.width / 1.9
254 text_height = self.height
255 font_height = text_height * 0.35
256
257
258 self._description.font_height = font_height
259 self._description.position = (text_x, text_y, 0)
260 self._description.size = (text_width, text_height)
261
266
267 - def _create_text(self):
268 txt = Text()
269 txt.font_family = "Nimbus Sans L"
270 txt.bg_color = (0, 0, 0, 0)
271 txt.alignment = pgm.TEXT_ALIGN_LEFT
272 txt.ellipsize = pgm.TEXT_ELLIPSIZE_MIDDLE
273 txt.opacity = 255
274 return txt
275
277 self._description.markup = u'<b>%s</b>' % text
278 self._description.visible = True
279
280
282 return self._description
283
284
285
286 text_idx = 0
287
294
296 for list_widget in lists:
297 try:
298 function(list_widget)
299 except Exception, exc:
300 print exc
301
303
304 if event.keyval in (pgm.keysyms.q, pgm.keysyms.Escape):
305 pgm.main_quit()
306
307 if event.keyval in (pgm.keysyms.Down, pgm.keysyms.Right):
308 prop = 'selected_item'
309 update_lists(lists,
310 lambda w: setattr(w, prop, getattr(w, prop) + 1))
311 elif event.keyval in (pgm.keysyms.Up, pgm.keysyms.Left):
312 prop = 'selected_item'
313 update_lists(lists,
314 lambda w: setattr(w, prop, getattr(w, prop) - 1))
315 elif event.keyval == pgm.keysyms.a:
316 update_lists(lists,
317 lambda w: w.append(create_item("pictures/fluendo.png")))
318 elif event.keyval == pgm.keysyms.r:
319 update_lists(lists,
320 lambda list_widget: list_widget.pop())
321
324
325
326 factory = pgm.ViewportFactory('opengl')
327 gl = factory.create()
328 gl.title = 'TextList widget-test'
329
330
331 canvas = pgm.Canvas()
332
333
334 gl.set_canvas(canvas)
335 gl.show()
336
337 visible_items = 9
338 items_nb = 20
339
340
341
342
343
344
345
346
347 top_left = ShadedScrolledList(3, 1, orientation=const.VERTICAL)
348 top_left.top_shade = "theme/gradient-top.png"
349 top_left.bottom_shade = "theme/gradient-bottom.png"
350
351 top_left.canvas = canvas
352 top_left.visible_range_size = visible_items
353 top_left.position = (0.04, 0.65, 0)
354 top_left.width = canvas.width * 0.55
355 top_left.height = canvas.height * 0.72
356 top_left.visible = True
357
358 bg = sliced_image.SlicedImage(top_file="theme/scrollbar-top.png",
359 bottom_file="theme/scrollbar-bottom.png",
360 body_file="theme/scrollbar-body.png")
361
362 cursor = sliced_image.SlicedImage(top_file="theme/cursor-top.png",
363 bottom_file="theme/cursor-bottom.png",
364 body_file="theme/cursor-body.png")
365
366 bar = scrollbar.Scrollbar(items_number=visible_items,
367 background=bg, cursor=cursor,
368 spacing=0.01)
369
370
371 bar.thickness=0.07
372
373 top_left.set_vertical_scrollbar(bar, const.LEFT, spacing=0.02)
374
375 pictos = ("theme/selector-left.png",
376 "theme/selector-right.png",
377 "theme/selector-body.png",
378 "theme/back-selector-left.png",
379 "theme/back-selector-right.png",
380 "theme/back-selector-body.png",
381
382 )
383
384 list_selector = selector.Selector(orientation=const.HORIZONTAL, *pictos)
385
386 top_left.set_selector(list_selector)
387
388 lists = [ top_left,
389 ]
390
391
392 label = "this is a long long text"
393 update_lists(lists, lambda w: [ w.append(create_item(label))
394 for i in xrange(items_nb) ])
395 update_lists(lists, lambda w: setattr(w, 'selected_item', 0))
396
397
398
399 gl.connect('key-press-event', on_key_press, lists)
400 gl.connect('delete-event', on_delete)
401 pgm.main()
402