forked from openlp/openlp
r1766
This commit is contained in:
commit
64bc3f0f9f
@ -144,6 +144,59 @@ def image_to_byte(image):
|
|||||||
# convert to base64 encoding so does not get missed!
|
# convert to base64 encoding so does not get missed!
|
||||||
return byte_array.toBase64()
|
return byte_array.toBase64()
|
||||||
|
|
||||||
|
def create_thumb(image_path, thumb_path, return_icon=True, size=None):
|
||||||
|
"""
|
||||||
|
Create a thumbnail from the given image path and depending on
|
||||||
|
``return_icon`` it returns an icon from this thumb.
|
||||||
|
|
||||||
|
``image_path``
|
||||||
|
The image file to create the icon from.
|
||||||
|
|
||||||
|
``thumb_path``
|
||||||
|
The filename to save the thumbnail to.
|
||||||
|
|
||||||
|
``return_icon``
|
||||||
|
States if an icon should be build and returned from the thumb. Defaults
|
||||||
|
to ``True``.
|
||||||
|
|
||||||
|
``size``
|
||||||
|
Allows to state a own size to use. Defaults to ``None``, which means
|
||||||
|
that a default height of 88 is used.
|
||||||
|
"""
|
||||||
|
ext = os.path.splitext(thumb_path)[1].lower()
|
||||||
|
reader = QtGui.QImageReader(image_path)
|
||||||
|
if size is None:
|
||||||
|
ratio = float(reader.size().width()) / float(reader.size().height())
|
||||||
|
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
|
||||||
|
else:
|
||||||
|
reader.setScaledSize(size)
|
||||||
|
thumb = reader.read()
|
||||||
|
thumb.save(thumb_path, ext[1:])
|
||||||
|
if not return_icon:
|
||||||
|
return
|
||||||
|
if os.path.exists(thumb_path):
|
||||||
|
return build_icon(unicode(thumb_path))
|
||||||
|
# Fallback for files with animation support.
|
||||||
|
return build_icon(unicode(image_path))
|
||||||
|
|
||||||
|
def validate_thumb(file_path, thumb_path):
|
||||||
|
"""
|
||||||
|
Validates whether an file's thumb still exists and if is up to date.
|
||||||
|
**Note**, you must **not** call this function, before checking the
|
||||||
|
existence of the file.
|
||||||
|
|
||||||
|
``file_path``
|
||||||
|
The path to the file. The file **must** exist!
|
||||||
|
|
||||||
|
``thumb_path``
|
||||||
|
The path to the thumb.
|
||||||
|
"""
|
||||||
|
if not os.path.exists(unicode(thumb_path)):
|
||||||
|
return False
|
||||||
|
image_date = os.stat(unicode(file_path)).st_mtime
|
||||||
|
thumb_date = os.stat(unicode(thumb_path)).st_mtime
|
||||||
|
return image_date <= thumb_date
|
||||||
|
|
||||||
def resize_image(image_path, width, height, background=u'#000000'):
|
def resize_image(image_path, width, height, background=u'#000000'):
|
||||||
"""
|
"""
|
||||||
Resize an image to fit on the current screen.
|
Resize an image to fit on the current screen.
|
||||||
@ -158,7 +211,7 @@ def resize_image(image_path, width, height, background=u'#000000'):
|
|||||||
The new image height.
|
The new image height.
|
||||||
|
|
||||||
``background``
|
``background``
|
||||||
The background colour defaults to black.
|
The background colour. Defaults to black.
|
||||||
|
|
||||||
DO NOT REMOVE THE DEFAULT BACKGROUND VALUE!
|
DO NOT REMOVE THE DEFAULT BACKGROUND VALUE!
|
||||||
"""
|
"""
|
||||||
|
@ -425,44 +425,6 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
count += 1
|
count += 1
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
def validate(self, image, thumb):
|
|
||||||
"""
|
|
||||||
Validates whether an image still exists and, if it does, is the
|
|
||||||
thumbnail representation of the image up to date.
|
|
||||||
"""
|
|
||||||
if not os.path.exists(unicode(image)):
|
|
||||||
return False
|
|
||||||
if os.path.exists(thumb):
|
|
||||||
imageDate = os.stat(unicode(image)).st_mtime
|
|
||||||
thumbDate = os.stat(unicode(thumb)).st_mtime
|
|
||||||
# If image has been updated rebuild icon
|
|
||||||
if imageDate > thumbDate:
|
|
||||||
self.iconFromFile(image, thumb)
|
|
||||||
else:
|
|
||||||
self.iconFromFile(image, thumb)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def iconFromFile(self, image_path, thumb_path):
|
|
||||||
"""
|
|
||||||
Create a thumbnail icon from a given image.
|
|
||||||
|
|
||||||
``image_path``
|
|
||||||
The image file to create the icon from.
|
|
||||||
|
|
||||||
``thumb_path``
|
|
||||||
The filename to save the thumbnail to.
|
|
||||||
"""
|
|
||||||
ext = os.path.splitext(thumb_path)[1].lower()
|
|
||||||
reader = QtGui.QImageReader(image_path)
|
|
||||||
ratio = float(reader.size().width()) / float(reader.size().height())
|
|
||||||
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
|
|
||||||
thumb = reader.read()
|
|
||||||
thumb.save(thumb_path, ext[1:])
|
|
||||||
if os.path.exists(thumb_path):
|
|
||||||
return build_icon(unicode(thumb_path))
|
|
||||||
# Fallback for files with animation support.
|
|
||||||
return build_icon(unicode(image_path))
|
|
||||||
|
|
||||||
def loadList(self, list):
|
def loadList(self, list):
|
||||||
raise NotImplementedError(u'MediaManagerItem.loadList needs to be '
|
raise NotImplementedError(u'MediaManagerItem.loadList needs to be '
|
||||||
u'defined by the plugin')
|
u'defined by the plugin')
|
||||||
|
@ -660,14 +660,17 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
for item in items:
|
for item in items:
|
||||||
self.mainwindow.incrementProgressBar()
|
self.mainwindow.incrementProgressBar()
|
||||||
serviceItem = ServiceItem()
|
serviceItem = ServiceItem()
|
||||||
serviceItem.from_service = True
|
|
||||||
serviceItem.renderer = self.mainwindow.renderer
|
serviceItem.renderer = self.mainwindow.renderer
|
||||||
serviceItem.set_from_service(item, self.servicePath)
|
serviceItem.set_from_service(item, self.servicePath)
|
||||||
self.validateItem(serviceItem)
|
self.validateItem(serviceItem)
|
||||||
self.addServiceItem(serviceItem, repaint=False)
|
self.loadItem_uuid = 0
|
||||||
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
|
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
|
||||||
Receiver.send_message(u'%s_service_load' %
|
Receiver.send_message(u'%s_service_load' %
|
||||||
serviceItem.name.lower(), serviceItem)
|
serviceItem.name.lower(), serviceItem)
|
||||||
|
# if the item has been processed
|
||||||
|
if serviceItem._uuid == self.loadItem_uuid:
|
||||||
|
serviceItem.edit_id = int(self.loadItem_editId)
|
||||||
|
self.addServiceItem(serviceItem, repaint=False)
|
||||||
delete_file(p_file)
|
delete_file(p_file)
|
||||||
self.setFileName(fileName)
|
self.setFileName(fileName)
|
||||||
self.mainwindow.addRecentFile(fileName)
|
self.mainwindow.addRecentFile(fileName)
|
||||||
@ -1122,12 +1125,10 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
def serviceItemUpdate(self, message):
|
def serviceItemUpdate(self, message):
|
||||||
"""
|
"""
|
||||||
Triggered from plugins to update service items.
|
Triggered from plugins to update service items.
|
||||||
|
Save the values as they will be used as part of the service load
|
||||||
"""
|
"""
|
||||||
editId, uuid = message.split(u':')
|
editId, self.loadItem_uuid = message.split(u':')
|
||||||
for item in self.serviceItems:
|
self.loadItem_editId = int(editId)
|
||||||
if item[u'service_item']._uuid == uuid:
|
|
||||||
item[u'service_item'].edit_id = int(editId)
|
|
||||||
self.setModified()
|
|
||||||
|
|
||||||
def replaceServiceItem(self, newItem):
|
def replaceServiceItem(self, newItem):
|
||||||
"""
|
"""
|
||||||
|
@ -669,14 +669,14 @@ class SlideController(QtGui.QWidget):
|
|||||||
label.setMargin(4)
|
label.setMargin(4)
|
||||||
label.setScaledContents(True)
|
label.setScaledContents(True)
|
||||||
if self.serviceItem.is_command():
|
if self.serviceItem.is_command():
|
||||||
image = QtGui.QImage(frame[u'image'])
|
label.setPixmap(QtGui.QPixmap(frame[u'image']))
|
||||||
else:
|
else:
|
||||||
# If current slide set background to image
|
# If current slide set background to image
|
||||||
if framenumber == slideno:
|
if framenumber == slideno:
|
||||||
self.serviceItem.bg_image_bytes = \
|
self.serviceItem.bg_image_bytes = \
|
||||||
self.imageManager.get_image_bytes(frame[u'title'])
|
self.imageManager.get_image_bytes(frame[u'title'])
|
||||||
image = self.imageManager.get_image(frame[u'title'])
|
image = self.imageManager.get_image(frame[u'title'])
|
||||||
label.setPixmap(QtGui.QPixmap.fromImage(image))
|
label.setPixmap(QtGui.QPixmap.fromImage(image))
|
||||||
self.previewListWidget.setCellWidget(framenumber, 0, label)
|
self.previewListWidget.setCellWidget(framenumber, 0, label)
|
||||||
slideHeight = width * self.parent().renderer.screen_ratio
|
slideHeight = width * self.parent().renderer.screen_ratio
|
||||||
row += 1
|
row += 1
|
||||||
|
@ -36,7 +36,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, \
|
from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, \
|
||||||
Receiver, SettingsManager, translate, check_item_selected, \
|
Receiver, SettingsManager, translate, check_item_selected, \
|
||||||
check_directory_exists
|
check_directory_exists, create_thumb, validate_thumb
|
||||||
from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, \
|
from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, \
|
||||||
BackgroundGradientType
|
BackgroundGradientType
|
||||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
|
||||||
@ -359,7 +359,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
The theme to delete.
|
The theme to delete.
|
||||||
"""
|
"""
|
||||||
self.themelist.remove(theme)
|
self.themelist.remove(theme)
|
||||||
thumb = theme + u'.png'
|
thumb = u'%s.png' % theme
|
||||||
delete_file(os.path.join(self.path, thumb))
|
delete_file(os.path.join(self.path, thumb))
|
||||||
delete_file(os.path.join(self.thumbPath, thumb))
|
delete_file(os.path.join(self.thumbPath, thumb))
|
||||||
try:
|
try:
|
||||||
@ -473,15 +473,12 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
name = textName
|
name = textName
|
||||||
thumb = os.path.join(self.thumbPath, u'%s.png' % textName)
|
thumb = os.path.join(self.thumbPath, u'%s.png' % textName)
|
||||||
item_name = QtGui.QListWidgetItem(name)
|
item_name = QtGui.QListWidgetItem(name)
|
||||||
if os.path.exists(thumb):
|
if validate_thumb(theme, thumb):
|
||||||
icon = build_icon(thumb)
|
icon = build_icon(thumb)
|
||||||
else:
|
else:
|
||||||
icon = build_icon(theme)
|
icon = create_thumb(theme, thumb)
|
||||||
pixmap = icon.pixmap(QtCore.QSize(88, 50))
|
|
||||||
pixmap.save(thumb, u'png')
|
|
||||||
item_name.setIcon(icon)
|
item_name.setIcon(icon)
|
||||||
item_name.setData(QtCore.Qt.UserRole,
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName))
|
||||||
QtCore.QVariant(textName))
|
|
||||||
self.themeListWidget.addItem(item_name)
|
self.themeListWidget.addItem(item_name)
|
||||||
self.themelist.append(textName)
|
self.themelist.append(textName)
|
||||||
self._pushThemes()
|
self._pushThemes()
|
||||||
@ -658,9 +655,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
os.unlink(samplepathname)
|
os.unlink(samplepathname)
|
||||||
frame.save(samplepathname, u'png')
|
frame.save(samplepathname, u'png')
|
||||||
thumb = os.path.join(self.thumbPath, u'%s.png' % name)
|
thumb = os.path.join(self.thumbPath, u'%s.png' % name)
|
||||||
icon = build_icon(frame)
|
create_thumb(samplepathname, thumb, False)
|
||||||
pixmap = icon.pixmap(QtCore.QSize(88, 50))
|
|
||||||
pixmap.save(thumb, u'png')
|
|
||||||
log.debug(u'Theme image written to %s', samplepathname)
|
log.debug(u'Theme image written to %s', samplepathname)
|
||||||
|
|
||||||
def updatePreviewImages(self):
|
def updatePreviewImages(self):
|
||||||
|
@ -33,7 +33,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
|
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
|
||||||
SettingsManager, translate, check_item_selected, check_directory_exists, \
|
SettingsManager, translate, check_item_selected, check_directory_exists, \
|
||||||
Receiver
|
Receiver, create_thumb, validate_thumb
|
||||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
||||||
from openlp.core.utils import AppLocation, delete_file, get_images_filter
|
from openlp.core.utils import AppLocation, delete_file, get_images_filter
|
||||||
|
|
||||||
@ -127,13 +127,13 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.plugin.formparent.incrementProgressBar()
|
self.plugin.formparent.incrementProgressBar()
|
||||||
filename = os.path.split(unicode(imageFile))[1]
|
filename = os.path.split(unicode(imageFile))[1]
|
||||||
thumb = os.path.join(self.servicePath, filename)
|
thumb = os.path.join(self.servicePath, filename)
|
||||||
if os.path.exists(thumb):
|
if not os.path.exists(imageFile):
|
||||||
if self.validate(imageFile, thumb):
|
icon = build_icon(u':/general/general_delete.png')
|
||||||
|
else:
|
||||||
|
if validate_thumb(imageFile, thumb):
|
||||||
icon = build_icon(thumb)
|
icon = build_icon(thumb)
|
||||||
else:
|
else:
|
||||||
icon = build_icon(u':/general/general_delete.png')
|
icon = create_thumb(imageFile, thumb)
|
||||||
else:
|
|
||||||
icon = self.iconFromFile(imageFile, thumb)
|
|
||||||
item_name = QtGui.QListWidgetItem(filename)
|
item_name = QtGui.QListWidgetItem(filename)
|
||||||
item_name.setIcon(icon)
|
item_name.setIcon(icon)
|
||||||
item_name.setToolTip(imageFile)
|
item_name.setToolTip(imageFile)
|
||||||
|
@ -32,7 +32,8 @@ import locale
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import MediaManagerItem, build_icon, SettingsManager, \
|
from openlp.core.lib import MediaManagerItem, build_icon, SettingsManager, \
|
||||||
translate, check_item_selected, Receiver, ItemCapabilities
|
translate, check_item_selected, Receiver, ItemCapabilities, create_thumb, \
|
||||||
|
validate_thumb
|
||||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
|
||||||
media_item_combo_box
|
media_item_combo_box
|
||||||
from openlp.plugins.presentations.lib import MessageListener
|
from openlp.plugins.presentations.lib import MessageListener
|
||||||
@ -193,10 +194,13 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
doc.load_presentation()
|
doc.load_presentation()
|
||||||
preview = doc.get_thumbnail_path(1, True)
|
preview = doc.get_thumbnail_path(1, True)
|
||||||
doc.close_presentation()
|
doc.close_presentation()
|
||||||
if preview and self.validate(preview, thumb):
|
if not (preview and os.path.exists(preview)):
|
||||||
icon = build_icon(thumb)
|
|
||||||
else:
|
|
||||||
icon = build_icon(u':/general/general_delete.png')
|
icon = build_icon(u':/general/general_delete.png')
|
||||||
|
else:
|
||||||
|
if validate_thumb(preview, thumb):
|
||||||
|
icon = build_icon(thumb)
|
||||||
|
else:
|
||||||
|
icon = create_thumb(preview, thumb)
|
||||||
else:
|
else:
|
||||||
if initialLoad:
|
if initialLoad:
|
||||||
icon = build_icon(u':/general/general_delete.png')
|
icon = build_icon(u':/general/general_delete.png')
|
||||||
|
@ -31,7 +31,8 @@ import shutil
|
|||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.lib import Receiver, resize_image
|
from openlp.core.lib import Receiver, check_directory_exists, create_thumb, \
|
||||||
|
resize_image, validate_thumb
|
||||||
from openlp.core.utils import AppLocation
|
from openlp.core.utils import AppLocation
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -97,8 +98,7 @@ class PresentationDocument(object):
|
|||||||
self.slidenumber = 0
|
self.slidenumber = 0
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.filepath = name
|
self.filepath = name
|
||||||
if not os.path.isdir(self.get_thumbnail_folder()):
|
check_directory_exists(self.get_thumbnail_folder())
|
||||||
os.mkdir(self.get_thumbnail_folder())
|
|
||||||
|
|
||||||
def load_presentation(self):
|
def load_presentation(self):
|
||||||
"""
|
"""
|
||||||
@ -145,15 +145,13 @@ class PresentationDocument(object):
|
|||||||
|
|
||||||
def check_thumbnails(self):
|
def check_thumbnails(self):
|
||||||
"""
|
"""
|
||||||
Returns true if the thumbnail images look to exist and are more
|
Returns ``True`` if the thumbnail images exist and are more recent than
|
||||||
recent than the powerpoint
|
the powerpoint file.
|
||||||
"""
|
"""
|
||||||
lastimage = self.get_thumbnail_path(self.get_slide_count(), True)
|
lastimage = self.get_thumbnail_path(self.get_slide_count(), True)
|
||||||
if not (lastimage and os.path.isfile(lastimage)):
|
if not (lastimage and os.path.isfile(lastimage)):
|
||||||
return False
|
return False
|
||||||
imgdate = os.stat(lastimage).st_mtime
|
return validate_thumb(self.filepath, lastimage)
|
||||||
pptdate = os.stat(self.filepath).st_mtime
|
|
||||||
return imgdate >= pptdate
|
|
||||||
|
|
||||||
def close_presentation(self):
|
def close_presentation(self):
|
||||||
"""
|
"""
|
||||||
@ -246,8 +244,8 @@ class PresentationDocument(object):
|
|||||||
if self.check_thumbnails():
|
if self.check_thumbnails():
|
||||||
return
|
return
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
img = resize_image(file, 320, 240)
|
thumb_path = self.get_thumbnail_path(idx, False)
|
||||||
img.save(self.get_thumbnail_path(idx, False))
|
create_thumb(file, thumb_path, False, QtCore.QSize(320, 240))
|
||||||
|
|
||||||
def get_thumbnail_path(self, slide_no, check_exists):
|
def get_thumbnail_path(self, slide_no, check_exists):
|
||||||
"""
|
"""
|
||||||
@ -387,10 +385,8 @@ class PresentationController(object):
|
|||||||
AppLocation.get_section_data_path(self.settings_section),
|
AppLocation.get_section_data_path(self.settings_section),
|
||||||
u'thumbnails')
|
u'thumbnails')
|
||||||
self.thumbnail_prefix = u'slide'
|
self.thumbnail_prefix = u'slide'
|
||||||
if not os.path.isdir(self.thumbnail_folder):
|
check_directory_exists(self.thumbnail_folder)
|
||||||
os.makedirs(self.thumbnail_folder)
|
check_directory_exists(self.temp_folder)
|
||||||
if not os.path.isdir(self.temp_folder):
|
|
||||||
os.makedirs(self.temp_folder)
|
|
||||||
|
|
||||||
def enabled(self):
|
def enabled(self):
|
||||||
"""
|
"""
|
||||||
|
@ -510,7 +510,8 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
# Add the audio file to the service item.
|
# Add the audio file to the service item.
|
||||||
if len(song.media_files) > 0:
|
if len(song.media_files) > 0:
|
||||||
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
|
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
|
||||||
service_item.background_audio = [m.file_name for m in song.media_files]
|
service_item.background_audio = \
|
||||||
|
[m.file_name for m in song.media_files]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def serviceLoad(self, item):
|
def serviceLoad(self, item):
|
||||||
|
Loading…
Reference in New Issue
Block a user