Moved thumbnail creation to httprouter.py

This commit is contained in:
Tomas Groth 2014-09-23 22:45:42 +01:00
parent 78d9da5c26
commit 31a868ca61
3 changed files with 10 additions and 11 deletions

View File

@ -297,11 +297,10 @@ class ServiceItem(RegistryProperties):
if background:
self.image_border = background
self.service_item_type = ServiceItemType.Image
# 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._raw_frames.append({'title': title, 'path': path})
else:
self._raw_frames.append({'title': title, 'path': path, 'image': thumbnail})
self.image_manager.add_image(path, ImageSource.ImagePlugin, self.image_border)
self._new_item()

View File

@ -125,7 +125,7 @@ from mako.template import Template
from PyQt4 import QtCore
from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, translate
from openlp.core.lib import PluginStatus, StringContent, image_to_byte, ItemCapabilities
from openlp.core.lib import PluginStatus, StringContent, image_to_byte, ItemCapabilities, create_thumb
log = logging.getLogger(__name__)
FILE_TYPES = {
@ -508,6 +508,9 @@ class HttpRouter(RegistryProperties):
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'])
# Create thumbnail if it doesn't exists
if not os.path.exists(thumbnail_path):
create_thumb(current_item.get_frame_path(), thumbnail_path, False)
item['img'] = urllib.request.pathname2url(thumbnail_path)
item['text'] = str(frame['title'])
item['html'] = str(frame['title'])

View File

@ -111,8 +111,7 @@ class TestServiceItem(TestCase):
# GIVEN: A new service item and a mocked add icon function
image_name = 'image_1.jpg'
test_file = os.path.join(TEST_PATH, image_name)
thumb_file = os.path.normpath(os.path.join('/path/thumbnails', image_name))
frame_array = {'path': test_file, 'title': image_name, 'image': thumb_file}
frame_array = {'path': test_file, 'title': image_name}
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
@ -158,10 +157,8 @@ class TestServiceItem(TestCase):
image_name2 = 'image_2.jpg'
test_file1 = os.path.normpath(os.path.join('/home/openlp', image_name1))
test_file2 = os.path.normpath(os.path.join('/home/openlp', image_name2))
thumb_file1 = os.path.normpath(os.path.join('/path/thumbnails', image_name1))
thumb_file2 = os.path.normpath(os.path.join('/path/thumbnails', image_name2))
frame_array1 = {'path': test_file1, 'title': image_name1, 'image': thumb_file1}
frame_array2 = {'path': test_file2, 'title': image_name2, 'image': thumb_file2}
frame_array1 = {'path': test_file1, 'title': image_name1}
frame_array2 = {'path': test_file2, 'title': image_name2}
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()