Package elisa :: Package plugins :: Package bad :: Package poblenou_frontend :: Package poblenou_widgets :: Module circular_list
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.poblenou_frontend.poblenou_widgets.circular_list

  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  import math 
 18   
 19  import pgm 
 20  from pgm.widgets.list import List 
 21   
 22  VERTICAL, HORIZONTAL = 0, 1 
 23   
24 -class CircularList(List):
25
26 - def __init__(self, 27 canvas, 28 layer, 29 width = 1.0, 30 height = 2.0, 31 visible_items = 7, 32 orientation = VERTICAL, 33 selected_item = 0, 34 selector_file = None, 35 selector_offset = (0.0, 0.0, 0.0), 36 selector_size = (1.0, 1.0)):
37 38 self._ratio = 4.0/3.0 39 40 List.__init__(self, canvas, layer, 41 width, height, 42 visible_items, orientation, 43 selected_item, selector_file, 44 selector_offset, selector_size)
45 46 47
48 - def _compute_position(self, index):
49 # it depends on the zoom 50 zoom = self._compute_zoom(index) 51 52 # floor division 53 middle_index = self._visible_items // 2 + 1 54 55 tw = self._width 56 th = self._height 57 58 # x/y_top_left_offset are the offset between the top left corner and 59 # the center of a drawable 60 # x and y are the coordinates of the center of the drawable 61 if self._orientation == VERTICAL: 62 h = self._widget_height*zoom 63 w = h*self._ratio 64 x_top_left_offset = -w/2.0 65 y_top_left_offset = -h/2.0 66 67 step = math.pi/(self.visible_items+1) 68 69 a = step*index 70 if index == middle_index: 71 z = 1.0 72 elif index < middle_index: 73 z = 0.0 74 elif index > middle_index: 75 z = 0.0 76 77 x = math.sin(a)*tw 78 y = -math.cos(a)*th/2.0 + th/2.0 79 80 elif self._orientation == HORIZONTAL: 81 w = self._widget_width*zoom 82 h = w/self._ratio 83 x_top_left_offset = -w/2.0 84 y_top_left_offset = -h/2.0 85 86 step = math.pi/(self.visible_items+1) 87 88 a = step*index 89 if index == middle_index: 90 z = 1.0 91 elif index < middle_index: 92 z = 0.0 93 elif index > middle_index: 94 z = 0.0 95 96 x = -math.cos(a)*tw/2.0 + tw/2.0 97 y = math.sin(a)*th 98 99 position = (x+x_top_left_offset, y+y_top_left_offset, z) 100 return position
101
102 - def _compute_opacity(self, index):
103 # floor division 104 middle_index = self._visible_items // 2 + 1 105 if index == middle_index: 106 return 255 107 elif index == 0 or index == self._visible_items+1: 108 return 0 109 else: 110 max_opacity = 80 111 min_opacity = 50 112 step = (max_opacity - min_opacity) / middle_index 113 114 if index > middle_index: 115 index = -index + 2*middle_index 116 117 opacity = min_opacity + index * step 118 return opacity
119
120 - def _compute_zoom(self, index):
121 zoom_middle = 1.7 122 min_zoom = 0.6 123 # floor division 124 middle_index = self._visible_items // 2 + 1 125 126 if index == middle_index: 127 return zoom_middle + 0.1 128 elif index == 0 or index == self._visible_items+1: 129 return min_zoom 130 else: 131 mid = middle_index - 1 132 step = (2.0*mid+1.0-zoom_middle-2.0*mid*min_zoom)/(mid*(mid-1)) 133 134 if index > middle_index: 135 index = -index + 2*middle_index 136 137 zoom = min_zoom + (index-1) * step 138 return zoom
139 140
141 - def _update(self):
142 # floor division 143 start = self._selected_item - self._visible_items // 2 - 1 144 stop = min(start + self._visible_items + 2, len(self.widgets)) 145 146 i = max(0, -start) 147 148 for widget in self.animated_widgets[max(start, 0):stop]: 149 widget.opacity = self._attributes[i][1] 150 widget.position = self._attributes[i][0] 151 zoom = self._attributes[i][2] 152 if self._orientation == VERTICAL: 153 h = self._widget_height*zoom 154 w = h*self._ratio 155 widget.size = (w, h) 156 157 elif self._orientation == HORIZONTAL: 158 w = self._widget_width*zoom 159 h = w/self._ratio 160 widget.size = (w, h) 161 i += 1
162 163 164 if __name__ == "__main__": 165 import os 166 import pgm 167 import gobject 168 import gst 169 from pgm.graph.text import Text 170 from pgm.graph.image import Image 171 from pgm.timing import implicit 172
173 - def create_text(label):
174 txt = Text() 175 txt.label = label 176 txt.font_family = "Bitstream DejaVu" 177 txt.font_height = 0.225 178 txt.fg_color = (255, 255, 255, 255) 179 txt.bg_color = (255, 0, 0, 255) 180 txt.ellipsize = pgm.TEXT_ELLIPSIZE_END 181 txt.visible = True 182 return txt
183
184 - def create_img(img_file):
185 img = Image() 186 img.set_from_file(img_file) 187 img.fg_color = (255, 255, 255, 255) 188 img.bg_color = (100, 200, 100, 155) 189 img.visible = True 190 return img
191
192 - def create_video(video_uri):
193 img = Image() 194 img.fg_color = (255, 255, 255, 255) 195 img.bg_color = (0, 0, 0, 0) 196 img.alignment = pgm.IMAGE_LEFT 197 img.visible = True 198 199 # GStreamer pipeline setup 200 pipeline = gst.element_factory_make('playbin') 201 sink = gst.element_factory_make('pgmimagesink') 202 pipeline.set_property('uri', video_uri) 203 pipeline.set_property('video-sink', sink) 204 sink.set_property('image', img) 205 pipeline.set_state(gst.STATE_PLAYING) 206 207 return img
208 209
210 - def on_key_press(viewport, event, gl, widget, step_size):
211 if event.type == pgm.KEY_PRESS: 212 # quit on q or ESC 213 if event.keyval == pgm.keysyms.q or event.keyval == pgm.keysyms.Escape: 214 pgm.main_quit() 215 216 elif event.keyval == pgm.keysyms.b: 217 list_widget.selected_item = 0 218 219 elif event.keyval == pgm.keysyms.g: 220 list_widget.selected_item = len(list_widget) - 1 221 222 elif event.keyval == pgm.keysyms.h: 223 list_widget.visible_items += 2 224 print list_widget.visible_items 225 226 elif event.keyval == pgm.keysyms.n: 227 list_widget.visible_items -= 2 228 229 elif event.keyval == pgm.keysyms.s: 230 if list_widget.orientation == VERTICAL: 231 list_widget.orientation = HORIZONTAL 232 elif list_widget.orientation == HORIZONTAL: 233 list_widget.orientation = VERTICAL 234 235 elif event.keyval == pgm.keysyms.Down or \ 236 event.keyval == pgm.keysyms.Right: 237 list_widget.selected_item += 1 238 239 elif event.keyval == pgm.keysyms.Up or \ 240 event.keyval == pgm.keysyms.Left: 241 list_widget.selected_item -= 1 242 243 # add an example entry at the 3rd position 244 elif event.keyval == pgm.keysyms.space: 245 list_widget.insert(2, create_text("Test")) 246 #list_widget.append(create_text("Test")) 247 248 # remove the currently selected item 249 elif event.keyval == pgm.keysyms.Return: 250 list_widget.pop(list_widget.selected_item)
251
252 - def on_delete(viewport, event):
253 pgm.main_quit()
254 255 256 257 # OpenGL viewport creation 258 factory = pgm.ViewportFactory('opengl') 259 gl = factory.create() 260 gl.title = 'TextList widget-test' 261 262 # Canvas and image drawable creation 263 canvas = pgm.Canvas() 264 265 # Bind the canvas to the OpenGL viewport 266 gl.set_canvas(canvas) 267 gl.show() 268 269 list_widget = CircularList(canvas, pgm.DRAWABLE_MIDDLE, 270 orientation=HORIZONTAL) 271 list_widget.position = (0.5, 1.0, 0.0) 272 list_widget.width = 3.0 273 list_widget.height = 1.0 274 list_widget.visible_items = 13 275 276 img = Image() 277 img.fg_color = (255, 255, 255, 255) 278 img.bg_color = (100, 200, 100, 155) 279 img.position = list_widget.position 280 img.width = list_widget.width 281 img.height = list_widget.height 282 img.visible = True 283 canvas.add(pgm.DRAWABLE_MIDDLE, img) 284 285 for i in xrange(50): 286 #list_widget.append(create_text("%s" % i)) 287 list_widget.append(create_img("examples/pictures/fluendo.png")) 288 """ 289 t = create_text("%s" % i) 290 i = create_img("examples/pictures/fluendo.png") 291 g = Group(canvas, pgm.DRAWABLE_MIDDLE) 292 g.add(t) 293 g.add(i) 294 g.visible = True 295 list_widget.append(g) 296 """ 297 298 #list_widget.append(create_video("file:///home/kaleo/Desktop/media/videos/t_mariogalaxy_e36_h264.wmv")) 299 300 list_widget.selected_item = 3 301 list_widget.visible = True 302 303 animated_list_widget = implicit.AnimatedObject(list_widget) 304 305 306 # Let's start a mainloop 307 gl.connect('key-press-event', 308 on_key_press, 309 gl, 310 animated_list_widget, 311 0.25) 312 gl.connect('delete-event', on_delete) 313 gobject.timeout_add(10, gl.update) 314 pgm.main() 315