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
2cd9f5ca
Commit
2cd9f5ca
authored
Mar 26, 2021
by
Paul McCarthy
🚵
Browse files
ENH: Colour properties accept any colour value that matplotlib accepts
parent
a21cccdd
Changes
1
Show whitespace changes
Inline
Side-by-side
fsleyes_props/properties_types.py
View file @
2cd9f5ca
...
@@ -35,6 +35,7 @@ import os.path as op
...
@@ -35,6 +35,7 @@ import os.path as op
from
collections
import
abc
from
collections
import
abc
import
matplotlib.colors
as
mplcolors
import
numpy
as
np
import
numpy
as
np
from
.
import
properties
as
props
from
.
import
properties
as
props
...
@@ -767,8 +768,8 @@ class Colour(props.PropertyBase):
...
@@ -767,8 +768,8 @@ class Colour(props.PropertyBase):
"""A property which represents a RGBA colour, stored as four floating
"""A property which represents a RGBA colour, stored as four floating
point values in the range ``0.0 - 1.0``.
point values in the range ``0.0 - 1.0``.
RGB colours are also accepted - if an
RGB colour is
provided, the
Any value which can be interpreted by matplotlib as a
RGB
(A)
colour is
alpha channel is set to 1.0.
accepted. If an RGB colour is provided, the
alpha channel is set to 1.0.
"""
"""
...
@@ -795,14 +796,7 @@ class Colour(props.PropertyBase):
...
@@ -795,14 +796,7 @@ class Colour(props.PropertyBase):
range ``(0.0 - 1.0)``.
range ``(0.0 - 1.0)``.
"""
"""
props
.
PropertyBase
.
validate
(
self
,
instance
,
attributes
,
value
)
props
.
PropertyBase
.
validate
(
self
,
instance
,
attributes
,
value
)
mplcolors
.
to_rgba
(
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'
)
def
cast
(
self
,
instance
,
attributes
,
value
):
def
cast
(
self
,
instance
,
attributes
,
value
):
...
@@ -812,24 +806,8 @@ class Colour(props.PropertyBase):
...
@@ -812,24 +806,8 @@ class Colour(props.PropertyBase):
If the alpha channel is not provided, it is set to the current alpha
If the alpha channel is not provided, it is set to the current alpha
value (which defaults to ``1.0``).
value (which defaults to ``1.0``).
"""
"""
if
value
is
not
None
:
return
mplcolors
.
to_rgba
(
value
)
pv
=
self
.
getPropVal
(
instance
)
else
:
return
value
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
class
ColourMap
(
props
.
PropertyBase
):
class
ColourMap
(
props
.
PropertyBase
):
...
...
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