fsleyes_props.properties_types
Definitions for different property types.
This module provides a number of PropertyBase subclasses which
define properties of different types. These classes are intended to be
added as attributes of a HasProperties class definition.
A property which encapsulates any value.
A property which encapsulates a
boolvalue.A
Numberwhich encapsulates an integer.A
Numberwhich encapsulates a floating point number.A
Realproperty which represents a percentage.A property which encapsulates a string.
A property which may only be set to one of a set of predefined values.
A property which represents a file or directory path.
A property which represents a list of items, of another property type.
A property which represents a RGBA colour, stored as four floating point values in the range
0.0 - 1.0.A property which encapsulates a
matplotlib.colors.Colormap.A property which represents numeric bounds in any number of dimensions, as long as that number is no more than 4.
A property which represents a point in some n-dimensional (up to 4) space.
A property which represents a
numpyarray.
- class fsleyes_props.properties_types.Object(**kwargs)[source]
Bases:
PropertyBaseA property which encapsulates any value.
Create a
Objectproperty. If anequalityFuncis not provided, any writes to this property will be treated as if the value has changed (and any listeners will be notified).
- class fsleyes_props.properties_types.Boolean(**kwargs)[source]
Bases:
PropertyBaseA property which encapsulates a
boolvalue.Create a
Booleanproperty.If the
defaultkwargis not provided, a default value ofFalseis used.- cast(instance, attributes, value)[source]
Overrides
PropertyBase.cast(). Casts the given value to abool.
- class fsleyes_props.properties_types.Number(minval=None, maxval=None, clamped=False, **kwargs)[source]
Bases:
PropertyBaseBase class for the
IntandRealclasses.A property which represents a number. Don’t use/subclass this, use/subclass one of
IntorReal.Define a
Numberproperty.- Parameters:
minval – Minimum valid value
maxval – Maximum valid value
clamped – If
True, the value will be clamped to its min/max bounds.kwargs – Passed through to
PropertyBase.__init__(). If adefaultvalue is not provided, it is set to something sensible.
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate(). Validates the given number.Calls the
PropertyBase.validate()method. Then, if theminvaland/ormaxvalattributes have been set, and the given value is not within those values, aValueErroris raised.- Parameters:
instance – The owning
HasPropertiesinstance (orNonefor unbound property values).attributes – Dictionary containing property attributes.
value – The value to validate.
- cast(instance, attributes, value)[source]
Overrides
PropertyBase.cast().If the
clampedattribute isTrueand theminvaland/ormaxvalhave been set, this function ensures that the given value lies within theminvalandmaxvallimits. Otherwise the value is returned unchanged.
- class fsleyes_props.properties_types.Int(**kwargs)[source]
Bases:
NumberA
Numberwhich encapsulates an integer.Create an
Intproperty.- cast(instance, attributes, value)[source]
Overrides
Number.cast(). Casts the given value to anint, and then passes the value toNumber.cast().
- class fsleyes_props.properties_types.Real(precision=1e-09, **kwargs)[source]
Bases:
NumberA
Numberwhich encapsulates a floating point number.Define a
Realproperty.- Parameters:
precision – Tolerance for equality testing. Set to
Noneto use exact equality.
- cast(instance, attributes, value)[source]
Overrides
Number.cast(). Casts the given value to afloat, and then passes the value toNumber.cast().
- class fsleyes_props.properties_types.Percentage(**kwargs)[source]
Bases:
RealA
Realproperty which represents a percentage.A
Percentageproperty is just aRealproperty with a default minimum value of0and default maximum value of100.Create a
Percentageproperty.
- class fsleyes_props.properties_types.String(minlen=None, maxlen=None, **kwargs)[source]
Bases:
PropertyBaseA property which encapsulates a string.
Cteate a
Stringproperty.- Parameters:
minlen (int) – Minimum valid string length.
maxlen (int) – Maximum valid string length.
- cast(instance, attributes, value)[source]
Overrides
PropertyBase.cast().Casts the given value to a string. If the given value is the empty string, it is replaced with
None.
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().Passes the given value to
PropertyBase.validate(). Then, if either theminlenormaxlenattributes have been set, and the given value has length less thanminlenor greater thanmaxlen, raises aValueError.
- class fsleyes_props.properties_types.Choice(choices=None, alternates=None, allowStr=False, **kwargs)[source]
Bases:
PropertyBaseA property which may only be set to one of a set of predefined values.
Choices can be added/removed via the
addChoice(),removeChoice()method, andsetChoices()methods. Existing choices can be modified with theupdateChoice()method.Individual choices can be enabled/disabled via the
enableChoice()anddisableChoice()methods. ThechoiceEnabledattribute contains a dictionary of{choice : boolean}mappings representing the enabled/disabled state of each choice.A set of alternate values can be provided for each choice - these alternates will be accepted when assigning to a
Choiceproperty.Note
If you create a
Choiceproperty with non-string choice and alternate values, you may run into problems when usingserialiseand/orclifunctionality, unless you setallowStrtoTrue.Create a
Choiceproperty.- Parameters:
choices – List of values, the possible values that this property can take. Can alternately be a
dict- see the note above.alternates – A list of lists, specificying alternate acceptable values for each choice. Can also be a dict of
{choice : [alternates]}mappings. All alternate values must be unique - different choices cannot have equivalent alternate values.allowStr – If
True, string versions of any non-string choice values will be accepted -strversions of each choice are added as alternate values for that choice. Defaults toFalse.
- disableChoice(choice, instance=None)[source]
Disables the given choice. An attempt to set the property to a disabled value will result in a
ValueError.
- choiceEnabled(choice, instance=None)[source]
Returns
Trueif the given choice is enabled,Falseotherwise.
- getAlternates(instance=None)[source]
Returns a list of the current acceptable alternate values for each choice.
- updateChoice(choice, newChoice=None, newAlt=None, instance=None)[source]
Updates the choice value and/or alternates for the specified choice.
- setChoices(choices, alternates=None, instance=None, newChoice=None)[source]
Sets the list of possible choices (and their alternate values, if not None).
- addChoice(choice, alternate=None, instance=None)[source]
Adds a new choice to the list of possible choices.
- removeChoice(choice, instance=None)[source]
Removes the specified choice from the list of possible choices.
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().Raises a
ValueErrorif the given value is not one of the possible values for thisChoiceproperty.
- cast(instance, attributes, value)[source]
Overrides
PropertyBase.cast().Checks to see if the given value is a valid alternate value for a choice. If so, the alternate value is replaced with the choice value.
- class fsleyes_props.properties_types.FilePath(exists=False, isFile=True, suffixes=None, **kwargs)[source]
Bases:
StringA property which represents a file or directory path.
There is currently no support for validating a path which may be either a file or a directory - only one or the other.
Create a
FilePathproperty.- Parameters:
exists (bool) – If
True, the path must exist.isFile (bool) – If
True, the path must be a file. IfFalse, the path must be a directory. This check is only performed ifexistsisTrue.suffixes (list) – List of acceptable file suffixes (only relevant if
isFileisTrue).
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().If the
existsattribute is notTrue, does nothing. Otherwise, ifisFileisFalseand the given value is not a path to an existing directory, aValueErroris raised.If
isFileisTrue, and the given value is not a path to an existing file (which, ifsuffixesis not None, must end in one of the specified suffixes), aValueErroris raised.
- class fsleyes_props.properties_types.List(listType=None, minlen=None, maxlen=None, **kwargs)[source]
Bases:
ListPropertyBaseA property which represents a list of items, of another property type.
If you use
Listproperties, you really should read the documentation for thePropertyValueList, as it contains important usage information.Create a
Listproperty.- Parameters:
listType – A
PropertyBasetype, specifying the values allowed in the list. IfNone, anything can be stored in the list, but no casting or validation will occur.minlen (int) – Minimum list length.
maxlen (int) – Maximum list length.
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().Checks that the given value (which should be a list) meets the
minlen/maxlenattribute. Raises aValueErrorif it does not.
- class fsleyes_props.properties_types.Colour(**kwargs)[source]
Bases:
PropertyBaseA property which represents a RGBA colour, stored as four floating point values in the range
0.0 - 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.
Create a
Colourproperty.If the
defaultkwargis not provided, the default is set to white.
- class fsleyes_props.properties_types.ColourMap(cmaps=None, prefix=None, **kwargs)[source]
Bases:
PropertyBaseA property which encapsulates a
matplotlib.colors.Colormap.A
ColourMapproperty can take anyColormapinstance as its value. ColourMap values may be specified either as aColormapinstance, or as a string containing the name of a registered colour map instance.ColourMapproperties also maintain an internal list of colour map names; while these names do not restrict the value that aColourMapproperty can take, they are used for display purposes - a widget which is created for aColourMapinstance will only display the options returned by thegetColourMaps()method. See thewidgets._ColourMap()function.It is possible to specify a colour map name
prefixwhen creating aColourMapproperty. When a prefix is set, assignments to the property, e.g.obj.cmap = 'red'will cause a colour map named{prefix}_redto be chosen over a colour map namedred, if the former is registered with matplotlib.This prefix option was added because, for historical reasons, FSLeyes defines some colour maps with the same name as built-in matplotlib colour maps. From matplotlib ~3.5 and newer, it is not possible to override built-in colour maps, so these are registered as
fsleyes_{name}. Furthermore, matplotlib 3.8 made it impossible to give a colour map a name which is different to the key under which it is registered.Define a
ColourMapproperty.- setColourMaps(cmaps, instance=None)[source]
Set the colour maps for this property.
- Parameters:
cmaps – a list of registered colour map names.
- addColourMap(cmap, instance=None)[source]
Add a colour map to the list.
- Parameters:
cmap – The name of a registered colour map.
- getColourMaps(instance=None)[source]
Returns a list containing the names of registered colour maps available for this property.
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().Raises a
ValueErrorif the givenvalueis not a matplotlibColormapinstance.
- cast(instance, attributes, value)[source]
Overrides
PropertyBase.cast().If the provided value is a string, an attempt is made to convert it to a colour map, via the
matplotlib.colormapsregistry. The value may either be the registered colour map name, or itsColormap.nameattribute. The match is case-insensitive.
- class fsleyes_props.properties_types.BoundsValueList(*args, **kwargs)[source]
Bases:
PropertyValueListA
PropertyValueListwith values which represent bounds along a number of dimensions (up to 4).This class is used by the
Boundsproperty to encapsulate bounding values for an arbitrary number of dimensions. ForN+1dimensions, the bounding values are stored as a list:[lo0, hi0, lo1, hi1, ..., loN, hiN]
This class just adds some convenience methods and attributes to the
PropertyValueListbase class. For a single dimension, a bound object has alovalue and ahivalue, specifying the bounds along that dimension. To make things confusing, each dimension also hasminandmaxattributes, which define the minimum/maximum values that theloandhighvalues may take for that dimension.Some dynamic attributes are available on
BoundsValueListobjects, allowing access to and assignment of bound values and attributes. Dimensions0, 1, 2, 3respectively map to identifiersx, y, z, t. If an attempt is made to access/assign an attribute corresponding to a dimension which does not exist on a particularBoundsValueListinstance (e.g. attributeton a 3-dimensional list), anIndexErrorwill be raised. Here is an example of dynamic bound attribute access:class MyObj(props.HasProperties): myBounds = Bounds(ndims=4) obj = MyObj() # set/access lo/hi values together xlo, xhi = obj.mybounds.x obj.mybounds.z = (25, 30) # set/access lo/hi values separately obj.mybounds.xlo = 2 obj.mybounds.zhi = 50 # get the length of the bounds for a dimension ylen = obj.mybounds.ylen # set/access the minimum/maximum # constraints for a dimension obj.mybounds.xmin = 0 tmax = obj.mybounds.tmax
Create a
BoundsValueListinstance - seePropertyValueList.__init__().- getLo(axis=None)[source]
Return the low value for the given (0-indexed) axis. If
axisis not specified, the low bounds for all axes are returned.
- getHi(axis=None)[source]
Return the high value for the given (0-indexed) axis. If
axisis not specified, the high bounds for all axes are returned.
- setLimit(axis, limit, value)[source]
Sets the value for the specified axis and limit (0 == low, 1 == high).
- getLimit(axis, limit)[source]
Returns the value for the specified axis and limit (0 == low, 1 == high).
- class fsleyes_props.properties_types.Bounds(ndims=1, real=True, minDistance=None, clamped=True, minval=None, maxval=None, **kwargs)[source]
Bases:
ListA property which represents numeric bounds in any number of dimensions, as long as that number is no more than 4.
Boundsvalues are stored in aBoundsValueList, a list of integer or floating point values, with two values (lo, hi) for each dimension.Boundsvalues may also have bounds of their own, i.e. minimium/maximum values that the bound values can take. These bound-limits are referred to as ‘min’ and ‘max’, and can be set via theBoundsValueList.setMin()andBoundsValueList.setMax()methods. The advantage to using these methods, instead of using, for example,PropertyValue.setAttribute(), is that if you use the latter you will have to set the attributes on both the low and the high values.Create a
Boundsproperty.- Parameters:
ndims – Number of dimensions. This is (currently) not a property attribute, hence it cannot be changed.
real – If
True(the default), the bound values are stored asRealvalues; otherwise, they are stored asIntvalues.minDistance – Minimum distance to be maintained between the low/high values for each dimension.
clamped – If
True(the default), the bound values are clamped to their limits. See theNumberclass.minval – Initial minimum value to use for all dimensions
maxval – Initial maximum value to use for all dimensions
- validate(instance, attributes, value)[source]
Overrides
PropertyBase.validate().Raises a
ValueErrorif the given value (a list of min/max values) is of the wrong length or data type, or if any of the min values are greater than the corresponding max value.
- class fsleyes_props.properties_types.PointValueList(*args, **kwargs)[source]
Bases:
PropertyValueListA list of values which represent a point in some n-dimensional (up to 4) space.
This class is used by the
Pointproperty to encapsulate point values for between 1 and 4 dimensions.This class just adds some convenience methods and attributes to the
PropertyValueListbase class, in a similar manner to theBoundsValueListclass.The point values for each dimension may be queried/assigned via the dynamic attributes
x, y, z, t, which respectively map to dimensions0, 1, 2, 3. When querying/assigning point values, you may use GLSL-like swizzling. For example:class MyObj(props.HasProperties): mypoint = props.Point(ndims=3) obj = MyObj() y,z = obj.mypoint.yz obj.mypoint.zxy = (3,6,1)
Create a
PointValueList- seePropertyValueList.__init__().
- class fsleyes_props.properties_types.Point(ndims=2, real=True, **kwargs)[source]
Bases:
ListA property which represents a point in some n-dimensional (up to 4) space.
Pointproperty values are stored in aPointValueList, a list of integer or floating point values, one for each dimension.Create a
Pointproperty.
- class fsleyes_props.properties_types.ArrayProxy(*args, **kwargs)[source]
Bases:
PropertyValueA proxy class indended to encapsulate a
numpyarray.ArrayProxyinstances are used by theArrayproperty type.An
ArrayProxyis aPropertyValuewhich contains, and tries to act like, anumpyarray. Element access andassignment, and attribute access can be performed through theArrayProxy.All element assignments which occur via an
ArrayProxyinstance will result in notification of all registered listeners (see thePropertyValue.addListener()method). A limitation of this implementation is that notification will occur even if the assignment does not change the array values.The underlying
numpyarray is accessible via thegetArray()method. However, changes made directly to the numpy array will bypass thePropertyValuenotification procedure.Create an
ArrayProxy. All arguments are passed through to thePropertyValue.__init__()method.- get()[source]
Overrides
PropertyValue.get(). Returns thisArrayProxy.
- class fsleyes_props.properties_types.Array(dtype=None, shape=None, resizable=True, nullable=True, **kwargs)[source]
Bases:
PropertyBaseA property which represents a
numpyarray. Each array is encapsulated within anArrayProxyinstance.Create an
Arrayproperty.- Parameters:
dtype –
numpydata type.shape – Initial shape of the array.
resizable – Defaults to
True. IfFalse, the array size will be fixed to theshapespecified here. Different sized arrays will still be allowed, if theallowInvalidparameter toPropertyBase.__init__()is set toTrue.nullable – Defaults to
True. Allow the property to be set toNone.