forked from openlp/openlp
Make to code more robust
This commit is contained in:
parent
98b5c6b1fd
commit
61b769a064
@ -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 '
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user