forked from openlp/openlp
Moved thumbnail creation to httprouter.py
This commit is contained in:
parent
78d9da5c26
commit
31a868ca61
@ -297,10 +297,9 @@ class ServiceItem(RegistryProperties):
|
|||||||
if background:
|
if background:
|
||||||
self.image_border = background
|
self.image_border = background
|
||||||
self.service_item_type = ServiceItemType.Image
|
self.service_item_type = ServiceItemType.Image
|
||||||
# If no thumbnail was given we create one
|
|
||||||
if not thumbnail:
|
if not thumbnail:
|
||||||
thumbnail = os.path.join(AppLocation.get_section_data_path('images'), 'thumbnails', os.path.split(path)[1])
|
self._raw_frames.append({'title': title, 'path': path})
|
||||||
create_thumb(path, thumbnail, False)
|
else:
|
||||||
self._raw_frames.append({'title': title, 'path': path, 'image': thumbnail})
|
self._raw_frames.append({'title': title, 'path': path, 'image': thumbnail})
|
||||||
self.image_manager.add_image(path, ImageSource.ImagePlugin, self.image_border)
|
self.image_manager.add_image(path, ImageSource.ImagePlugin, self.image_border)
|
||||||
self._new_item()
|
self._new_item()
|
||||||
|
@ -125,7 +125,7 @@ from mako.template import Template
|
|||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, translate
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
FILE_TYPES = {
|
FILE_TYPES = {
|
||||||
@ -508,6 +508,9 @@ class HttpRouter(RegistryProperties):
|
|||||||
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
|
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
|
||||||
item['tag'] = str(index + 1)
|
item['tag'] = str(index + 1)
|
||||||
thumbnail_path = os.path.sep + os.path.join('images', 'thumbnails', frame['title'])
|
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['img'] = urllib.request.pathname2url(thumbnail_path)
|
||||||
item['text'] = str(frame['title'])
|
item['text'] = str(frame['title'])
|
||||||
item['html'] = 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
|
# GIVEN: A new service item and a mocked add icon function
|
||||||
image_name = 'image_1.jpg'
|
image_name = 'image_1.jpg'
|
||||||
test_file = os.path.join(TEST_PATH, image_name)
|
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}
|
||||||
frame_array = {'path': test_file, 'title': image_name, 'image': thumb_file}
|
|
||||||
|
|
||||||
service_item = ServiceItem(None)
|
service_item = ServiceItem(None)
|
||||||
service_item.add_icon = MagicMock()
|
service_item.add_icon = MagicMock()
|
||||||
@ -158,10 +157,8 @@ class TestServiceItem(TestCase):
|
|||||||
image_name2 = 'image_2.jpg'
|
image_name2 = 'image_2.jpg'
|
||||||
test_file1 = os.path.normpath(os.path.join('/home/openlp', image_name1))
|
test_file1 = os.path.normpath(os.path.join('/home/openlp', image_name1))
|
||||||
test_file2 = os.path.normpath(os.path.join('/home/openlp', image_name2))
|
test_file2 = os.path.normpath(os.path.join('/home/openlp', image_name2))
|
||||||
thumb_file1 = os.path.normpath(os.path.join('/path/thumbnails', image_name1))
|
frame_array1 = {'path': test_file1, 'title': image_name1}
|
||||||
thumb_file2 = os.path.normpath(os.path.join('/path/thumbnails', image_name2))
|
frame_array2 = {'path': test_file2, 'title': image_name2}
|
||||||
frame_array1 = {'path': test_file1, 'title': image_name1, 'image': thumb_file1}
|
|
||||||
frame_array2 = {'path': test_file2, 'title': image_name2, 'image': thumb_file2}
|
|
||||||
|
|
||||||
service_item = ServiceItem(None)
|
service_item = ServiceItem(None)
|
||||||
service_item.add_icon = MagicMock()
|
service_item.add_icon = MagicMock()
|
||||||
|
Loading…
Reference in New Issue
Block a user