diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index 20664c8e0..1439e711e 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -30,6 +30,7 @@ import os.path from PyQt4 import QtCore, QtGui from openlp.core.lib import ThemeXML, translate +from openlp.core.utils import get_images_filter from amendthemedialog import Ui_AmendThemeDialog log = logging.getLogger(u'AmendThemeForm') @@ -209,8 +210,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): self.previewTheme() def onImageToolButtonClicked(self): - filename = unicode(QtGui.QFileDialog.getOpenFileName( - self, translate('AmendThemeForm', 'Open File'))) + images_filter = get_images_filter() + images_filter = '%s;;%s (*.*) (*)' % (images_filter, + translate('AmendThemeForm', 'All Files')) + filename = QtGui.QFileDialog.getOpenFileName(self, + translate('AmendThemeForm', 'Select Image'), u'', images_filter) if filename: self.ImageLineEdit.setText(filename) self.theme.background_filename = filename diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 857207896..78c16e26a 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -30,17 +30,20 @@ import os import sys import logging import urllib2 - from datetime import datetime -from PyQt4 import QtCore + +from PyQt4 import QtGui, QtCore import openlp +from openlp.core.lib import translate log = logging.getLogger(__name__) +images_filter = None class AppLocation(object): """ - Retrieve a directory based on the directory type. + The :class:`AppLocation` class is a static class which retrieves a + directory based on the directory type. """ AppDir = 1 ConfigDir = 2 @@ -176,6 +179,22 @@ def get_filesystem_encoding(): encoding = sys.getdefaultencoding() return encoding +def get_images_filter(): + """ + Returns a filter string for a file dialog containing all the supported + image formats. + """ + global images_filter + if not images_filter: + log.debug(u'Generating images filter.') + formats = [unicode(fmt) + for fmt in QtGui.QImageReader.supportedImageFormats()] + visible_formats = u'(*.%s)' % u'; *.'.join(formats) + actual_formats = u'(*.%s)' % u' *.'.join(formats) + images_filter = u'%s %s %s' % (translate('OpenLP', 'Image Files'), + visible_formats, actual_formats) + return images_filter + from languagemanager import LanguageManager __all__ = [u'AppLocation', u'check_latest_version', u'add_actions', diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 3cd498740..4c74c1b5b 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -30,7 +30,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ context_menu_action, ItemCapabilities, SettingsManager, translate -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, get_images_filter log = logging.getLogger(__name__) @@ -61,12 +61,9 @@ class ImageMediaItem(MediaManagerItem): def retranslateUi(self): self.OnNewPrompt = translate('ImagePlugin.MediaItem', 'Select Image(s)') - file_formats = u'' - for file_format in QtGui.QImageReader.supportedImageFormats(): - file_formats += u'*.%s ' % file_format - self.OnNewFileMasks = unicode( - translate('ImagePlugin.MediaItem', - 'Images (%s);; All files (*)')) % file_formats + file_formats = get_images_filter() + self.OnNewFileMasks = u'%s;;%s (*.*) (*)' % (file_formats, + unicode(translate('ImagePlugin.MediaItem', 'All Files'))) def requiredIcons(self): MediaManagerItem.requiredIcons(self)