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

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

  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.graph.group import Group 
 18  from pgm.graph.text import Text # FIXME: should be replaced with Rectangle 
 19  from pgm.graph.image import Image 
 20  from pgm.timing import implicit 
 21  import gst 
 22  import os 
 23  import pgm 
 24  from twisted.internet import reactor 
 25   
26 -class Dock(Group):
27
28 - def __init__(self, canvas, layer, 29 width, height, 30 background_image):
31 32 Group.__init__(self, canvas, layer) 33 34 # build the background 35 self._background = Image() 36 self._background.set_from_file(background_image) 37 self._background.layout = pgm.IMAGE_FILLED 38 self._background.alignment = pgm.IMAGE_LEFT 39 self._background.opacity = 255 40 self._background.bg_color = (0, 0, 0, 0) 41 self.add(self._background) 42 self._background.position = (0.0, 0.0, 0.0) 43 self._background.size = (width, height) 44 45 self._background.visible = True 46 47 self._show = None 48 49 self._animated_group = implicit.AnimatedObject(self) 50 self._animated_group.mode = implicit.REPLACE 51 self._animated_group.setup_next_animations(duration = 500, 52 transformation = implicit.DECELERATE)
53
54 - def show(self, time_to_show=-1):
55 """ 56 Show the player dock for the next seconds 57 @time_to_show: duration before the dock disappears (in seconds) 58 if set to -1 the dock will not disappear 59 """ 60 if self._animated_group.opacity != 255: 61 self._animated_group.opacity = 255 62 63 if time_to_show > 0: 64 if self._show != None and self._show.active(): 65 self._show.reset(time_to_show) 66 else: 67 self._show = reactor.callLater(time_to_show, self.hide)
68
69 - def _cancel_timer(self):
70 if self._show != None and self._show.active(): 71 self._show.cancel()
72
73 - def hide(self):
74 """ 75 Hide the dock 76 """ 77 self._cancel_timer() 78 if self._animated_group.opacity != 0: 79 self._animated_group.opacity = 0
80
81 - def is_visible(self):
82 # FIXME: we should override visible__get() here, but it doesn't work... 83 # the progress bar is not visible anymore if we do so. 84 return self._animated_group.opacity == 255
85 86
87 - def image_from_path(self, path):
88 self._background.set_from_file(path)
89
90 - def connect(self, signal, *args):
91 self._background.connect(signal, *args)
92 93 94 95 96 97 98 99 LEFT, RIGHT, TOP, BOTTOM = 0, 1, 2, 3 100 EXTENDED, FIXED, OPTIMISED = 0, 1, 2 101
102 -class OldDock(Group):
103
104 - def __init__(self, canvas, layer):
105 # group containing the dock's widgets 106 Group.__init__(self, canvas, layer) 107 self._thickness = 0.25 108 self._stick = TOP 109 self._layout = EXTENDED 110 self._opened_value = 0.0 111 112 self._animated_group = implicit.AnimatedObject(self) 113 self._animated_group.setup_next_animations(duration = 500) 114 115 # background of the dock 116 # FIXME: should be replaced with Rectangle 117 self._background = Image() 118 # self._background.label = "" 119 self._background.bg_color = (20, 20, 20, 255) 120 self.add(self._background) 121 122 # default values 123 # self._position = TOP 124 # self._thickness = 0.25 125 # self._layout = EXTENDED 126 127 # recompute properties 128 self.stick = TOP 129 self.thickness = self._thickness 130 self.layout = self._layout 131 132 # display the dock 133 self.visible = False 134 self._background.visible = True
135 136 137
138 - def stick__set(self, position):
139 previous_position = self._stick 140 self._stick = position 141 142 # reorganise the dock's widgets 143 if (previous_position in [TOP, BOTTOM]).__xor__ \ 144 (position in [TOP, BOTTOM]): 145 for child in self.children: 146 if child != self._background: 147 # FIXME: bug if set during implicit animation 148 #print child, child.x, child.y 149 child.x, child.y = child.y, child.x 150 #print child, child.x, child.y 151 152 # reposition the dock 153 if position == TOP: 154 self._coordinate = "y" 155 self._opened_value = 0.0 156 self._animated_group.x = 0.0 157 elif position == BOTTOM: 158 self._coordinate = "y" 159 self._opened_value = self._canvas.height - self.thickness 160 self._animated_group.x = 0.0 161 162 self._animated_group.y = self._opened_value 163 164 # recompute properties 165 self.thickness = self._thickness 166 self.layout = self._layout
167
168 - def stick__get(self):
169 return self._stick
170
171 - def layout__set(self, layout):
172 self._layout = layout 173 174 if layout == EXTENDED: 175 self._background.size = (self._canvas.width, 176 self._background.size[1])
177 178
179 - def layout__get(self):
180 return self._layout
181
182 - def thickness__set(self, thickness):
183 self._thickness = thickness 184 185 for child in self.children: 186 if child == self._background: 187 child.size = (child.size[0], thickness) 188 else: 189 child.size = (thickness, thickness)
190
191 - def thickness__get(self):
192 return self._thickness
193
194 - def open(self):
195 value = self._opened_value 196 self._animated_group.y = value
197
198 - def close(self):
199 value = self._opened_value - self._thickness 200 self._animated_group.y = value
201
202 - def add(self, item, setx=0.0, sety=0.0):
203 Group.add(self, item) 204 item.size = (self.thickness, self.thickness) 205 206 if self._layout == EXTENDED: 207 item.x = setx 208 item.y = sety
209 210 211 if __name__ == "__main__": 212 from pgm.graph.image import Image 213 from pgm.graph.text import Text 214 import pgm 215 import os, gobject, sys 216
217 - def handle_events(dock, gl, loop):
218 for event in gl.get_events(): 219 if event.type == pgm.DELETE: 220 loop.quit() 221 222 if event.type == pgm.KEY_PRESS: 223 if event.keyval == pgm.KEY_ESCAPE or event.keyval == pgm.KEY_q: 224 loop.quit() 225 226 elif event.keyval == pgm.KEY_DOWN: 227 if dock.stick == TOP: 228 dock.open() 229 elif dock.position == BOTTOM: 230 dock.close() 231 232 elif event.keyval == pgm.KEY_UP: 233 if dock.stick == TOP: 234 dock.close() 235 elif dock.position == BOTTOM: 236 dock.open() 237 238 elif event.keyval == pgm.KEY_RIGHT: 239 if dock.stick == RIGHT: 240 dock.close() 241 elif dock.position == LEFT: 242 dock.open() 243 244 elif event.keyval == pgm.KEY_LEFT: 245 if dock.stick == RIGHT: 246 dock.open() 247 elif dock.position == LEFT: 248 dock.close() 249 250 elif event.keyval == pgm.KEY_s: 251 dock.stick = LEFT 252 253 elif event.keyval == pgm.KEY_d: 254 dock.stick = BOTTOM 255 256 elif event.keyval == pgm.KEY_f: 257 dock.stick = TOP 258 259 elif event.keyval == pgm.KEY_g: 260 dock.stick = RIGHT 261 262 elif event.keyval == pgm.KEY_i: 263 dock.stick += 0.1 264 265 elif event.keyval == pgm.KEY_o: 266 dock.stick -= 0.1 267 268 return True
269 270 factory = pgm.ViewportFactory('opengl') 271 gl = factory.create() 272 gl.title = 'Dock widget' 273 274 canvas = pgm.Canvas() 275 276 gl.set_canvas(canvas) 277 278 279 dock = Dock(canvas, pgm.DRAWABLE_MIDDLE) 280 281 label = Text() 282 label.label = "Dock" 283 label.fg_color = (220, 220, 220, 255) 284 label.bg_color = (0, 0, 0, 0) 285 label.visible = True 286 287 logo = Image() 288 # logo.set_from_file("fluendo.png") 289 logo.bg_color = (0, 0, 0, 0) 290 logo.opacity = 255 291 logo.visible = True 292 293 video = Image() 294 video.bg_a = 0 295 video.visible = True 296 297 if len(sys.argv) > 1: 298 # GStreamer pipeline setup 299 pipeline = gst.element_factory_make('playbin') 300 sink = gst.element_factory_make('pgmimagesink') 301 pipeline.set_property('uri', sys.argv[1]) 302 pipeline.set_property('video-sink', sink) 303 sink.set_property('image', video) 304 pipeline.set_state(gst.STATE_PLAYING) 305 306 dock.add(video, 1.0) 307 dock.add(label, 0.8,0.1) 308 dock.add(logo, 0.0) 309 310 # animate the logo 311 animated_logo = implicit.AnimatedObject(logo) 312 313 animated_logo.setup_next_animations(duration=500, 314 repeat_behavior=implicit.REVERSE, 315 repeat_count=implicit.INFINITE) 316 animated_logo.opacity = 100 317 318 # animate the video 319 animated_video = implicit.AnimatedObject(video) 320 animated_video.setup_next_animations(duration=1000, 321 repeat_behavior=implicit.REVERSE, 322 repeat_count=implicit.INFINITE, 323 transformation=implicit.SMOOTH) 324 animated_video.x = 2.0 325 326 327 loop = gobject.MainLoop() 328 gobject.timeout_add(5, gl.update) 329 gobject.timeout_add(15, handle_events, dock, gl, loop) 330 loop.run() 331