From 2f69ef75d9f9ef028f96838aa1f953c0950c5280 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Tue, 22 Sep 2015 07:36:27 +0100 Subject: [PATCH] Use a single list of image file types This ensures consistency between the importer and normal image loading. See issue #15. --- src/photini/__init__.py | 6 +++--- src/photini/imagelist.py | 13 ++----------- src/photini/importer.py | 11 +++-------- src/photini/utils.py | 15 ++++++++++++++- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/photini/__init__.py b/src/photini/__init__.py index e0cd825e..cee4d72a 100644 --- a/src/photini/__init__.py +++ b/src/photini/__init__.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals -__version__ = '15.09.1.dev340' -_dev_no = '340' -_commit = 'b0a4571' +__version__ = '15.09.1.dev341' +_dev_no = '341' +_commit = '4ecc775' diff --git a/src/photini/imagelist.py b/src/photini/imagelist.py index 8dc9f3e0..be918955 100644 --- a/src/photini/imagelist.py +++ b/src/photini/imagelist.py @@ -31,7 +31,7 @@ from .flowlayout import FlowLayout from .metadata import Metadata, MetadataHandler from .pyqt import Qt, QtCore, QtGui, QtWidgets -from .utils import Busy +from .utils import Busy, image_types DRAG_MIMETYPE = 'application/x-photini-image' @@ -301,16 +301,7 @@ def mousePressEvent(self, event): @QtCore.pyqtSlot() def open_files(self): - types = [ - 'jpeg', 'jpg', 'exv', 'cr2', 'crw', 'mrw', 'tiff', 'tif', 'dng', - 'nef', 'pef', 'arw', 'rw2', 'sr2', 'srw', 'orf', 'png', 'pgf', - 'raf', 'eps', 'gif', 'psd', 'tga', 'bmp', 'jp2', 'pnm' - ] - for fmt in QtGui.QImageReader.supportedImageFormats(): - ext = fmt.data().decode('utf_8').lower() - if ext not in types: - types.append(ext) - types = map(lambda x: '*.' + x, types) + types = ['*.' + x for x in image_types] path_list = QtWidgets.QFileDialog.getOpenFileNames( self, "Open files", self.config_store.get('paths', 'images', ''), self.tr("Images ({0});;All files (*)").format(' '.join(types))) diff --git a/src/photini/importer.py b/src/photini/importer.py index d3633987..02957f7d 100644 --- a/src/photini/importer.py +++ b/src/photini/importer.py @@ -33,18 +33,13 @@ from .configstore import ConfigStore from .metadata import Metadata -from .pyqt import Qt, QtCore, QtGui, QtWidgets -from .utils import Busy +from .pyqt import Qt, QtCore, QtWidgets +from .utils import Busy, image_types class FolderSource(object): def __init__(self, root): self.root = root - self.image_types = QtGui.QImageReader.supportedImageFormats() - self.image_types = [x.data().decode('utf-8') for x in self.image_types] - self.image_types = ['.' + x.lower() for x in self.image_types] - for ext in ('.ico', '.xcf'): - while ext in self.image_types: - self.image_types.remove(ext) + self.image_types = ['.' + x for x in image_types] def list_files(self): result = [] diff --git a/src/photini/utils.py b/src/photini/utils.py index 50b5f4df..b9bb4671 100644 --- a/src/photini/utils.py +++ b/src/photini/utils.py @@ -21,13 +21,26 @@ import os -from .pyqt import Qt, QtWidgets +from .pyqt import Qt, QtGui, QtWidgets data_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', '') multiple = QtWidgets.QApplication.translate('utils', '') multiple_values = QtWidgets.QApplication.translate('utils', '') +image_types = [ + 'jpeg', 'jpg', 'exv', 'cr2', 'crw', 'mrw', 'tiff', 'tif', 'dng', + 'nef', 'pef', 'arw', 'rw2', 'sr2', 'srw', 'orf', 'png', 'pgf', + 'raf', 'eps', 'gif', 'psd', 'tga', 'bmp', 'jp2', 'pnm' + ] +for _fmt in QtGui.QImageReader.supportedImageFormats(): + _ext = _fmt.data().decode('utf_8').lower() + if _ext not in image_types: + image_types.append(_ext) +for _ext in ('ico', 'xcf'): + if _ext in image_types: + image_types.remove(_ext) + class Busy(object): def __enter__(self): QtWidgets.QApplication.setOverrideCursor(Qt.WaitCursor)