make sure we have the image file for theme backgrounds

Fixes: https://launchpad.net/bugs/1197376
This commit is contained in:
Tim Bentley 2013-07-11 21:58:15 +01:00
parent 51ab25b716
commit 6062605622
2 changed files with 19 additions and 2 deletions

View File

@ -38,7 +38,7 @@ from openlp.core.lib import UiStrings, Registry, translate
from openlp.core.lib.theme import BackgroundType, BackgroundGradientType
from openlp.core.lib.ui import 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__)
@ -178,7 +178,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 not self.imageFileEdit.text():
self.theme.background_type == background_image and 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 '
'background image. Please select one before continuing.'))

View File

@ -246,6 +246,23 @@ def get_images_filter():
return IMAGES_FILTER
def is_not_image_file(file_name):
"""
Validate that the file is not an image file.
``file_name``
File name to be checked.
"""
if file_name.isEmpty():
return True
else:
formats = [fmt.lower() for fmt in QtGui.QImageReader.supportedImageFormats()]
file_part, file_extension = os.path.splitext(unicode(file_name))
if file_extension[1:].lower() in formats and os.path.exists(file_name):
return False
return True
def split_filename(path):
"""
Return a list of the parts in a given path.