Home | Trees | Indices | Help |
---|
|
1 # -*- coding: utf-8 -*- 2 # Elisa - Home multimedia server 3 # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 4 # All rights reserved. 5 # 6 # This file is available under one of two license agreements. 7 # 8 # This file is licensed under the GPL version 3. 9 # See "LICENSE.GPL" in the root of this distribution including a special 10 # exception to use Elisa with Fluendo's plugins. 11 # 12 # The GPL part of Elisa is also available under a commercial licensing 13 # agreement from Fluendo. 14 # See "LICENSE.Elisa" in the root directory of this distribution package 15 # for details on that license. 16 17 from pgm.timing import implicit 18 from pgm.widgets import list_ng, const 1921251 252 if __name__ == "__main__": 253 import pgm 254 import gobject 255 import operator, os, sys 256 from pgm.graph.image import Image 257 from pgm.graph.text import Text 258 from pgm.graph.group import Group 259 from pgm.timing import implicit 260 261 from pgm.widgets.sliced_image import SlicedImage 262 from pgm.widgets.scrollbar import Scrollbar 263 import selector 26422 - def __init__(self, width=1.0, height=2.0, 23 visible_range_size=7, orientation=const.VERTICAL):24 self._hbar = None 25 self._vbar = None 26 self._hbar_pos = None 27 self._vbar_pos = None 28 self._vbar_spacing = 0 29 self._hbar_spacing = 0 30 self._selector = None 31 self._selector_spacing = 0 32 super(ScrolledList, self).__init__(width, height, 33 visible_range_size, orientation)3436 self._selector = selector 37 38 self._selector_spacing = spacing 39 self.add(self._selector) 40 self._selector.z = - 1.0 41 x = self.compute_x(self.selected_item) 42 y = self.compute_y(self.selected_item) 43 44 spacing = self._selector_spacing 45 46 if self._orientation == const.VERTICAL: 47 x -= spacing / 2. 48 y -= spacing / 2. 49 elif self._orientation == const.HORIZONTAL: 50 x -= spacing 51 y -= spacing 52 self._selector.x = x 53 self._selector.y = y 54 55 self._animated_selector = implicit.AnimatedObject(self._selector) 56 settings = {'duration': 200, 57 'transformation': implicit.DECELERATE} 58 self._animated_selector.setup_next_animations(**settings) 59 self._animated_selector.mode = implicit.REPLACE 60 61 self._update_selector() 62 self._layout_selector() 63 self._selector.visible = True64 6769 self._hbar = bar 70 self._hbar_pos = position 71 self._hbar.items_number = self.visible_range_size 72 self._hbar.width = self.width 73 self._hbar_spacing = self._hbar.height + spacing 74 self._hbar.connect('index-changed', self._bar_index_changed) 75 self._update_bars()7678 self._vbar = bar 79 self._vbar_pos = position 80 self._vbar.items_number = self.visible_range_size 81 self._vbar.height = self.height 82 self._vbar_spacing = self._vbar.width + spacing 83 self._vbar.connect('index-changed', self._bar_index_changed) 84 self.add(self._vbar) 85 self._update_bars()86 90 9496 empty = len(self.widgets) == 0 97 try: 98 list_ng.List.insert(self, index, widget, forward_signals) 99 finally: 100 if not empty: 101 self._update_bars() 102 self._layout_selector()103105 try: 106 item = list_ng.List.pop(self, index) 107 finally: 108 self._update_bars() 109 self._layout_selector() 110 return item111113 # always keep the selected item in [0, len(self.widgets)) 114 if index < 0: 115 self._animated.visible_range_start = 0 116 index = 0 117 elif index >= len(self.widgets): 118 self._animated.visible_range_start = \ 119 max(0, len(self.widgets) - self.visible_range_size) 120 index = len(self.widgets) - 1 121 122 list_ng.List.selected_item__set(self, index) 123 124 if self._vbar: 125 self._vbar.cursor_index = index 126 if self._hbar: 127 self._hbar.cursor_index = index 128 129 self._layout_selector()130 135 140 145 149151 x = list_ng.List.compute_x(self, index) 152 if self._vbar: 153 if self._vbar_pos == const.LEFT: 154 x += self._vbar_spacing 155 else: 156 x -= self._vbar_spacing 157 158 return x159161 y = list_ng.List.compute_y(self, index) 162 if self._hbar: 163 if self._hbar_pos == const.TOP: 164 y += self._hbar_spacing 165 else: 166 y -= self._hbar_spacing 167 return y168170 x, y, z = self.position 171 172 # toggle scrollbars when no scroll needed 173 visible = len(self.widgets) > self.visible_range_size 174 if self._vbar: 175 self._vbar.visible = visible 176 if self._hbar: 177 self._hbar.visible = visible 178 179 if self._vbar: 180 self._vbar.items_number = len(self.widgets) 181 self._vbar.height = self.height 182 183 if self._vbar_pos == const.LEFT: 184 self._vbar.position = (0, 0, z) 185 elif self._vbar_pos == const.RIGHT: 186 x = self.width - self._vbar_spacing 187 self._vbar.position = (x, 0, z) 188 189 if self._hbar: 190 self._hbar.items_number = len(self.widgets) 191 self._hbar.width = self.width 192 193 if self._hbar_pos == const.TOP: 194 self._hbar.position = (0, 0, z) 195 elif self._hbar_pos == const.BOTTOM: 196 y = self.height - self._hbar_spacing 197 self._hbar.position = (0, y, z)198200 if self._selector: 201 if len(self.widgets) > 0: 202 selected_item = self.selected_item 203 204 # FIXME: copied from Grid... Might be better to factorize in 205 # list_ng directly. 206 half_size = (self.visible_range_size - 1.0) / 2.0 207 position = -self._animated.visible_range_start + \ 208 int(self.selected_item) 209 210 lower_limit = half_size 211 upper_limit = -self._animated.visible_range_start + \ 212 len(self.widgets) - half_size 213 214 if (position <= lower_limit) or (position >= upper_limit): 215 selected_item = position 216 217 x = self.compute_x(selected_item) 218 y = self.compute_y(selected_item) 219 220 spacing = self._selector_spacing 221 222 if self._orientation == const.VERTICAL: 223 x -= spacing / 2. 224 y -= spacing / 2. 225 elif self._orientation == const.HORIZONTAL: 226 x -= spacing 227 y -= spacing 228 229 if self._selector.visible and self._selector.opacity != 0: 230 self._animated_selector.position = (x, y, -1.0) 231 else: 232 self._selector.position = (x, y, -1.0) 233 else: 234 self._selector.visible = False235237 if self._selector: 238 width, height = self._widget_width*1.1, self._widget_height 239 height += self._selector_spacing 240 width += self._selector_spacing * 2.5 241 242 self._selector.size = (width, height)243245 super(ScrolledList, self).do_drag_begin(x, y, z, button, time) 246 self._animated_selector.opacity = 0247266352 353268 Group.__init__(self) 269 270 self.thumbnail = Image() 271 self.thumbnail.bg_color = (0, 255, 0, 255) 272 #self.thumbnail.bg_color = (0, 0, 0, 0) 273 self.thumbnail.layout = pgm.IMAGE_SCALED 274 self.thumbnail.visible = True 275 276 self._description = self._create_text() 277 #self._description.bg_color = (255, 0, 0, 255) 278 279 self.add(self.thumbnail) 280 self.add(self._description) 281 282 if thumbnail is not None: 283 self.thumbnail.set_from_file(thumbnail) 284 285 self.description = description 286 287 if self.canvas: 288 self._layout() 289 290 # Arrow support disabled until some decision is taken. 291 """ 292 arrow_x = text_x + text_width 293 arrow_y = 0.4 294 arrow_width = 0.25 295 arrow_height = 0.8 296 297 self.arrow = Image() 298 self.arrow.bg_color = (0, 0, 0, 0) 299 #self.arrow.bg_color = (0, 0, 255, 255) 300 self.arrow.layout = pgm.IMAGE_SCALED 301 self.arrow.size = (arrow_width, arrow_height) 302 self.add(self.arrow) 303 self.arrow.position = (arrow_x, arrow_y, 0) 304 305 if arrow: 306 self.arrow.set_from_file(arrow) 307 """308310 canvas = self.canvas 311 312 vspacing = canvas.width / 35. 313 thumbnail_width = canvas.width / 13. 314 thumbnail_height = canvas.height / 8. 315 thumbnail_x = canvas.width / 70. 316 thumbnail_y = canvas.height / 60. 317 318 self.thumbnail.position = (thumbnail_x, thumbnail_y, 0) 319 self.thumbnail.size = (thumbnail_width, thumbnail_height) 320 321 text_x = thumbnail_width + vspacing 322 text_y = canvas.height / 45. 323 text_width = canvas.width / 1.9 324 #text_height = canvas.height / 6. 325 #print self.height 326 text_height = self.height 327 font_height = text_height * 0.35 328 329 self._description.font_height = font_height 330 self._description.position = (text_x, text_y, 0) 331 self._description.size = (text_width, text_height)332 336338 txt = Text() 339 txt.font_family = "Nimbus Sans L" 340 txt.bg_color = (0, 0, 0, 0) 341 txt.alignment = pgm.TEXT_ALIGN_LEFT 342 txt.ellipsize = pgm.TEXT_ELLIPSIZE_MIDDLE 343 txt.opacity = 255 344 return txt345 349355384 385 386 text_idx = 0 387358 super(DetailedListItem, self).__init__(thumbnail=thumbnail, 359 description=description, 360 arrow=arrow) 361 362 self._sub_description = self._create_text() 363 self.add(self._sub_description) 364 self._sub_description.fg_color = (150, 150, 150, 255) 365 #self._sub_description.bg_color = (0, 0, 255, 255) 366 self._sub_description.visible = True 367 self._sub_description.font_height = 0.12 368 369 if sub_description: 370 self.sub_description = sub_description 371 372 text_x = self.description.x 373 text_y = 0.21 374 text_width = self.description.width 375 text_height = .25 376 377 self._description.y = 0.01 378 379 self._sub_description.position = (text_x, text_y, 0) 380 self._sub_description.size = (text_width, text_height)381383 self._sub_description.markup = '<b>%s</b>' % text389 global text_idx 390 txt = Text() 391 txt.label = "%s %s" % (label, text_idx) 392 text_idx += 1 393 txt.font_family = "Bitstream DejaVu" 394 txt.font_height = 0.125 395 txt.alignment = pgm.TEXT_ALIGN_CENTER 396 txt.bg_color = (255, 0, 0, 123) 397 #txt.bg_color = (0, 0, 0, 0) 398 txt.ellipsize = pgm.TEXT_ELLIPSIZE_END 399 txt.visible = True 400 return txt401403 img = Image() 404 img.set_from_file(img_file) 405 img.fg_color = (255, 255, 255, 255) 406 #img.bg_color = (100, 200, 100, 155) 407 img.bg_color = (0, 0, 0, 0) 408 img.opacity = 0 409 img.visible = True 410 return img411413 # quit on q or ESC 414 if event.keyval in (pgm.keysyms.q, pgm.keysyms.Escape): 415 pgm.main_quit() 416 417 elif event.keyval == pgm.keysyms.a: 418 canvas.regenerate() 419 420 if event.keyval in (pgm.keysyms.Down, pgm.keysyms.Right): 421 for l in lists: 422 l.selected_item += 1 423 elif event.keyval in (pgm.keysyms.Up, pgm.keysyms.Left): 424 for l in lists: 425 l.selected_item -= 1 426 elif event.keyval == pgm.keysyms.r: 427 for l in lists: 428 l.pop()429 432 433 # OpenGL viewport creation 434 factory = pgm.ViewportFactory('opengl') 435 gl = factory.create() 436 gl.title = 'TextList widget-test' 437 438 # Canvas and image drawable creation 439 canvas = pgm.Canvas() 440 441 # Bind the canvas to the OpenGL viewport 442 gl.set_canvas(canvas) 443 gl.show() 444 445 top_left = ScrolledList(3.0, 1.0, orientation=const.VERTICAL) 446 top_left.position = (0.04, 0.5, 0) 447 top_left.width = canvas.width * 0.5 448 top_left.height = canvas.height * 0.8 449 ## top_left.position = (0.5, 0.2, 0.0) 450 top_left.visible_range_size = 9 451 ## top_left.width = canvas.width * 0.6 452 ## top_left.height = canvas.height * 0.8 453 top_left.visible = True 454 top_left.canvas = canvas 455 456 bg = SlicedImage() 457 bg.top_file = "theme/scrollbar-top.png" 458 bg.bottom_file = "theme/scrollbar-bottom.png" 459 bg.body_file = "theme/scrollbar-body.png" 460 461 cursor = SlicedImage() 462 cursor.top_file = "theme/cursor-top.png" 463 cursor.bottom_file = "theme/cursor-bottom.png" 464 cursor.body_file = "theme/cursor-body.png" 465 466 bar = Scrollbar(items_number=9, background=bg, cursor=cursor, spacing=0.01) 467 #bar.visible = False 468 469 #thickness=0.08, 470 top_left.set_vertical_scrollbar(bar, const.LEFT) 471 472 pictos = ("theme/selector-left.png", 473 "theme/selector-right.png", 474 "theme/selector-body.png", 475 "theme/back-selector-left.png", 476 "theme/back-selector-right.png", 477 "theme/back-selector-body.png", 478 ) 479 list_selector = selector.Selector(orientation=const.HORIZONTAL, *pictos) 480 top_left.set_selector(list_selector) 481 482 lists = [top_left, ] 483 484 if len(sys.argv[1:]) >= 1: 485 cover = sys.argv[1] 486 else: 487 cover = '/tmp/cover.png' 488 if not os.path.exists(cover): 489 cover = None 490 491 txt = "This is a very long text blah blah blah!" 492 for l in lists: 493 for i in xrange(1): 494 d = ListItem(cover, txt, 495 "theme/arrow.png") 496 ## d = DetailedListItem(cover, txt, "theme/arrow.png", 497 ## sub_description="this is the sub text quoi") 498 l.append(d) 499 500 # Let's start a mainloop 501 gl.connect('key-press-event', on_key_press, lists) 502 gl.connect('delete-event', on_delete) 503 pgm.main() 504
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:10:22 2008 | http://epydoc.sourceforge.net |