diff options
Diffstat (limited to 'silx/gui/plot/tools/profile')
-rw-r--r-- | silx/gui/plot/tools/profile/manager.py | 31 | ||||
-rw-r--r-- | silx/gui/plot/tools/profile/rois.py | 14 |
2 files changed, 30 insertions, 15 deletions
diff --git a/silx/gui/plot/tools/profile/manager.py b/silx/gui/plot/tools/profile/manager.py index 4d467f0..757b741 100644 --- a/silx/gui/plot/tools/profile/manager.py +++ b/silx/gui/plot/tools/profile/manager.py @@ -76,6 +76,17 @@ class _RunnableComputeProfile(qt.QRunnable): self._signals.moveToThread(threadPool.thread()) self._item = item self._roi = roi + self._cancelled = False + + def _lazyCancel(self): + """Cancel the runner if it is not yet started. + + The threadpool will still execute the runner, but this will process + nothing. + + This is only used with Qt<5.9 where QThreadPool.tryTake is not available. + """ + self._cancelled = True def autoDelete(self): return False @@ -106,12 +117,13 @@ class _RunnableComputeProfile(qt.QRunnable): def run(self): """Process the profile computation. """ - try: - profileData = self._roi.computeProfile(self._item) - except Exception: - _logger.error("Error while computing profile", exc_info=True) - else: - self.resultReady.emit(self._roi, profileData) + if not self._cancelled: + try: + profileData = self._roi.computeProfile(self._item) + except Exception: + _logger.error("Error while computing profile", exc_info=True) + else: + self.resultReady.emit(self._roi, profileData) self.runnerFinished.emit(self) @@ -815,8 +827,11 @@ class ProfileManager(qt.QObject): self._pendingRunners.remove(runner) continue if runner.getRoi() is profileRoi: - if threadPool.tryTake(runner): - self._pendingRunners.remove(runner) + if hasattr(threadPool, "tryTake"): + if threadPool.tryTake(runner): + self._pendingRunners.remove(runner) + else: # Support Qt<5.9 + runner._lazyCancel() item = self.getPlotItem() if item is None or not isinstance(item, profileRoi.ITEM_KIND): diff --git a/silx/gui/plot/tools/profile/rois.py b/silx/gui/plot/tools/profile/rois.py index b49679c..9e651a7 100644 --- a/silx/gui/plot/tools/profile/rois.py +++ b/silx/gui/plot/tools/profile/rois.py @@ -137,11 +137,11 @@ class _ImageProfileArea(items.Shape): if not isinstance(item, items.ImageBase): raise TypeError("Unexpected class %s" % type(item)) - if isinstance(item, items.ImageData): - currentData = item.getData(copy=False) - elif isinstance(item, items.ImageRgba): + if isinstance(item, items.ImageRgba): rgba = item.getData(copy=False) currentData = rgba[..., 0] + else: + currentData = item.getData(copy=False) roi = self.getParentRoi() origin = item.getOrigin() @@ -310,15 +310,15 @@ class _DefaultImageProfileRoiMixIn(core.ProfileRoiMixIn): method=method) return coords, profile, profileName, xLabel - if isinstance(item, items.ImageData): - currentData = item.getData(copy=False) - elif isinstance(item, items.ImageRgba): + if isinstance(item, items.ImageRgba): rgba = item.getData(copy=False) is_uint8 = rgba.dtype.type == numpy.uint8 # luminosity if is_uint8: - rgba = rgba.astype(numpy.float) + rgba = rgba.astype(numpy.float64) currentData = 0.21 * rgba[..., 0] + 0.72 * rgba[..., 1] + 0.07 * rgba[..., 2] + else: + currentData = item.getData(copy=False) yLabel = "%s" % str(method).capitalize() coords, profile, title, xLabel = createProfile2(currentData) |