From e418645502fa3e13995fb5f73d1961698c166afa Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Thu, 18 Feb 2016 15:28:45 -0500 Subject: [PATCH] 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])