diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 5d2349dbc..b4440e038 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -36,7 +36,7 @@ from openlp.core.lib import Receiver, translate from openlp.core.lib.theme import BackgroundType, BackgroundGradientType from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.ui import ThemeLayoutForm -from openlp.core.utils import get_images_filter +from openlp.core.utils import get_images_filter, is_not_image_file from themewizard import Ui_ThemeWizard log = logging.getLogger(__name__) @@ -233,8 +233,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): background_image = BackgroundType.to_string(BackgroundType.Image) if self.page(self.currentId()) == self.backgroundPage and \ self.theme.background_type == background_image and \ - (self.imageFileEdit.text().isEmpty() or - os.path.exists(self.imageFileEdit.text())): + is_not_image_file(self.imageFileEdit.text()): QtGui.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), translate('OpenLP.ThemeWizard', 'You have not selected a ' diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 664f98d8c..c5b4ad1fb 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -364,6 +364,22 @@ def get_images_filter(): visible_formats, actual_formats) return IMAGES_FILTER +def is_not_image_file(file_name): + """ + Validate that the file is an image file. + + ``file_name`` + File name to be checked. + """ + formats = [unicode(fmt) + for fmt in QtGui.QImageReader.supportedImageFormats()] + if file_name.isEmpty(): + return True + else: + file_part, file_extension = os.path.splitext(unicode(file_name)) + if file_extension[1:] in formats and os.path.exists(file_name): + return False + return True def join_url(base, *args): """