forked from openlp/openlp
Moved thumbnail creation to httprouter.py
This commit is contained in:
parent
78d9da5c26
commit
31a868ca61
@ -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()
|
||||
|
||||
|
@ -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'])
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user