Skip to content

Commit

Permalink
Delay computation of 'image_types'
Browse files Browse the repository at this point in the history
On Windows calling QImageReader.supportedImageFormats() immediately the
utils module is loaded was causing problems with image display. It's now
deferred until needed. (To be fair, the Qt documentation says "Note that
the QApplication instance must be created before this function is
called.")
  • Loading branch information
jim-easterbrook committed Oct 15, 2015
1 parent 8d74a6b commit aefc969
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/photini/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from __future__ import unicode_literals

__version__ = '15.10.0'
_dev_no = '364'
_commit = 'c0decf3'
__version__ = '15.10.0.dev365'
_dev_no = '365'
_commit = '8d74a6b'
13 changes: 8 additions & 5 deletions src/photini/imagelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class Image(QtWidgets.QFrame):
def __init__(self, path, image_list, thumb_size=80, parent=None):
QtWidgets.QFrame.__init__(self, parent)
super(Image, self).__init__(parent)
self.path = path
self.image_list = image_list
self.name = os.path.splitext(os.path.basename(self.path))[0]
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_selected(self):
class ScrollArea(QtWidgets.QScrollArea):
dropped_images = QtCore.pyqtSignal(list)
def __init__(self, parent=None):
QtWidgets.QScrollArea.__init__(self, parent)
super(ScrollArea, self).__init__(parent)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setWidgetResizable(True)
self.setAcceptDrops(True)
Expand All @@ -209,14 +209,17 @@ def dragEnterEvent(self, event):
if event.mimeData().hasFormat('text/uri-list'):
event.acceptProposedAction()


class ImageList(QtWidgets.QWidget):
image_list_changed = QtCore.pyqtSignal()
new_metadata = QtCore.pyqtSignal(bool)
selection_changed = QtCore.pyqtSignal(list)
sort_order_changed = QtCore.pyqtSignal()

def __init__(self, config_store, parent=None):
QtWidgets.QWidget.__init__(self, parent)
super(ImageList, self).__init__(parent)
self.config_store = config_store
self.image_types = ['*.' + x for x in image_types()]
self.app = QtWidgets.QApplication.instance()
self.drag_icon = None
self.path_list = list()
Expand Down Expand Up @@ -301,10 +304,10 @@ def mousePressEvent(self, event):

@QtCore.pyqtSlot()
def open_files(self):
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)))
self.tr("Images ({0});;All files (*)").format(
' '.join(self.image_types)))
if QtCore.QT_VERSION_STR.split('.')[0] == '5':
path_list = path_list[0]
if not path_list:
Expand Down
2 changes: 1 addition & 1 deletion src/photini/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class FolderSource(object):
def __init__(self, root):
self.root = root
self.image_types = ['.' + x for x in image_types]
self.image_types = ['.' + x for x in image_types()]

def list_files(self):
result = []
Expand Down
32 changes: 20 additions & 12 deletions src/photini/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@
multiple = QtWidgets.QApplication.translate('utils', '<multiple>')
multiple_values = QtWidgets.QApplication.translate('utils', '<multiple values>')

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)
_image_types = None

def image_types():
global _image_types
if _image_types:
return _image_types
_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)
return _image_types


class Busy(object):
def __enter__(self):
Expand Down

0 comments on commit aefc969

Please sign in to comment.