Merge remote-tracking branch 'origin/pr/4220'
This commit is contained in:
commit
6c245ca7a0
@ -934,7 +934,6 @@ class QtColor(BaseType):
|
|||||||
if val.endswith('%'):
|
if val.endswith('%'):
|
||||||
val = val[:-1]
|
val = val[:-1]
|
||||||
mult = 255.0 / 100
|
mult = 255.0 / 100
|
||||||
return int(float(val) * 255.0 / 100.0)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return int(float(val) * mult)
|
return int(float(val) * mult)
|
||||||
@ -948,19 +947,21 @@ class QtColor(BaseType):
|
|||||||
elif not value:
|
elif not value:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if value.endswith(')'):
|
if '(' in value and value.endswith(')'):
|
||||||
openparen = value.index('(')
|
openparen = value.index('(')
|
||||||
kind = value[:openparen]
|
kind = value[:openparen]
|
||||||
vals = value[openparen+1:-1].split(',')
|
vals = value[openparen+1:-1].split(',')
|
||||||
vals = [self._parse_value(v) for v in vals]
|
vals = [self._parse_value(v) for v in vals]
|
||||||
if kind == 'rgba' and len(vals) == 4:
|
if kind == 'rgba' and len(vals) == 4:
|
||||||
return QColor.fromRgb(*vals)
|
return QColor.fromRgb(*vals)
|
||||||
if kind == 'rgb' and len(vals) == 3:
|
elif kind == 'rgb' and len(vals) == 3:
|
||||||
return QColor.fromRgb(*vals)
|
return QColor.fromRgb(*vals)
|
||||||
if kind == 'hsva' and len(vals) == 4:
|
elif kind == 'hsva' and len(vals) == 4:
|
||||||
return QColor.fromHsv(*vals)
|
return QColor.fromHsv(*vals)
|
||||||
if kind == 'hsv' and len(vals) == 3:
|
elif kind == 'hsv' and len(vals) == 3:
|
||||||
return QColor.fromHsv(*vals)
|
return QColor.fromHsv(*vals)
|
||||||
|
else:
|
||||||
|
raise configexc.ValidationError(value, "must be a valid color")
|
||||||
|
|
||||||
color = QColor(value)
|
color = QColor(value)
|
||||||
if color.isValid():
|
if color.isValid():
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import itertools
|
|
||||||
import warnings
|
import warnings
|
||||||
import inspect
|
import inspect
|
||||||
import functools
|
import functools
|
||||||
@ -1247,11 +1246,9 @@ class TestQtColor:
|
|||||||
# however this is consistent with Qt's CSS parser
|
# however this is consistent with Qt's CSS parser
|
||||||
# https://bugreports.qt.io/browse/QTBUG-70897
|
# https://bugreports.qt.io/browse/QTBUG-70897
|
||||||
('hsv(10%,10%,10%)', QColor.fromHsv(25, 25, 25)),
|
('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):
|
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
|
assert configtypes.QtColor().to_py(val) == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', [
|
@pytest.mark.parametrize('val', [
|
||||||
@ -1262,6 +1259,13 @@ class TestQtColor:
|
|||||||
'42',
|
'42',
|
||||||
'foo(1, 2, 3)',
|
'foo(1, 2, 3)',
|
||||||
'rgb(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):
|
def test_invalid(self, val):
|
||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
|
Loading…
Reference in New Issue
Block a user