Permalink
Browse files

Dont calculate thumbnails after the thumbnail grid is cleared

  • Loading branch information...
1 parent f740294 commit e609a5078cab7f941c0941c825e70145ef76ef58 @ijanos committed Dec 14, 2011
Showing with 22 additions and 4 deletions.
  1. +10 −0 widgets/thumbnailer.py
  2. +12 −4 widgets/thumbnails.py
View
@@ -12,18 +12,28 @@ class Thumbnailmaker(QRunnable):
"""
def __init__(self, filename, width, height, parent=None):
QRunnable.__init__(self)
+
+ self.dontrun = False
+
self.filename = filename
self._w = width
self._h = height
# Need a QObject to emit signals from a QRunnable
self.obj = QObject()
+ def dontRun(self):
+ self.dontrun = True
+
def run(self):
"""
Method run by the worker thread, responsible for downscaling
one image to thumbnail size
"""
+
+ if self.dontrun: # dont run the image resize if the image is not needed
+ return
+
# Use two way scaling of the image.
# The result will be calculated faster than a one-way
# SmoothTransformation but will be as nice.
View
@@ -20,14 +20,15 @@ class ThumbnailCache():
class Thumbnail(QtCore.QObject):
def __init__(self, imagepath, parent):
QtCore.QObject .__init__(self, parent=parent)
+ self.parent = parent
self.path = imagepath
self._thread = None
self.qimg = None
self.pool = QtCore.QThreadPool.globalInstance()
- self._qlistview = parent
+ self._qlistview = parent._view
self._index = None
def calcThumbnail(self, index, w, h):
@@ -39,6 +40,7 @@ def calcThumbnail(self, index, w, h):
thread = Thumbnailmaker(self.path, w, h)
self.connect(thread.obj, QtCore.SIGNAL("imageDone"), self.imageDone)
+ self.connect(self.parent, QtCore.SIGNAL("stopCalculations"), thread.dontRun)
#Hold onto a reference to prevent PyQt from dereferencing
self._thread = thread
@@ -193,11 +195,13 @@ class Thumbnails(QtGui.QWidget):
"""
This widget can display a list of images in a thumbnail grid
- has two slots:
+ slots:
addImages: takes a list of strings, paths to images
clearWidget: remove the thumbnals, show empty the widget
- emits no signals
+ signals:
+ stopCalculations: notifies child widgets that the canvas is cleared,
+ and do not run any more image resize functions
"""
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
@@ -223,12 +227,16 @@ def __init__(self, parent=None):
self.setLayout(layout)
def addImages(self, imagelist):
+ self.emit(QtCore.SIGNAL('stopCalculations'))
+
logging.debug("Adding images to thumbview: %s", imagelist)
m = ThumbnailsModel(
- [Thumbnail(i, parent=self._view) for i in imagelist])
+ [Thumbnail(i, parent=self) for i in imagelist])
self._view.setModel(m)
def clearWidget(self):
+ self.emit(QtCore.SIGNAL('stopCalculations'))
+
m = ThumbnailsModel([])
self._view.setModel(m)

0 comments on commit e609a50

Please sign in to comment.