From fb098e9cdc0cdf75bdcb4c01874b05c2f6503151 Mon Sep 17 00:00:00 2001 From: "ALLENINST\\stephanies" Date: Wed, 6 Mar 2019 12:42:22 -0800 Subject: [PATCH 1/4] add option to set other field variables in ColorMapWidget --- pyqtgraph/widgets/ColorMapWidget.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index 7e6bfab7..8939d632 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -90,6 +90,10 @@ class ColorMapParameter(ptree.types.GroupParameter): values List of unique values for which the user may assign a color when mode=='enum'. Optionally may specify a dict instead {value: name}. + colormap assign a colormap to the field + min/max assign a min/max to the field, default is 0, 1 + operation assign operation for merging multiple maps from ['Overlay', + 'Add', 'Multiply', 'Set'], default is 'Overlay' ============== ============================================================ """ self.fields = OrderedDict(fields) @@ -169,12 +173,12 @@ class RangeColorMapItem(ptree.types.SimpleParameter): self.fieldName = name units = opts.get('units', '') ptree.types.SimpleParameter.__init__(self, - name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True, + name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True, value=opts.get('colormap', None), children=[ #dict(name="Field", type='list', value=name, values=fields), - dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True), - dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True), - dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), + dict(name='Min', type='float', value=opts.get('min', 0.0), suffix=units, siPrefix=True), + dict(name='Max', type='float', value=opts.get('max', 1.0), suffix=units, siPrefix=True), + dict(name='Operation', type='list', value=opts.get('operation', 'Overlay'), values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Red', type='bool', value=True), dict(name='Green', type='bool', value=True), @@ -219,7 +223,7 @@ class EnumColorMapItem(ptree.types.GroupParameter): name=name, autoIncrementName=True, removable=True, renamable=True, children=[ dict(name='Values', type='group', children=childs), - dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), + dict(name='Operation', type='list', value=opts.get('operation', 'Overlay'), values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Red', type='bool', value=True), dict(name='Green', type='bool', value=True), From bafe1b4b7422fff6bfdde60117b95d7905def66c Mon Sep 17 00:00:00 2001 From: "ALLENINST\\stephanies" Date: Fri, 8 Mar 2019 12:00:21 -0800 Subject: [PATCH 2/4] group all defaults into one argument --- pyqtgraph/widgets/ColorMapWidget.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index 8939d632..e06f250e 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -90,10 +90,7 @@ class ColorMapParameter(ptree.types.GroupParameter): values List of unique values for which the user may assign a color when mode=='enum'. Optionally may specify a dict instead {value: name}. - colormap assign a colormap to the field - min/max assign a min/max to the field, default is 0, 1 - operation assign operation for merging multiple maps from ['Overlay', - 'Add', 'Multiply', 'Set'], default is 'Overlay' + defaults Dict of ColorMapParameter children and it's default value ============== ============================================================ """ self.fields = OrderedDict(fields) @@ -173,12 +170,12 @@ class RangeColorMapItem(ptree.types.SimpleParameter): self.fieldName = name units = opts.get('units', '') ptree.types.SimpleParameter.__init__(self, - name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True, value=opts.get('colormap', None), + name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True, children=[ #dict(name="Field", type='list', value=name, values=fields), - dict(name='Min', type='float', value=opts.get('min', 0.0), suffix=units, siPrefix=True), - dict(name='Max', type='float', value=opts.get('max', 1.0), suffix=units, siPrefix=True), - dict(name='Operation', type='list', value=opts.get('operation', 'Overlay'), values=['Overlay', 'Add', 'Multiply', 'Set']), + dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True), + dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True), + dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Red', type='bool', value=True), dict(name='Green', type='bool', value=True), @@ -188,7 +185,14 @@ class RangeColorMapItem(ptree.types.SimpleParameter): dict(name='Enabled', type='bool', value=True), dict(name='NaN', type='color'), ]) - + if 'defaults' in opts: + defaults = opts['defaults'] + for k, v in defaults.items(): + if k == 'colormap': + self.setValue(v) + else: + self[k] = v + def map(self, data): data = data[self.fieldName] @@ -223,7 +227,7 @@ class EnumColorMapItem(ptree.types.GroupParameter): name=name, autoIncrementName=True, removable=True, renamable=True, children=[ dict(name='Values', type='group', children=childs), - dict(name='Operation', type='list', value=opts.get('operation', 'Overlay'), values=['Overlay', 'Add', 'Multiply', 'Set']), + dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Red', type='bool', value=True), dict(name='Green', type='bool', value=True), From 894c9a43621f509b7252949b0908ee327d3ec035 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 8 Mar 2019 12:33:14 -0800 Subject: [PATCH 3/4] move default handling up to colormapparameter --- pyqtgraph/widgets/ColorMapWidget.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index e06f250e..b1235571 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -60,11 +60,21 @@ class ColorMapParameter(ptree.types.GroupParameter): self.sigColorMapChanged.emit(self) def addNew(self, name): - mode = self.fields[name].get('mode', 'range') + fieldSpec = self.fields[name] + + mode = fieldSpec.get('mode', 'range') if mode == 'range': item = RangeColorMapItem(name, self.fields[name]) elif mode == 'enum': item = EnumColorMapItem(name, self.fields[name]) + + defaults = fieldSpec.get('defaults', {}) + for k, v in defaults.items(): + if k == 'colormap': + item.setValue(v) + else: + item[k] = v + self.addChild(item) return item @@ -90,7 +100,7 @@ class ColorMapParameter(ptree.types.GroupParameter): values List of unique values for which the user may assign a color when mode=='enum'. Optionally may specify a dict instead {value: name}. - defaults Dict of ColorMapParameter children and it's default value + defaults Dict of ColorMapParameter children and its default value ============== ============================================================ """ self.fields = OrderedDict(fields) @@ -137,8 +147,7 @@ class ColorMapParameter(ptree.types.GroupParameter): c3[:,3:4] = colors[:,3:4] + (1-colors[:,3:4]) * a colors = c3 elif op == 'Set': - colors[mask] = colors2[mask] - + colors[mask] = colors2[mask] colors = np.clip(colors, 0, 1) if mode == 'byte': @@ -185,13 +194,6 @@ class RangeColorMapItem(ptree.types.SimpleParameter): dict(name='Enabled', type='bool', value=True), dict(name='NaN', type='color'), ]) - if 'defaults' in opts: - defaults = opts['defaults'] - for k, v in defaults.items(): - if k == 'colormap': - self.setValue(v) - else: - self[k] = v def map(self, data): data = data[self.fieldName] From 41107e4caa41737e9dfc3da6e88137b8d4045f7d Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 8 Mar 2019 12:46:10 -0800 Subject: [PATCH 4/4] expand docstring --- pyqtgraph/widgets/ColorMapWidget.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index b1235571..b5e25d94 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -100,7 +100,11 @@ class ColorMapParameter(ptree.types.GroupParameter): values List of unique values for which the user may assign a color when mode=='enum'. Optionally may specify a dict instead {value: name}. - defaults Dict of ColorMapParameter children and its default value + defaults Dict of default values to apply to color map items when + they are created. Valid keys are 'colormap' to provide + a default color map, or otherwise they a string or tuple + indicating the parameter to be set, such as 'Operation' or + ('Channels..', 'Red'). ============== ============================================================ """ self.fields = OrderedDict(fields)