From 625ef9fc00bcb464103ea0d6a4b165fd61758218 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 1 Jan 2011 22:41:28 +0100 Subject: [PATCH 1/5] fixed adding more images at once, tweaked adding images when one image is not present --- openlp/plugins/images/lib/mediaitem.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 7281bb091..3309f06aa 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -43,6 +43,7 @@ class ImageListView(BaseListWithDnD): self.PluginName = u'Images' BaseListWithDnD.__init__(self, parent) + class ImageMediaItem(MediaManagerItem): """ This is the custom media manager item for images. @@ -51,8 +52,8 @@ class ImageMediaItem(MediaManagerItem): def __init__(self, parent, plugin, icon): self.IconPath = u'images/image' - # this next is a class, not an instance of a class - it will - # be instanced by the base MediaManagerItem + # This next is a class, not an instance of a class - it will + # be instanced by the base MediaManagerItem. self.ListViewWithDnD_class = ImageListView MediaManagerItem.__init__(self, parent, self, icon) @@ -113,7 +114,7 @@ class ImageMediaItem(MediaManagerItem): u':/system/system_close.png', translate('ImagePlugin.MediaItem', 'Reset Live Background'), self.onResetClick, False) - # Add the song widget to the page layout + # Add the song widget to the page layout. self.pageLayout.addWidget(self.ImageWidget) self.resetButton.setVisible(False) @@ -171,15 +172,24 @@ class ImageMediaItem(MediaManagerItem): if os.path.exists(filename): (path, name) = os.path.split(filename) service_item.add_from_image(filename, name) - return True - else: - # File is no longer present + # We have only one image, which is no longer present. + elif len(items) == 1: QtGui.QMessageBox.critical( self, translate('ImagePlugin.MediaItem', 'Missing Image'), unicode(translate('ImagePlugin.MediaItem', - 'The Image %s no longer exists.')) % filename) + 'The image %s no longer exists.')) % filename) return False + # We have more than one item, but a file is missing. + elif QtGui.QMessageBox.question(self, + translate('ImagePlugin.MediaItem', 'Missing Image'), + unicode(translate('ImagePlugin.MediaItem', 'The image ' + '%s no longer exists. Do you want to add the other ' + 'images anyway?')) % filename, + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | + QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: + return False + return True else: return False From 2693e3dbd94f5ff1ba1e8141a86d26d1cc6ccd84 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 1 Jan 2011 22:46:00 +0100 Subject: [PATCH 2/5] removed a not needed import --- openlp/plugins/images/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 3309f06aa..b0b411798 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ context_menu_action, ItemCapabilities, SettingsManager, translate, \ - check_item_selected, Receiver + check_item_selected from openlp.core.utils import AppLocation, get_images_filter log = logging.getLogger(__name__) From def66c204a2b94de5aa9f88a677cbe323615f5a6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 1 Jan 2011 22:55:22 +0100 Subject: [PATCH 3/5] fixed wrong indent --- openlp/plugins/images/lib/mediaitem.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index b0b411798..c3b265e61 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -182,13 +182,13 @@ class ImageMediaItem(MediaManagerItem): return False # We have more than one item, but a file is missing. elif QtGui.QMessageBox.question(self, - translate('ImagePlugin.MediaItem', 'Missing Image'), - unicode(translate('ImagePlugin.MediaItem', 'The image ' - '%s no longer exists. Do you want to add the other ' - 'images anyway?')) % filename, - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: - return False + translate('ImagePlugin.MediaItem', 'Missing Image'), + unicode(translate('ImagePlugin.MediaItem', 'The image %s ' + 'no longer exists. Do you want to add the other images ' + 'anyway?')) % filename, + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | + QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: + return False return True else: return False From 8a0eeb54bb66e9d3cc9cf4a354e969e75ccae721 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 2 Jan 2011 08:57:05 +0100 Subject: [PATCH 4/5] --- openlp/plugins/images/__init__.py | 2 +- openlp/plugins/images/imageplugin.py | 2 +- openlp/plugins/images/lib/__init__.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 48 +++++++++++++++++++------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/openlp/plugins/images/__init__.py b/openlp/plugins/images/__init__.py index 6ea473c72..9939bd87e 100644 --- a/openlp/plugins/images/__init__.py +++ b/openlp/plugins/images/__init__.py @@ -26,4 +26,4 @@ """ The :mod:`images` module provides the Images plugin. The Images plugin provides the facility to display images from OpenLP. -""" \ No newline at end of file +""" diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 79b08eb8c..ea118d3ec 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -41,7 +41,7 @@ class ImagePlugin(Plugin): self.icon = build_icon(self.icon_path) def getMediaManagerItem(self): - # Create the MediaManagerItem object + # Create the MediaManagerItem object. return ImageMediaItem(self, self, self.icon) def about(self): diff --git a/openlp/plugins/images/lib/__init__.py b/openlp/plugins/images/lib/__init__.py index 6ff2a295b..6a16ecc88 100644 --- a/openlp/plugins/images/lib/__init__.py +++ b/openlp/plugins/images/lib/__init__.py @@ -24,4 +24,4 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from mediaitem import ImageMediaItem \ No newline at end of file +from mediaitem import ImageMediaItem diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index c3b265e61..f81a744d4 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -166,29 +166,51 @@ class ImageMediaItem(MediaManagerItem): service_item.add_capability(ItemCapabilities.AllowsAdditions) # force a nonexistent theme service_item.theme = -1 + existing_images = [] + missing_images = [] + text = u'' for item in items: bitem = self.listView.item(item.row()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) if os.path.exists(filename): - (path, name) = os.path.split(filename) - service_item.add_from_image(filename, name) - # We have only one image, which is no longer present. - elif len(items) == 1: - QtGui.QMessageBox.critical( - self, translate('ImagePlugin.MediaItem', - 'Missing Image'), + existing_images.append(filename) + else: + missing_images.append(filename) + text += u'\n' + filename + # We cannot continue, as all images are missing. + if len(missing_images) == len(items): + if len(missing_images) == 1: + QtGui.QMessageBox.critical(self, + translate('ImagePlugin.MediaItem', 'Missing Image'), unicode(translate('ImagePlugin.MediaItem', - 'The image %s no longer exists.')) % filename) - return False - # We have more than one item, but a file is missing. - elif QtGui.QMessageBox.question(self, - translate('ImagePlugin.MediaItem', 'Missing Image'), + 'The image %s no longer exists.')) % text) + else: + QtGui.QMessageBox.critical(self, + translate('ImagePlugin.MediaItem', 'Missing Images'), + unicode(translate('ImagePlugin.MediaItem', + 'The following images no longer exist: %s')) % text) + return False + # We still have present images. Ask what to do. + elif missing_images: + if len(missing_images) == 1 and QtGui.QMessageBox.question( + self, translate('ImagePlugin.MediaItem', 'Missing Image'), unicode(translate('ImagePlugin.MediaItem', 'The image %s ' 'no longer exists. Do you want to add the other images ' - 'anyway?')) % filename, + 'anyway?')) % text, QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: return False + elif len(missing_images) > 1 and QtGui.QMessageBox.question( + self, translate('ImagePlugin.MediaItem', 'Missing Images'), + unicode(translate('ImagePlugin.MediaItem', 'The following ' + 'images no longer exist: %s\nDo you want to add the other ' + 'images anyway?')) % text, + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | + QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: + return False + for filename in existing_images: + (path, name) = os.path.split(filename) + service_item.add_from_image(filename, name) return True else: return False From d8ef3c5947a253ddec1c304384b5ce6ac67adbfe Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 2 Jan 2011 22:34:33 +0100 Subject: [PATCH 5/5] added a check to prevent replacing the live background with an non existing image, prevent replacing with more images --- openlp/plugins/images/lib/mediaitem.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index bf702ae44..ccc432931 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -208,16 +208,21 @@ class ImageMediaItem(MediaManagerItem): self.parent.liveController.display.resetImage() def onReplaceClick(self): - # TODO: Check if image exists. if check_item_selected(self.listView, translate('ImagePlugin.MediaItem', 'You must select an image to replace the background with.')): - items = self.listView.selectedIndexes() - for item in items: - bitem = self.listView.item(item.row()) - filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) + item = self.listView.selectedIndexes()[0] + bitem = self.listView.item(item.row()) + filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) + if os.path.exists(filename): (path, name) = os.path.split(filename) self.parent.liveController.display.directImage(name, filename) + else: + QtGui.QMessageBox.critical(self, + translate('ImagePlugin.MediaItem', 'Live Background Could ' + 'Not Be Replaced'), + unicode(translate('ImagePlugin.MediaItem', + 'The image %s no longer exists.')) % filename) self.resetButton.setVisible(True) def onPreviewClick(self):