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 __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 2729 30 supported_controllers = ('base:slideshow_controller',) 3110933 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 = []4042 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 6466 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_value111 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 path129 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 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 162 165 168 171
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:10:08 2008 | http://epydoc.sourceforge.net |