Package elisa :: Package plugins :: Package base :: Package views :: Module slideshow_view
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.base.views.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 common 
 21  from elisa.base_components.view import View 
 22   
 23  import pgm 
 24  import tempfile, os 
 25   
 26  from twisted.internet import defer, reactor 
 27   
28 -class SlideshowView(View):
29 30 supported_controllers = ('base:slideshow_controller',) 31
32 - def __init__(self):
33 super(SlideshowView, self).__init__() 34 self.slideshow_widget = None 35 self._delay_id = None 36 37 # FIXME: this is a workaround the fact that we are not warned when 38 # self.controller.model.playlist changes 39 self._playlist = []
40
41 - def frontend_changed(self, previous_frontend, new_frontend):
42 if new_frontend == None: 43 return 44 45 super(SlideshowView, self).frontend_changed(previous_frontend, 46 new_frontend) 47 48 if self.slideshow_widget == None: 49 canvas = self.frontend.context.viewport_handle.get_canvas() 50 self.slideshow_widget = self.SlideshowWidgetClass(canvas, 51 pgm.DRAWABLE_FAR) 52 self.slideshow_widget.size = canvas.size 53 self.slideshow_widget.visible = True 54 55 self.context_handle = self.slideshow_widget 56 57 self.slideshow_widget.connect('clicked', self.drag_clicked) 58 self.slideshow_widget.connect('drag_begin', self.drag_begin) 59 self.slideshow_widget.connect('drag_motion', self.drag_motion) 60 self.slideshow_widget.connect('drag_end', self.drag_end)
61
62 - def controller_changed(self, old_controller, new_controller):
63 self.slideshow_widget.duration = self.controller.model.duration
64
65 - def attribute_set(self, origin, key, old_value, new_value):
66 super(SlideshowView, self).attribute_set(origin, key, old_value, 67 new_value) 68 if key == 'current_index': 69 if self._delay_id != None and self._delay_id.active(): 70 self._delay_id.cancel() 71 # update paths to the pictures in the slideshow widget 72 # FIXME: this is a hack and should actually only be done when 73 # playlist's content changes; it is also quite inefficient. 74 #paths = map(lambda uri: uri.path, self.controller.model.playlist) 75 #self.slideshow_widget.pictures_paths = paths 76 77 if self._playlist != self.controller.model.playlist: 78 # copy the original playlist model locally 79 self._playlist = [] 80 for picture in self.controller.model.playlist: 81 self._playlist.append(picture) 82 83 # update paths to the pictures in the slideshow widget 84 size = len(self._playlist) 85 self.slideshow_widget.pictures_paths = [""]*size 86 i = 0 87 for uri in self._playlist: 88 self._set_thumbnail_path(uri, i) 89 i += 1 90 91 # update the path for the current item 92 uri = self._playlist[new_value] 93 94 def load_full_size(path): 95 # FIXME: should wait until the thumbnail has been loaded 96 self.debug("slideshow path at index %s set to %s" \ 97 % (new_value, path)) 98 self.slideshow_widget.set_path_for_index(new_value, path)
99 100 dfr = self._get_local_path(uri) 101 self._delay_id = reactor.callLater(1.0, dfr.addCallback, 102 load_full_size) 103 104 # update the index in the slideshow widget 105 self.slideshow_widget.current_index = new_value 106 107 elif key == 'duration': 108 self.slideshow_widget.duration = new_value
109
110 - def _get_local_path(self, uri):
111 media_manager = common.application.media_manager 112 uri = media_manager.get_real_uri(uri) 113 114 if uri.scheme == 'file': 115 dfr_open = defer.Deferred() 116 path = uri.path 117 dfr_open.callback(path) 118 else: 119 # FIXME: locally cache the picture if it is not a local file; that 120 # should be the job of the media_manager 121 def read(data, handle): 122 fd, path = tempfile.mkstemp(prefix="elisa_", 123 suffix="_%s" % uri.extension) 124 self.debug("caching full resolution image to %s", path) 125 os.write(fd, data) 126 os.close(fd) 127 handle.close() 128 return path
129 130 def opened(handle): 131 if handle != None: 132 dfr_read = handle.read() 133 dfr_read.addCallback(read, handle) 134 135 return dfr_read 136 137 self.debug("downloading full resolution image from %s" % uri) 138 dfr_open = media_manager.open(uri) 139 dfr_open.addCallback(opened) 140 141 return dfr_open 142
143 - def _set_thumbnail_path(self, uri, index):
144 def error(error): 145 try: 146 error.raiseException() 147 except Exception, e: 148 self.info(e)
149 150 def success(result, index): 151 if result is not None: 152 self.debug("slideshow path at index %s set to %s" \ 153 % (index, result[0])) 154 self.slideshow_widget.set_path_for_index(index, result[0]) 155 156 dfr = common.application.thumbnailer.get_thumbnail(uri, 256, "image") 157 dfr.addErrback(error).addCallback(success, index) 158 159
160 - def drag_begin(self, drawable, x, y, z, button, time):
161 return False
162
163 - def drag_end(self, drawable, x, y, z, button, time):
164 return False
165
166 - def drag_motion(self, drawable, x, y, z, button, time):
167 return False
168
169 - def drag_clicked(self, drawable, x, y, z, button, time):
170 return False
171