From 7774a76eea757b7f84ddf4b03ba74a1ed61a6884 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Thu, 31 Oct 2013 14:46:04 +1100 Subject: [PATCH] Add plugin return values for ImageViewer The model supported is that plugins can return an overlay, some data, or both. Each plugin therefore returns an `(overlay, data)` tuple in which each element can be `None`. To allow return values, the plugin need only override the `output` method defined in the base Plugin class. See discussions here: https://groups.google.com/d/msg/scikit-image/0nkJM-WguXA/iqogBABa748J and here: https://github.com/scikit-image/scikit-image/pull/805 --- skimage/viewer/plugins/base.py | 17 +++++++++++++++++ skimage/viewer/viewers/core.py | 1 + 2 files changed, 18 insertions(+) diff --git a/skimage/viewer/plugins/base.py b/skimage/viewer/plugins/base.py index 50b7601c..1da020d0 100644 --- a/skimage/viewer/plugins/base.py +++ b/skimage/viewer/plugins/base.py @@ -235,3 +235,20 @@ class Plugin(QtGui.QDialog): """Remove artists that are connected to the image viewer.""" for a in self.artists: a.remove() + + def output(self): + """Return the plugin's representation and data. + + Parameters + ---------- + None + + Returns + ------- + overlay : array, same shape as ``self.image_viewer.image``, or None + The filtered image. + data : array, arbitrary shape and type, or None + Any data associated with the plugin. + """ + return (self.image_viewer.image, None) + diff --git a/skimage/viewer/viewers/core.py b/skimage/viewer/viewers/core.py index 8b5eb7ba..27cf7c4e 100644 --- a/skimage/viewer/viewers/core.py +++ b/skimage/viewer/viewers/core.py @@ -228,6 +228,7 @@ class ImageViewer(QtGui.QMainWindow): self._show() if main_window: utils.start_qtapp() + return [p.output() for p in self.plugins] def redraw(self): self.canvas.draw_idle()