From bb5a1796472a3046faf4a191c6e38b15a75dfb4e Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 23 Mar 2021 11:35:06 -0700 Subject: [PATCH] Add Deprecation Warning to Hex Strings That Do Not Start With "#" in mkColor (#1644) * Add deprecation warning * Incorporate changes to docs/warning * correct input for no warnings * Update docs examples in LabelItem --- examples/customPlot.py | 2 +- examples/parametertree.py | 2 +- pyqtgraph/functions.py | 21 ++++++++++++------- pyqtgraph/graphicsItems/LabelItem.py | 2 +- .../tests/test_parametertypes.py | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/examples/customPlot.py b/examples/customPlot.py index 9a4d9f6e..ec632f73 100644 --- a/examples/customPlot.py +++ b/examples/customPlot.py @@ -42,7 +42,7 @@ class CustomTickSliderItem(pg.TickSliderItem): self.removeTick(tick) for pos in ticks: - tickItem = self.addTick(pos, movable=False, color="333333") + tickItem = self.addTick(pos, movable=False, color="#333333") self.all_ticks[pos] = tickItem self.updateRange(None, self._range) diff --git a/examples/parametertree.py b/examples/parametertree.py index 518ff3e7..6ce54918 100644 --- a/examples/parametertree.py +++ b/examples/parametertree.py @@ -69,7 +69,7 @@ params = [ {'name': 'List', 'type': 'list', 'values': [1,2,3], 'value': 2}, {'name': 'Named List', 'type': 'list', 'values': {"one": 1, "two": "twosies", "three": [3,3,3]}, 'value': 2}, {'name': 'Boolean', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"}, - {'name': 'Color', 'type': 'color', 'value': "FF0", 'tip': "This is a color button"}, + {'name': 'Color', 'type': 'color', 'value': "#FF0", 'tip': "This is a color button"}, {'name': 'Gradient', 'type': 'colormap'}, {'name': 'Subgroup', 'type': 'group', 'children': [ {'name': 'Sub-param 1', 'type': 'int', 'value': 10}, diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 5ca74a58..c327e470 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -213,7 +213,8 @@ class Color(QtGui.QColor): def mkColor(*args): """ - Convenience function for constructing QColor from a variety of argument types. Accepted arguments are: + Convenience function for constructing QColor from a variety of argument + types. Accepted arguments are: ================ ================================================ 'c' one of: r, g, b, c, m, y, k, w @@ -222,10 +223,10 @@ def mkColor(*args): float greyscale, 0.0-1.0 int see :func:`intColor() ` (int, hues) see :func:`intColor() ` - "RGB" hexadecimal strings; may begin with '#' - "RGBA" - "RRGGBB" - "RRGGBBAA" + "#RGB" hexadecimal strings prefixed with '#' + "#RGBA" previously allowed use without prefix is deprecated and + "#RRGGBB" will be removed in 0.13 + "#RRGGBBAA" QColor QColor instance; makes a copy. ================ ================================================ """ @@ -233,13 +234,19 @@ def mkColor(*args): if len(args) == 1: if isinstance(args[0], basestring): c = args[0] - if c[0] == '#': - c = c[1:] if len(c) == 1: try: return Colors[c] except KeyError: raise ValueError('No color named "%s"' % c) + if c[0] == '#': + c = c[1:] + else: + warnings.warn( + "Parsing of hex strings that do not start with '#' is" + "deprecated and support will be removed in 0.13", + DeprecationWarning, stacklevel=2 + ) if len(c) == 3: r = int(c[0]*2, 16) g = int(c[1]*2, 16) diff --git a/pyqtgraph/graphicsItems/LabelItem.py b/pyqtgraph/graphicsItems/LabelItem.py index ba8b72fe..a4ecbcbf 100644 --- a/pyqtgraph/graphicsItems/LabelItem.py +++ b/pyqtgraph/graphicsItems/LabelItem.py @@ -39,7 +39,7 @@ class LabelItem(GraphicsWidget, GraphicsWidgetAnchor): ==================== ============================== **Style Arguments:** - color (str) example: 'CCFF00' + color (str) example: '#CCFF00' size (str) example: '8pt' bold (bool) italic (bool) diff --git a/pyqtgraph/parametertree/tests/test_parametertypes.py b/pyqtgraph/parametertree/tests/test_parametertypes.py index 28b10c88..7898a533 100644 --- a/pyqtgraph/parametertree/tests/test_parametertypes.py +++ b/pyqtgraph/parametertree/tests/test_parametertypes.py @@ -46,7 +46,7 @@ def test_types(): all_objs = { 'int0': 0, 'int':7, 'float': -0.35, 'bigfloat': 1e129, 'npfloat': np.float64(5), 'npint': np.int64(5),'npinf': np.inf, 'npnan': np.nan, 'bool': True, - 'complex': 5+3j, 'str': 'xxx', 'unicode': asUnicode('µ'), + 'complex': 5+3j, 'str': '#xxx', 'unicode': asUnicode('µ'), 'list': [1,2,3], 'dict': {'1': 2}, 'color': pg.mkColor('k'), 'brush': pg.mkBrush('k'), 'pen': pg.mkPen('k'), 'none': None }