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

Source Code for Module elisa.plugins.bad.poblenou_frontend.slideshow_view

  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  __maintainer__ = 'Florian Boucault <florian@fluendo.com>' 
 18   
 19   
 20  from elisa.core import plugin_registry 
 21   
 22  from poblenou_widgets.slideshow import Slideshow 
 23  from poblenou_widgets.slideshow_osd import SlideshowOsd 
 24  from poblenou_widgets.player_osd import Dock 
 25   
 26  from pgm.graph.group import Group 
 27   
 28  import pgm 
 29   
 30  SlideshowViewClass = plugin_registry.get_component_class('base:slideshow_view') 
 31  PlayerViewClass = plugin_registry.get_component_class('poblenou:player_view') 
 32   
33 -class SlideshowView(SlideshowViewClass, PlayerViewClass):
34 default_config = {} 35 supported_controllers = ('base:slideshow_controller',) 36 37 SlideshowWidgetClass = Slideshow 38 39 bindings = {'playing':'playing', 40 'current_index' : 'index'} 41
42 - def __init__(self):
43 super(SlideshowView, self).__init__() 44 45 # delay before the osd disappears automatically 46 self._osd_duration = 3 47 48 # position of the mouse when the dragging started 49 self._drag_start_position = None
50
51 - def playing__set(self, state):
52 if self.controller.focused: 53 self.osd_show(self._osd_duration)
54
55 - def index__set(self, index):
58
59 - def frontend_changed(self, previous_frontend, new_frontend):
60 # FIXME: we can't use super() because of context_handle overriding 61 # by both parent views. :( 62 63 if new_frontend == None: 64 return 65 66 viewport = self.frontend.context.viewport_handle 67 canvas = viewport.get_canvas() 68 viewport.connect("motion-notify-event", self.mouse_moved) 69 70 if self.slideshow_widget == None: 71 canvas = self.frontend.context.viewport_handle.get_canvas() 72 self.slideshow_widget = self.SlideshowWidgetClass(canvas, 73 pgm.DRAWABLE_FAR) 74 self.slideshow_widget.size = canvas.size 75 self.slideshow_widget.visible = True 76 77 self.slideshow_widget.connect('clicked', self.drag_clicked) 78 self.slideshow_widget.connect('drag_begin', self.drag_begin) 79 self.slideshow_widget.connect('drag_motion', self.drag_motion) 80 self.slideshow_widget.connect('drag_end', self.drag_end) 81 82 83 if self.group == None: 84 canvas = self.frontend.context.viewport_handle.get_canvas() 85 86 # FIXME: why is the OSD not in self.group? Because of resizing 87 # issue that will be solved when drawable.regenerate is in place 88 # in Pigment. 89 90 # create the group containing all the widgets of the player 91 self.group = Group(canvas, pgm.DRAWABLE_FAR) 92 self.group.visible = True 93 self.context_handle = self.group 94 95 theme = self.frontend.theme 96 self._normal_osd_status_bg = theme.get_media("dock_background") 97 self._mouse_osd_status_bg = theme.get_media("dock_background_mouse") 98 self._play_button_image = theme.get_media("play_button_mouse") 99 self._pause_button_image = theme.get_media("pause_button_mouse") 100 101 self._create_background() 102 self._create_playpause_button() 103 self._create_osd_status_widget() 104 self._create_back_widget()
105
106 - def _create_background(self):
107 self._background = self.slideshow_widget 108 self.group.add(self._background)
109
111 # FIXME: refactorize. only difference with player view is usage 112 # of SlideshowOsd instead of PlayerOsd 113 canvas = self.frontend.context.viewport_handle.get_canvas() 114 theme = self.frontend.theme 115 116 osd_status_bar_bg = theme.get_media("dock_bar_bg") 117 osd_status_bar_fg = theme.get_media("dock_bar_fg") 118 119 px, py = 0.7, 0.8 120 iw, ih = canvas.width, canvas.height 121 osd_status_w = iw * px 122 osd_status_h = ih * 0.15 123 self._osd_status = SlideshowOsd(canvas, 124 pgm.DRAWABLE_FAR, 125 10000, 126 osd_status_w, osd_status_h, 127 osd_status_bar_bg, 128 osd_status_bar_fg, 129 self._normal_osd_status_bg) 130 self._osd_status.opacity = 0 131 self._osd_status.position = self._osd_status_position 132 self._osd_status.visible = True 133 self._osd_status.index = 0 134 self._osd_status.length = 0 135 self._osd_status.connect("clicked", self._osd_status_clicked)
136
137 - def attribute_set(self, origin, key, old_value, new_value):
138 super(SlideshowView, self).attribute_set(origin, key, old_value, 139 new_value) 140 if key == 'focused': 141 if (new_value, self.frontend.context.touchscreen) == (True, True): 142 self.osd_show(self._osd_duration)
143
144 - def osd_show(self, time_visible=-1):
145 self._update_play_button('') 146 self._update_length_and_position() 147 self._update_osd_layout() 148 self._osd_back_button.show(time_visible) 149 self._osd_status.show(time_visible) 150 self._osd_play_button.show(time_visible)
151
152 - def osd_hide(self):
153 self._osd_back_button.hide() 154 self._osd_status.hide() 155 self._osd_play_button.hide()
156
157 - def focused_changed(self, new_value):
158 if not new_value: 159 self.osd_hide()
160
162 self._osd_status.length = len(self.controller.model.playlist) 163 self._osd_status.index = self.controller.model.current_index +1
164
165 - def _update_play_button(self, state):
166 if self.controller.model.playing == True: 167 icon = self._pause_button_image 168 else: 169 icon = self._play_button_image 170 171 self._osd_play_button.image_from_path(icon)
172
173 - def mouse_moved(self, viewport, event):
174 if not self.controller.focused: 175 return False 176 177 self.osd_show(self._osd_duration) 178 return True
179
180 - def _osd_play_button_clicked(self, drawable, x, y, z, button, time):
185
186 - def _osd_back_button_clicked(self, drawable, x, y, z, button, time):
187 if self.controller is None or not self.controller.focused: 188 return False 189 190 self.osd_hide() 191 self.controller.model.playling = False 192 self.controller.parent.focus() 193 return True
194
195 - def drag_begin(self, drawable, x, y, z, button, time):
196 if self.controller is None or not self.controller.focused: 197 return False 198 199 self._drag_start_position = (x, y) 200 self.slideshow_widget.move(0.0) 201 self.osd_show(self._osd_duration) 202 return True
203
204 - def drag_end(self, drawable, x, y, z, button, time):
205 if self.controller is None or not self.controller.focused: 206 return False 207 208 if self._drag_start_position != None: 209 dx = self._drag_start_position[0] - x 210 dy = self._drag_start_position[1] - y 211 212 if dx > 0.3: 213 if not self.controller.next_image(): 214 self.slideshow_widget.release() 215 elif dx < -0.3: 216 if not self.controller.previous_image(): 217 self.slideshow_widget.release() 218 else: 219 self.slideshow_widget.release() 220 221 self._drag_start_position = None 222 223 self.osd_show(self._osd_duration) 224 225 return True 226 227 return False
228
229 - def drag_motion(self, drawable, x, y, z, button, time):
230 if self.controller is None or not self.controller.focused: 231 return False 232 233 if self._drag_start_position != None: 234 dx = x - self._drag_start_position[0] 235 self.slideshow_widget.move(dx) 236 return True 237 238 return False
239
240 - def drag_clicked(self, drawable, x, y, z, button, time):
241 if self.controller is None or not self.controller.focused: 242 return False 243 244 if self.slideshow_widget.visible == False or self.slideshow_widget.opacity == 0.0: 245 return False 246 247 if self._drag_start_position != None: 248 dx = self._drag_start_position[0] - x 249 if dx < -0.05 or dx > 0.05: 250 return True 251 252 self.osd_show(self._osd_duration) 253 return True
254