From f614e5b98acc5b88e62efa6351d6664f9e556492 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 24 Oct 2015 16:01:32 +0200 Subject: [PATCH] Add none value for colors -> tabs.indicator.system. --- CHANGELOG.asciidoc | 2 ++ qutebrowser/config/configtypes.py | 4 +++- qutebrowser/utils/utils.py | 8 ++++++++ tests/unit/config/test_configtypes.py | 2 ++ tests/unit/utils/test_utils.py | 11 +++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index dacc2a06c..f993a3f9a 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -41,6 +41,8 @@ Added * `completion -> scrollbar-padding` * `colors -> completion.scrollbar.fg` * `colors -> completion.scrollbar.bg` +- New value `none` for `colors -> tabs.indicator.system` to not display a + gradient for tab indicators. Changed ~~~~~~~ diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 594510da9..7d69fd006 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -644,12 +644,14 @@ class ColorSystem(MappingType): special = True valid_values = ValidValues(('rgb', "Interpolate in the RGB color system."), ('hsv', "Interpolate in the HSV color system."), - ('hsl', "Interpolate in the HSL color system.")) + ('hsl', "Interpolate in the HSL color system."), + ('none', "Don't show a gradient.")) MAPPING = { 'rgb': QColor.Rgb, 'hsv': QColor.Hsv, 'hsl': QColor.Hsl, + 'none': None, } diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 32542f8ef..0a2fc364a 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -164,12 +164,20 @@ def interpolate_color(start, end, percent, colorspace=QColor.Rgb): percent: Which value to get (0 - 100) colorspace: The desired interpolation color system, QColor::{Rgb,Hsv,Hsl} (from QColor::Spec enum) + If None, start is used except when percent is 100. Return: The interpolated QColor, with the same spec as the given start color. """ qtutils.ensure_valid(start) qtutils.ensure_valid(end) + + if colorspace is None: + if percent == 100: + return end + else: + return start + out = QColor() if colorspace == QColor.Rgb: a_c1, a_c2, a_c3, _alpha = start.getRgb() diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 3fd9d8138..6db89a2b2 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -844,6 +844,8 @@ class TestColorSystem: 'hsv': QColor.Hsv, 'HSL': QColor.Hsl, 'hsl': QColor.Hsl, + 'none': None, + 'None': None, '': None, } INVALID = ['RRGB', 'HSV ', ''] # '' is invalid with none_ok=False diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 052bdb2ed..22a8d59e0 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -338,6 +338,17 @@ class TestInterpolateColor: expected.setHsl(0, 30, 150) assert Color(color) == expected + @pytest.mark.parametrize('percentage, expected', [ + (0, (0, 0, 0)), + (99, (0, 0, 0)), + (100, (255, 255, 255)), + ]) + def test_interpolation_none(self, percentage, expected): + """Test an interpolation with a gradient turned off.""" + color = utils.interpolate_color(Color(0, 0, 0), Color(255, 255, 255), + percentage, None) + assert Color(color) == Color(*expected) + @pytest.mark.parametrize('seconds, out', [ (-1, '-0:01'),