Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fsleyes
fsleyes-props
Commits
a811c494
Commit
a811c494
authored
Mar 27, 2021
by
Paul McCarthy
🚵
Browse files
Merge branch 'enh/colour' into 'master'
Enh/colour See merge request fsl/fsleyes/props!45
parents
a21cccdd
cb8820ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.rst
View file @
a811c494
...
...
@@ -2,6 +2,21 @@ This document contains the ``fsleyes-props`` release history in reverse
chronological order.
1.7.2 (Saturday March 26th 2021)
--------------------------------
Changed
^^^^^^^
* The :class:`.Color` property type now accepts any value that is accepted by
the `matplotlib.to_rgba
<https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.to_rgba.html>`_
function.
* Properties of type The :class:`.Int` and :class:`.Real` can be set to
``None`` (unless ``required=True and allowInvalid=False``).
1.7.1 (Tuesday March 9th 2021)
------------------------------
...
...
fsleyes_props/properties_types.py
View file @
a811c494
...
...
@@ -35,7 +35,8 @@ import os.path as op
from
collections
import
abc
import
numpy
as
np
import
matplotlib.colors
as
mplcolors
import
numpy
as
np
from
.
import
properties
as
props
from
.
import
properties_value
as
propvals
...
...
@@ -161,6 +162,9 @@ class Number(props.PropertyBase):
is returned unchanged.
"""
if
value
is
None
:
return
value
clamped
=
attributes
[
'clamped'
]
if
not
clamped
:
return
value
...
...
@@ -186,6 +190,8 @@ class Int(Number):
"""Overrides :meth:`Number.cast`. Casts the given value to an ``int``,
and then passes the value to :meth:`Number.cast`.
"""
if
value
is
None
:
return
value
return
Number
.
cast
(
self
,
instance
,
attributes
,
int
(
value
))
...
...
@@ -221,6 +227,8 @@ class Real(Number):
"""Overrides :meth:`Number.cast`. Casts the given value to a ``float``,
and then passes the value to :meth:`Number.cast`.
"""
if
value
is
None
:
return
value
return
Number
.
cast
(
self
,
instance
,
attributes
,
float
(
value
))
...
...
@@ -767,8 +775,8 @@ class Colour(props.PropertyBase):
"""A property which represents a RGBA colour, stored as four floating
point values in the range ``0.0 - 1.0``.
RGB colours are also accepted - if an
RGB colour is
provided, the
alpha channel is set to 1.0.
Any value which can be interpreted by matplotlib as a
RGB
(A)
colour is
accepted. If an RGB colour is provided, the
alpha channel is set to 1.0.
"""
...
...
@@ -795,14 +803,7 @@ class Colour(props.PropertyBase):
range ``(0.0 - 1.0)``.
"""
props
.
PropertyBase
.
validate
(
self
,
instance
,
attributes
,
value
)
if
(
not
isinstance
(
value
,
abc
.
Sequence
))
or
\
(
len
(
value
)
not
in
(
3
,
4
)):
raise
ValueError
(
'Colour must be a sequence of three/four values'
)
for
v
in
value
:
if
(
v
<
0.0
)
or
(
v
>
1.0
):
raise
ValueError
(
'Colour values must be between 0.0 and 1.0'
)
mplcolors
.
to_rgba
(
value
)
def
cast
(
self
,
instance
,
attributes
,
value
):
...
...
@@ -812,24 +813,8 @@ class Colour(props.PropertyBase):
If the alpha channel is not provided, it is set to the current alpha
value (which defaults to ``1.0``).
"""
pv
=
self
.
getPropVal
(
instance
)
if
pv
is
not
None
:
currentVal
=
pv
.
get
()
else
:
currentVal
=
self
.
getAttribute
(
None
,
'default'
)
value
=
[
float
(
v
)
for
v
in
value
]
if
len
(
value
)
==
3
:
value
=
value
+
[
currentVal
[
3
]]
value
=
value
[:
4
]
for
i
,
v
in
enumerate
(
value
):
if
v
<
0.0
:
value
[
i
]
=
0.0
if
v
>
1.0
:
value
[
i
]
=
1.0
return
value
if
value
is
not
None
:
return
mplcolors
.
to_rgba
(
value
)
else
:
return
value
class
ColourMap
(
props
.
PropertyBase
):
...
...
tests/test_property_number.py
View file @
a811c494
...
...
@@ -15,6 +15,7 @@ def test_Int():
class
MyObj
(
props
.
HasProperties
):
unbounded
=
props
.
Int
()
required
=
props
.
Int
(
required
=
True
,
allowInvalid
=
False
)
unbounded_default
=
props
.
Int
(
default
=
10
)
bounded
=
props
.
Int
(
minval
=
0
,
maxval
=
10
)
bounded_min
=
props
.
Int
(
minval
=
0
)
...
...
@@ -26,14 +27,17 @@ def test_Int():
obj
=
MyObj
()
# property, value, expected
assert
obj
.
unbounded_default
==
10
with
pytest
.
raises
(
ValueError
):
obj
.
unbounded
=
''
with
pytest
.
raises
(
ValueError
):
obj
.
unbounded
=
'abcde'
with
pytest
.
raises
(
TypeError
):
obj
.
unbounded
=
None
with
pytest
.
raises
(
ValueError
):
obj
.
required
=
None
obj
.
unbounded
=
None
obj
.
required
=
10
# property, value, expected
testcases
=
[
(
'unbounded'
,
'-999'
,
-
999
),
(
'unbounded'
,
'0'
,
0
),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment