From 3a50f6512053291acba9076dd402e7939816cc02 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Mon, 15 Feb 2016 16:58:13 -0500 Subject: [PATCH 1/7] added setColorMap method to ImageView --- pyqtgraph/imageview/ImageView.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 61193fc4..466b4bcf 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -717,4 +717,8 @@ class ImageView(QtGui.QWidget): if self.menu is None: self.buildMenu() self.menu.popup(QtGui.QCursor.pos()) + + def setColorMap(self, colormap): + """Set the color map. *colormap* is an instance of ColorMap()""" + self.ui.histogram.gradient.setColorMap(colormap) From 229fc6aec95e041e651e484c03b50766381771e3 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Mon, 15 Feb 2016 16:58:57 -0500 Subject: [PATCH 2/7] added lines setting a custom color map to the ImageView example --- examples/ImageView.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/ImageView.py b/examples/ImageView.py index 22168409..94d92a70 100644 --- a/examples/ImageView.py +++ b/examples/ImageView.py @@ -48,6 +48,12 @@ data[:,50:60,50:60] += sig ## Display the data and assign each frame a time value from 1.0 to 3.0 imv.setImage(data, xvals=np.linspace(1., 3., data.shape[0])) +## Set a custom color map +positions = [0, 0.5, 1] +colors = [(0,0,255), (0,255,255), (255,255,0)] +cm = pg.ColorMap(positions, colors) +imv.setColorMap(cm) + ## Start Qt event loop unless running in interactive mode. if __name__ == '__main__': import sys From 74fad9e29aa6a2e248290650f6ca953afdc87b2a Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Mon, 15 Feb 2016 17:17:09 -0500 Subject: [PATCH 3/7] added setPredefinedGradient function to ImageView, and added documentation to GradientEditorItem.loadPreset --- pyqtgraph/graphicsItems/GradientEditorItem.py | 3 ++- pyqtgraph/imageview/ImageView.py | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 5a7ca211..d57576c8 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -473,7 +473,8 @@ class GradientEditorItem(TickSliderItem): def loadPreset(self, name): """ - Load a predefined gradient. + Load a predefined gradient. Currently defined gradients are: 'thermal', + 'flame', 'yellowy', 'bipolar', 'spectrum', 'cyclic', 'greyclip', and 'grey'. """ ## TODO: provide image with names of defined gradients #global Gradients diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 466b4bcf..6832f316 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -721,4 +721,10 @@ class ImageView(QtGui.QWidget): def setColorMap(self, colormap): """Set the color map. *colormap* is an instance of ColorMap()""" self.ui.histogram.gradient.setColorMap(colormap) - + + def setPredefinedGradient(self, name): + """Set one of the gradients defined in :class:`GradientEditorItem ` + Currently defined gradients are: 'thermal', 'flame', 'yellowy', 'bipolar', + 'spectrum', 'cyclic', 'greyclip', and 'grey'. + """ + self.ui.histogram.gradient.loadPreset(name) From e5bd1f51a81cf93fc8247a885dcb435efde57137 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Mon, 15 Feb 2016 17:31:02 -0500 Subject: [PATCH 4/7] added note about updating docstring if Gradient list is updated --- pyqtgraph/graphicsItems/GradientEditorItem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index d57576c8..7afe466a 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -13,7 +13,7 @@ from ..python2_3 import cmp __all__ = ['TickSliderItem', 'GradientEditorItem'] - +##### If Gradients are added or removed, or gradient names are changed, please update the GradientEditorItem.loadPreset docstring. Gradients = OrderedDict([ ('thermal', {'ticks': [(0.3333, (185, 0, 0, 255)), (0.6666, (255, 220, 0, 255)), (1, (255, 255, 255, 255)), (0, (0, 0, 0, 255))], 'mode': 'rgb'}), ('flame', {'ticks': [(0.2, (7, 0, 220, 255)), (0.5, (236, 0, 134, 255)), (0.8, (246, 246, 0, 255)), (1.0, (255, 255, 255, 255)), (0.0, (0, 0, 0, 255))], 'mode': 'rgb'}), From e418645502fa3e13995fb5f73d1961698c166afa Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Thu, 18 Feb 2016 15:28:45 -0500 Subject: [PATCH 5/7] created a decorator function so we can auto-add the list of defined Gradients to docstrings --- pyqtgraph/graphicsItems/GradientEditorItem.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 7afe466a..b1824174 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -13,7 +13,6 @@ from ..python2_3 import cmp __all__ = ['TickSliderItem', 'GradientEditorItem'] -##### If Gradients are added or removed, or gradient names are changed, please update the GradientEditorItem.loadPreset docstring. Gradients = OrderedDict([ ('thermal', {'ticks': [(0.3333, (185, 0, 0, 255)), (0.6666, (255, 220, 0, 255)), (1, (255, 255, 255, 255)), (0, (0, 0, 0, 255))], 'mode': 'rgb'}), ('flame', {'ticks': [(0.2, (7, 0, 220, 255)), (0.5, (236, 0, 134, 255)), (0.8, (246, 246, 0, 255)), (1.0, (255, 255, 255, 255)), (0.0, (0, 0, 0, 255))], 'mode': 'rgb'}), @@ -25,6 +24,14 @@ Gradients = OrderedDict([ ('grey', {'ticks': [(0.0, (0, 0, 0, 255)), (1.0, (255, 255, 255, 255))], 'mode': 'rgb'}), ]) +def addGradientListToDocstring(): + ### create a decorator so that we can add construct a list of the gradients defined above in a docstring + ### Adds the list of gradients to the end of the functions docstring + def dec(fn): + fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']') + return fn + return dec + class TickSliderItem(GraphicsWidget): @@ -471,12 +478,13 @@ class GradientEditorItem(TickSliderItem): act = self.sender() self.loadPreset(act.name) + @addGradientListToDocstring() def loadPreset(self, name): """ - Load a predefined gradient. Currently defined gradients are: 'thermal', - 'flame', 'yellowy', 'bipolar', 'spectrum', 'cyclic', 'greyclip', and 'grey'. + Load a predefined gradient. Currently defined gradients are: - """ ## TODO: provide image with names of defined gradients + """## TODO: provide image with names of defined gradients + #global Gradients self.restoreState(Gradients[name]) From 240cdb1a41143615f62f4379a961401fb60c2a0b Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Thu, 18 Feb 2016 15:29:57 -0500 Subject: [PATCH 6/7] changed setPredefinedGradient docstring to reference GradientEditorItem.loadPreset --- pyqtgraph/imageview/ImageView.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 6832f316..59d1863d 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -723,8 +723,8 @@ class ImageView(QtGui.QWidget): self.ui.histogram.gradient.setColorMap(colormap) def setPredefinedGradient(self, name): - """Set one of the gradients defined in :class:`GradientEditorItem ` - Currently defined gradients are: 'thermal', 'flame', 'yellowy', 'bipolar', - 'spectrum', 'cyclic', 'greyclip', and 'grey'. + """Set one of the gradients defined in :class:`GradientEditorItem `. + For list of available gradients see :func:`GradientEditorItem.loadPreset() `. + """ self.ui.histogram.gradient.loadPreset(name) From 0e679edcf3f16958d2e95763983557e67befcf14 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Fri, 25 Mar 2016 12:36:49 -0400 Subject: [PATCH 7/7] some documentation improvements --- pyqtgraph/graphicsItems/GradientEditorItem.py | 4 +--- pyqtgraph/imageview/ImageView.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index b1824174..6ce06b61 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -25,8 +25,7 @@ Gradients = OrderedDict([ ]) def addGradientListToDocstring(): - ### create a decorator so that we can add construct a list of the gradients defined above in a docstring - ### Adds the list of gradients to the end of the functions docstring + """Decorator to add list of current pre-defined gradients to the end of a function docstring.""" def dec(fn): fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']') return fn @@ -482,7 +481,6 @@ class GradientEditorItem(TickSliderItem): def loadPreset(self, name): """ Load a predefined gradient. Currently defined gradients are: - """## TODO: provide image with names of defined gradients #global Gradients diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 59d1863d..27e64c4c 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -26,6 +26,7 @@ from ..graphicsItems.ROI import * from ..graphicsItems.LinearRegionItem import * from ..graphicsItems.InfiniteLine import * from ..graphicsItems.ViewBox import * +from ..graphicsItems.GradientEditorItem import addGradientListToDocstring from .. import ptime as ptime from .. import debug as debug from ..SignalProxy import SignalProxy @@ -719,12 +720,19 @@ class ImageView(QtGui.QWidget): self.menu.popup(QtGui.QCursor.pos()) def setColorMap(self, colormap): - """Set the color map. *colormap* is an instance of ColorMap()""" + """Set the color map. + + ============= ========================================================= + **Arguments** + colormap (A ColorMap() instance) The ColorMap to use for coloring + images. + ============= ========================================================= + """ self.ui.histogram.gradient.setColorMap(colormap) + @addGradientListToDocstring() def setPredefinedGradient(self, name): """Set one of the gradients defined in :class:`GradientEditorItem `. - For list of available gradients see :func:`GradientEditorItem.loadPreset() `. - + Currently available gradients are: """ self.ui.histogram.gradient.loadPreset(name)