Merge remote-tracking branch 'origin/pr/4220'

This commit is contained in:
Florian Bruhin 2018-10-04 19:34:03 +02:00
commit 6c245ca7a0
2 changed files with 14 additions and 9 deletions

View File

@ -934,7 +934,6 @@ class QtColor(BaseType):
if val.endswith('%'):
val = val[:-1]
mult = 255.0 / 100
return int(float(val) * 255.0 / 100.0)
try:
return int(float(val) * mult)
@ -948,19 +947,21 @@ class QtColor(BaseType):
elif not value:
return None
if value.endswith(')'):
if '(' in value and value.endswith(')'):
openparen = value.index('(')
kind = value[:openparen]
vals = value[openparen+1:-1].split(',')
vals = [self._parse_value(v) for v in vals]
if kind == 'rgba' and len(vals) == 4:
return QColor.fromRgb(*vals)
if kind == 'rgb' and len(vals) == 3:
elif kind == 'rgb' and len(vals) == 3:
return QColor.fromRgb(*vals)
if kind == 'hsva' and len(vals) == 4:
elif kind == 'hsva' and len(vals) == 4:
return QColor.fromHsv(*vals)
if kind == 'hsv' and len(vals) == 3:
elif kind == 'hsv' and len(vals) == 3:
return QColor.fromHsv(*vals)
else:
raise configexc.ValidationError(value, "must be a valid color")
color = QColor(value)
if color.isValid():

View File

@ -21,7 +21,6 @@
import re
import json
import math
import itertools
import warnings
import inspect
import functools
@ -1247,11 +1246,9 @@ class TestQtColor:
# however this is consistent with Qt's CSS parser
# https://bugreports.qt.io/browse/QTBUG-70897
('hsv(10%,10%,10%)', QColor.fromHsv(25, 25, 25)),
('hsva(10%,20%,30%,40%)', QColor.fromHsv(25, 51, 76, 102)),
])
def test_valid(self, val, expected):
act = configtypes.QtColor().to_py(val)
print(expected.hue(), expected.saturation(), expected.value(), expected.alpha())
print(act.hue(), act.saturation(), act.value(), act.alpha())
assert configtypes.QtColor().to_py(val) == expected
@pytest.mark.parametrize('val', [
@ -1262,6 +1259,13 @@ class TestQtColor:
'42',
'foo(1, 2, 3)',
'rgb(1, 2, 3',
'rgb)',
'rgb(1, 2, 3))',
'rgb((1, 2, 3)',
'rgb()',
'rgb(1, 2, 3, 4)',
'rgba(1, 2, 3)',
'rgb(10%%, 0, 0)',
])
def test_invalid(self, val):
with pytest.raises(configexc.ValidationError):