forked from openlp/openlp
Make image formats filter in a central location.
This commit is contained in:
parent
6b1255551a
commit
e615401007
@ -30,6 +30,7 @@ import os.path
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import ThemeXML, translate
|
from openlp.core.lib import ThemeXML, translate
|
||||||
|
from openlp.core.utils import get_images_filter
|
||||||
from amendthemedialog import Ui_AmendThemeDialog
|
from amendthemedialog import Ui_AmendThemeDialog
|
||||||
|
|
||||||
log = logging.getLogger(u'AmendThemeForm')
|
log = logging.getLogger(u'AmendThemeForm')
|
||||||
@ -209,8 +210,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||||||
self.previewTheme()
|
self.previewTheme()
|
||||||
|
|
||||||
def onImageToolButtonClicked(self):
|
def onImageToolButtonClicked(self):
|
||||||
filename = QtGui.QFileDialog.getOpenFileName(
|
images_filter = get_images_filter()
|
||||||
self, translate(u'AmendThemeForm', u'Open file'))
|
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:
|
if filename:
|
||||||
self.ImageLineEdit.setText(filename)
|
self.ImageLineEdit.setText(filename)
|
||||||
self.theme.background_filename = filename
|
self.theme.background_filename = filename
|
||||||
|
@ -30,17 +30,20 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from PyQt4 import QtCore
|
|
||||||
|
from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
import openlp
|
import openlp
|
||||||
|
from openlp.core.lib import translate
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
images_filter = None
|
||||||
|
|
||||||
class AppLocation(object):
|
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
|
AppDir = 1
|
||||||
ConfigDir = 2
|
ConfigDir = 2
|
||||||
@ -176,6 +179,27 @@ def get_filesystem_encoding():
|
|||||||
encoding = sys.getdefaultencoding()
|
encoding = sys.getdefaultencoding()
|
||||||
return encoding
|
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
|
from languagemanager import LanguageManager
|
||||||
|
|
||||||
__all__ = [u'AppLocation', u'check_latest_version', u'add_actions',
|
__all__ = [u'AppLocation', u'check_latest_version', u'add_actions',
|
||||||
|
@ -30,7 +30,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
||||||
context_menu_action, ItemCapabilities, SettingsManager, translate
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -61,12 +61,12 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.OnNewPrompt = translate('ImagePlugin.MediaItem',
|
self.OnNewPrompt = translate('ImagePlugin.MediaItem',
|
||||||
'Select Image(s)')
|
'Select Image(s)')
|
||||||
file_formats = u''
|
#file_formats = u''
|
||||||
for file_format in QtGui.QImageReader.supportedImageFormats():
|
#for file_format in QtGui.QImageReader.supportedImageFormats():
|
||||||
file_formats += u'*.%s ' % file_format
|
# file_formats += u'*.%s ' % file_format
|
||||||
self.OnNewFileMasks = unicode(
|
file_formats = get_images_filter()
|
||||||
translate('ImagePlugin.MediaItem',
|
self.OnNewFileMasks = u'%s;;%s (*.*) (*)' % (file_formats,
|
||||||
'Images (%s);; All files (*)')) % file_formats
|
unicode(translate('ImagePlugin.MediaItem', 'All Files')))
|
||||||
|
|
||||||
def requiredIcons(self):
|
def requiredIcons(self):
|
||||||
MediaManagerItem.requiredIcons(self)
|
MediaManagerItem.requiredIcons(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user