← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/imageformats into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/imageformats into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)


Put the image file type filter generation code in one place, and made both the images plugin and the theme manager use it.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/imageformats/+merge/27997
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/imageformats into lp:openlp.
=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py	2010-06-19 12:01:06 +0000
+++ openlp/core/ui/amendthemeform.py	2010-06-19 18:06:24 +0000
@@ -30,6 +30,7 @@
 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 @@
         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(u'AmendThemeForm', u'All Files'))
+        filename = QtGui.QFileDialog.getOpenFileName(self,
+            translate(u'AmendThemeForm', u'Select Image'), u'', images_filter)
         if filename:
             self.ImageLineEdit.setText(filename)
             self.theme.background_filename = filename

=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py	2010-06-15 15:22:26 +0000
+++ openlp/core/utils/__init__.py	2010-06-19 18:06:24 +0000
@@ -30,17 +30,20 @@
 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,27 @@
         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.')
+        old_formats = [str(fmt).lower()
+            for fmt in QtGui.QImageReader.supportedImageFormats()]
+        new_formats = []
+        for fmt in old_formats:
+            if fmt not in new_formats:
+                new_formats.append(fmt)
+        new_formats.sort()
+        visible_formats = u'(*.%s)' % u'; *.'.join(new_formats)
+        actual_formats = u'(*.%s)' % u' *.'.join(new_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',

=== modified file 'openlp/plugins/images/lib/mediaitem.py'
--- openlp/plugins/images/lib/mediaitem.py	2010-06-19 03:43:10 +0000
+++ openlp/plugins/images/lib/mediaitem.py	2010-06-19 18:06:24 +0000
@@ -30,7 +30,7 @@
 
 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,12 @@
     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 = u''
+        #for file_format in QtGui.QImageReader.supportedImageFormats():
+        #    file_formats += u'*.%s ' % file_format
+        file_formats = get_images_filter()
+        self.OnNewFileMasks = u'%s;;%s (*.*) (*)' % (file_formats,
+            unicode(translate('ImagePlugin.MediaItem', 'All Files')))
 
     def requiredIcons(self):
         MediaManagerItem.requiredIcons(self)


Follow ups