From 8d76aeffd25e243342449b934609ec4cdbac2e8d Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 10 Sep 2014 07:40:12 +0100 Subject: [PATCH] Added thumbnails for images from serviceitems --- openlp/core/lib/serviceitem.py | 17 +++++++++-------- openlp/plugins/images/lib/mediaitem.py | 2 +- openlp/plugins/remotes/lib/httprouter.py | 5 ++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 2d9e396e1..079c0a0bd 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -39,8 +39,8 @@ import uuid from PyQt4 import QtGui -from openlp.core.common import RegistryProperties, Settings, translate -from openlp.core.lib import ImageSource, build_icon, clean_tags, expand_tags +from openlp.core.common import RegistryProperties, Settings, translate, AppLocation +from openlp.core.lib import ImageSource, build_icon, clean_tags, expand_tags, create_thumb log = logging.getLogger(__name__) @@ -292,16 +292,17 @@ class ServiceItem(RegistryProperties): :param path: The directory in which the image file is located. :param title: A title for the slide in the service item. :param background: - :param thumbnail: Optional alternative thumbnail, used for remote thumbnails. + :param thumbnail: Optional thumbnail, used for remote thumbnails. """ if background: self.image_border = background self.service_item_type = ServiceItemType.Image - if thumbnail: - self._raw_frames.append({'title': title, 'path': path, 'image': thumbnail}) - self.image_manager.add_image(thumbnail, ImageSource.ImagePlugin, self.image_border) - else: - self._raw_frames.append({'title': title, 'path': path}) + # If no thumbnail was given we create one + if not thumbnail: + thumbnail = os.path.join(AppLocation.get_section_data_path('images'), 'thumbnails', os.path.split(path)[1]) + create_thumb(path, thumbnail, False) + self._raw_frames.append({'title': title, 'path': path, 'image': thumbnail}) + self.image_manager.add_image(thumbnail, ImageSource.ImagePlugin, self.image_border) self.image_manager.add_image(path, ImageSource.ImagePlugin, self.image_border) self._new_item() diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 82bf55477..d5892c250 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -590,7 +590,7 @@ class ImageMediaItem(MediaManagerItem): # Continue with the existing images. for filename in images_file_names: name = os.path.split(filename)[1] - service_item.add_from_image(filename, name, background) + service_item.add_from_image(filename, name, background, os.path.join(self.service_path, name)) return True def check_group_exists(self, new_group): diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index 07f99cf1b..7d3609784 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -407,7 +407,6 @@ class HttpRouter(RegistryProperties): 'thumbnails/' + full_path)) if os.path.exists(full_path): path, just_file_name = os.path.split(full_path) - self.image_manager.add_image(full_path, just_file_name, None, width, height) ext, content_type = self.get_content_type(full_path) image = self.image_manager.get_image(full_path, just_file_name, width, height) content = image_to_byte(image, False) @@ -504,8 +503,8 @@ class HttpRouter(RegistryProperties): item['tag'] = str(index + 1) item['text'] = str(frame['text']) item['html'] = str(frame['html']) - # Handle images, unless a custom thumbnail is given or if thumbnails is disabled - elif current_item.is_image() and not frame.get('image', None) and Settings().value('remotes/thumbnails'): + # Handle images, unless a thumbnail is given or if thumbnails is disabled + elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'): item['tag'] = str(index + 1) thumbnail_path = os.path.sep + os.path.join('images', 'thumbnails', frame['title']) item['img'] = urllib.request.pathname2url(thumbnail_path)