Commit 3ac5dadc authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

All mentions of 'constraints' replaced with 'attributes'

parent 368c5c36
......@@ -155,15 +155,15 @@ set.
The default validation logic of most ``PropertyBase`` objects can be
configured via *constraints*. For example, the :class:`.Number` property
allows ``minval`` and ``maxval`` constraints to be set. These may be set via
configured via *attributes*. For example, the :class:`.Number` property
allows ``minval`` and ``maxval`` attributes to be set. These may be set via
``PropertyBase`` constructors, (i.e. when it is defined as a class attribute
of a ``HasProperties`` definition), and may be queried and changed on
individual ``HasProperties`` instances via the
:meth:`.HasProperties.getConstraint`/:meth:`.HasProperties.setConstraint`
:meth:`.HasProperties.getAttribute`/:meth:`.HasProperties.setAttribute`
methods; similarly named methods are also available on ``PropertyBase``
instances. Some ``PropertyBase`` classes provide additional convenience
methods for accessing their constraints (e.g. :meth`.Choice.addChoice`).
methods for accessing their attributes (e.g. :meth`.Choice.addChoice`).
^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -290,7 +290,7 @@ notification of properties to be suppressed in a ``with`` statement.
"""
__version__ = '1.1.3.dev'
__version__ = '1.2.0.dev'
import sys
......
......@@ -257,7 +257,7 @@ def _Choice(parser,
will be configured to accept any value.
:arg default: If not ``None``, gives the default value. Otherwise,
the ``default`` constraint of the :class:`.Choice`
the ``default`` attribute of the :class:`.Choice`
object is used.
:arg useAlts: If ``True`` (the default), alternate values for the
......@@ -285,7 +285,7 @@ def _Choice(parser,
choices += [a for a in altList]
if default is None:
default = propObj.getConstraint(None, 'default')
default = propObj.getAttribute(None, 'default')
# Make sure that only unique
# choices are set as options.
......
......@@ -86,7 +86,7 @@ class PropertyBase(object):
equalityFunc=None,
required=False,
allowInvalid=True,
**constraints):
**atts):
"""Define a ``PropertyBase`` property.
:param default: Default/initial value.
......@@ -100,7 +100,7 @@ class PropertyBase(object):
:param validateFunc: Custom validation function. Must accept three
parameters: a reference to the ``HasProperties``
instance, the owner of this property; a
dictionary containing the constraints for this
dictionary containing the attributes for this
property; and the new property value. Should
return ``True`` if the property value is valid,
``False`` otherwise.
......@@ -114,25 +114,25 @@ class PropertyBase(object):
invalid - see caveats in the
:class:`.PropertyValue` documentation.
:param constraints: Type specific constraints used to test
:param atts: Type specific attributes used to test
validity - passed to the
:meth:`.PropertyValue.__init__` method as
its ``attributes``.
"""
constraints['default'] = default
constraints['enabled'] = constraints.get('enabled', True)
atts['default'] = default
atts['enabled'] = atts.get('enabled', True)
# A _label is added to this dict by the
# PropertyOwner metaclass for each new
# HasProperties class that is defined
self._label = {}
self._required = required
self._validateFunc = validateFunc
self._equalityFunc = equalityFunc
self._allowInvalid = allowInvalid
self._defaultConstraints = constraints
self._required = required
self._validateFunc = validateFunc
self._equalityFunc = equalityFunc
self._allowInvalid = allowInvalid
self._defaultAttributes = atts
def __copy__(self):
......@@ -149,8 +149,8 @@ class PropertyBase(object):
newProp._label = {}
# Give the new object an independent
# defaultConstraint dictionary
newProp._defaultConstraints = dict(newProp._defaultConstraints)
# defaultAttributes dictionary
newProp._defaultAttributes = dict(newProp._defaultAttributes)
return newProp
......@@ -319,7 +319,7 @@ class PropertyBase(object):
"""Creates and returns a ``PropertyValue`` object for the given
``HasProperties`` instance.
"""
default = self._defaultConstraints.get('default', None)
default = self._defaultAttributes.get('default', None)
return properties_value.PropertyValue(instance,
name=self.getLabel(instance),
value=default,
......@@ -327,7 +327,7 @@ class PropertyBase(object):
validateFunc=self.validate,
equalityFunc=self._equalityFunc,
allowInvalid=self._allowInvalid,
**self._defaultConstraints)
**self._defaultAttributes)
def validate(self, instance, attributes, value):
......@@ -360,8 +360,7 @@ class PropertyBase(object):
:param dict attributes: Attributes of the ``PropertyValue`` object,
which are used to store type-specific
constraints for ``PropertyBase``
subclasses.
attributes for ``PropertyBase`` subclasses.
:param value: The value to be validated.
"""
......@@ -469,7 +468,7 @@ class ListPropertyBase(PropertyBase):
itemValidateFunc = self._listType.validate
itemEqualityFunc = self._listType._equalityFunc
itemAllowInvalid = self._listType._allowInvalid
itemAttributes = self._listType._defaultConstraints
itemAttributes = self._listType._defaultAttributes
else:
itemCastFunc = None
itemValidateFunc = None
......@@ -477,7 +476,7 @@ class ListPropertyBase(PropertyBase):
itemAllowInvalid = True
itemAttributes = None
default = self._defaultConstraints.get('default', None)
default = self._defaultAttributes.get('default', None)
return properties_value.PropertyValueList(
instance,
......@@ -488,7 +487,7 @@ class ListPropertyBase(PropertyBase):
itemEqualityFunc=itemEqualityFunc,
listValidateFunc=self.validate,
itemAllowInvalid=itemAllowInvalid,
listAttributes=self._defaultConstraints,
listAttributes=self._defaultAttributes,
itemAttributes=itemAttributes)
......@@ -912,7 +911,7 @@ class HasProperties(six.with_metaclass(PropertyOwner, object)):
details='Use getAttribute instead')
def getConstraint(self, propName, constraint):
"""See :meth:`getAttribute`. """
return self.getProp(propName).getConstraint(self, constraint)
return self.getAttribute(propName, constraint)
@deprecation.deprecated(deprecated_in='1.2.0',
......@@ -920,7 +919,7 @@ class HasProperties(six.with_metaclass(PropertyOwner, object)):
details='Use setAttribute instead')
def setConstraint(self, propName, constraint, value):
"""See :meth:`setAttribute`. """
return self.getProp(propName).setConstraint(self, constraint, value)
return self.setAttribute(propName, constraint, value)
def getAttribute(self, propName, *args):
......
......@@ -137,7 +137,7 @@ class Number(props.PropertyBase):
:param instance: The owning :class:`.HasProperties` instance (or
``None`` for unbound property values).
:param attributes: Dictionary containing property constraints.
:param attributes: Dictionary containing property attributes.
:param value: The value to validate.
"""
......@@ -157,7 +157,7 @@ class Number(props.PropertyBase):
def cast(self, instance, attributes, value):
"""Overrides :meth:`.PropertyBase.cast`.
If the ``clamped`` constraint is ``True`` and the ``minval`` and/or
If the ``clamped`` attribute is ``True`` and the ``minval`` and/or
``maxval`` have been set, this function ensures that the given value
lies within the ``minval`` and ``maxval`` limits. Otherwise the value
is returned unchanged.
......@@ -273,7 +273,7 @@ class String(props.PropertyBase):
Passes the given value to
:meth:`.PropertyBase.validate`. Then, if either the
``minlen`` or ``maxlen`` constraints have been set, and the given
``minlen`` or ``maxlen`` attributes have been set, and the given
value has length less than ``minlen`` or greater than ``maxlen``,
raises a :exc:`ValueError`.
"""
......@@ -399,43 +399,43 @@ class Choice(props.PropertyBase):
if default not in self.getChoices(instance):
raise ValueError('{} is not a choice'.format(default))
self.setConstraint(instance, 'default', default)
self.setAttribute(instance, 'default', default)
def enableChoice(self, choice, instance=None):
"""Enables the given choice. """
choiceEnabled = dict(self.getConstraint(instance, 'choiceEnabled'))
choiceEnabled = dict(self.getAttribute(instance, 'choiceEnabled'))
choiceEnabled[choice] = True
self.setConstraint(instance, 'choiceEnabled', choiceEnabled)
self.setAttribute(instance, 'choiceEnabled', choiceEnabled)
def disableChoice(self, choice, instance=None):
"""Disables the given choice. An attempt to set the property to
a disabled value will result in a :exc:`ValueError`.
"""
choiceEnabled = dict(self.getConstraint(instance, 'choiceEnabled'))
choiceEnabled = dict(self.getAttribute(instance, 'choiceEnabled'))
choiceEnabled[choice] = False
self.setConstraint(instance, 'choiceEnabled', choiceEnabled)
self.setAttribute(instance, 'choiceEnabled', choiceEnabled)
def choiceEnabled(self, choice, instance=None):
"""Returns ``True`` if the given choice is enabled, ``False``
otherwise.
"""
return self.getConstraint(instance, 'choiceEnabled')[choice]
return self.getAttribute(instance, 'choiceEnabled')[choice]
def getChoices(self, instance=None):
"""Returns a list of the current choices. """
return list(self.getConstraint(instance, 'choices'))
return list(self.getAttribute(instance, 'choices'))
def getAlternates(self, instance=None):
"""Returns a list of the current acceptable alternate values for each
choice.
"""
choices = self.getConstraint(instance, 'choices')
altLists = self.getConstraint(instance, 'altLists')
choices = self.getAttribute(instance, 'choices')
altLists = self.getAttribute(instance, 'altLists')
return [altLists[c] for c in choices]
......@@ -448,8 +448,8 @@ class Choice(props.PropertyBase):
"""Updates the choice value and/or alternates for the specified choice.
"""
choices = list(self.getConstraint(instance, 'choices'))
altLists = dict(self.getConstraint(instance, 'altLists'))
choices = list(self.getAttribute(instance, 'choices'))
altLists = dict(self.getAttribute(instance, 'altLists'))
idx = choices.index(choice)
if newChoice is not None:
......@@ -479,7 +479,7 @@ class Choice(props.PropertyBase):
# Add stringified versions of all
# choices if allowStr is True
if self.getConstraint(instance, 'allowStr'):
if self.getAttribute(instance, 'allowStr'):
for c in choices:
strc = str(c)
alts = alternates[c]
......@@ -498,10 +498,10 @@ class Choice(props.PropertyBase):
if alternate is None: alternate = []
else: alternate = list(alternate)
choices = list(self.getConstraint(instance, 'choices'))
altLists = dict(self.getConstraint(instance, 'altLists'))
choices = list(self.getAttribute(instance, 'choices'))
altLists = dict(self.getAttribute(instance, 'altLists'))
if self.getConstraint(instance, 'allowStr'):
if self.getAttribute(instance, 'allowStr'):
strc = str(choice)
if strc not in alternate:
alternate.append(strc)
......@@ -515,8 +515,8 @@ class Choice(props.PropertyBase):
def removeChoice(self, choice, instance=None):
"""Removes the specified choice from the list of possible choices. """
choices = list(self.getConstraint(instance, 'choices'))
altLists = dict(self.getConstraint(instance, 'altLists'))
choices = list(self.getAttribute(instance, 'choices'))
altLists = dict(self.getAttribute(instance, 'altLists'))
choices .remove(choice)
altLists.pop( choice)
......@@ -553,9 +553,9 @@ class Choice(props.PropertyBase):
:param alternates: A dict of ``{choice : [alternates]}`` mappings.
"""
propVal = self.getPropVal( instance)
default = self.getConstraint(instance, 'default')
oldEnabled = self.getConstraint(instance, 'choiceEnabled')
propVal = self.getPropVal( instance)
default = self.getAttribute(instance, 'default')
oldEnabled = self.getAttribute(instance, 'choiceEnabled')
newEnabled = {}
# Prevent notification while
......@@ -577,11 +577,11 @@ class Choice(props.PropertyBase):
altLists = alternates
alternates = self.__generateAlternatesDict(altLists)
self.setConstraint(instance, 'choiceEnabled', newEnabled)
self.setConstraint(instance, 'altLists', altLists)
self.setConstraint(instance, 'alternates', alternates)
self.setConstraint(instance, 'choices', choices)
self.setConstraint(instance, 'default', default)
self.setAttribute(instance, 'choiceEnabled', newEnabled)
self.setAttribute(instance, 'altLists', altLists)
self.setAttribute(instance, 'alternates', alternates)
self.setAttribute(instance, 'choices', choices)
self.setAttribute(instance, 'default', default)
if propVal is not None:
......@@ -608,9 +608,9 @@ class Choice(props.PropertyBase):
"""
props.PropertyBase.validate(self, instance, attributes, value)
choices = self.getConstraint(instance, 'choices')
enabled = self.getConstraint(instance, 'choiceEnabled')
alternates = self.getConstraint(instance, 'alternates')
choices = self.getAttribute(instance, 'choices')
enabled = self.getAttribute(instance, 'choiceEnabled')
alternates = self.getAttribute(instance, 'alternates')
if len(choices) == 0: return
......@@ -631,7 +631,7 @@ class Choice(props.PropertyBase):
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.
"""
alternates = self.getConstraint(instance, 'alternates')
alternates = self.getAttribute(instance, 'alternates')
return alternates.get(value, value)
......@@ -667,7 +667,7 @@ class FilePath(String):
def validate(self, instance, attributes, value):
"""Overrides :meth:`.PropertyBase.validate`.
If the ``exists`` constraint is not ``True``, does nothing. Otherwise,
If the ``exists`` attribute is not ``True``, does nothing. Otherwise,
if ``isFile`` is ``False`` and the given value is not a path to an
existing directory, a :exc:`ValueError` is raised.
......@@ -748,7 +748,7 @@ class List(props.ListPropertyBase):
"""Overrides :meth:`.PropertyBase.validate`.
Checks that the given value (which should be a list) meets the
``minlen``/``maxlen`` constraints. Raises a :exc:`ValueError` if it
``minlen``/``maxlen`` attribute. Raises a :exc:`ValueError` if it
does not.
"""
......@@ -816,7 +816,7 @@ class Colour(props.PropertyBase):
pv = self.getPropVal(instance)
if pv is not None: currentVal = pv.get()
else: currentVal = self._defaultConstraints['default']
else: currentVal = self.getAttribute(None, 'default')
value = [float(v) for v in value]
......@@ -871,13 +871,13 @@ class ColourMap(props.PropertyBase):
:arg cmaps: a list of registered colour map names.
"""
default = self.getConstraint(instance, 'default')
default = self.getAttribute(instance, 'default')
if default not in cmaps:
default = cmaps[0]
self.setConstraint(instance, 'cmaps' , cmaps)
self.setConstraint(instance, 'default', default)
self.setAttribute(instance, 'cmaps' , cmaps)
self.setAttribute(instance, 'default', default)
def addColourMap(self, cmap, instance=None):
......@@ -897,7 +897,7 @@ class ColourMap(props.PropertyBase):
"""Returns a list containing the names of registered colour maps
available for this property.
"""
return list(self.getConstraint(instance, 'cmaps'))
return list(self.getAttribute(instance, 'cmaps'))
def validate(self, instance, attributes, value):
......@@ -958,12 +958,12 @@ class BoundsValueList(propvals.PropertyValueList):
``PropertyValueList`` base class. For a single dimension, a bound
object has a ``lo`` value and a ``hi`` value, specifying the bounds along
that dimension. To make things confusing, each dimension also has ``min``
and ``max`` constraints, which define the minimum/maximum values that the
and ``max`` attributes, which define the minimum/maximum values that the
``lo`` and ``high`` values may take for that dimension.
Some dynamic attributes are available on ``BoundsValueList`` objects,
allowing access to and assignment of bound values and
constraints. Dimensions ``0, 1, 2, 3`` respectively map to identifiers
attributes. Dimensions ``0, 1, 2, 3`` respectively map to identifiers
``x, y, z, t``. If an attempt is made to access/assign an attribute
corresponding to a dimension which does not exist on a particular
``BoundsValueList`` instance (e.g. attribute ``t`` on a 3-dimensional
......@@ -1200,7 +1200,7 @@ class Bounds(List):
and :meth:`BoundsValueList.setMax` methods. The advantage to using these
methods, instead of using, for example,
:meth:`.PropertyValue.setAttribute`, is that if you use the latter you will
have to set the constraints on both the low and the high values.
have to set the attributes on both the low and the high values.
"""
def __init__(self,
......@@ -1212,7 +1212,7 @@ class Bounds(List):
"""Create a ``Bounds`` property.
:arg ndims: Number of dimensions. This is (currently)
not a property constraint, hence it cannot
not a property attribute, hence it cannot
be changed.
:arg real: If ``True`` (the default), the bound values are
......@@ -1266,7 +1266,7 @@ class Bounds(List):
methods/attributes defined in the BVL class.
"""
default = self._defaultConstraints.get('default', None)
default = self.getAttribute(None, 'default', None)
bvl = BoundsValueList(
instance,
......@@ -1276,8 +1276,8 @@ class Bounds(List):
itemEqualityFunc=self._listType._equalityFunc,
itemValidateFunc=self._listType.validate,
listValidateFunc=self.validate,
listAttributes=self._defaultConstraints,
itemAttributes=self._listType._defaultConstraints)
listAttributes=self._defaultAttributes,
itemAttributes=self._listType._defaultAttributes)
return bvl
......@@ -1499,7 +1499,7 @@ class Point(List):
methods/attributes defined in the PVL class.
"""
default = self._defaultConstraints.get('default', None)
default = self.getAttribute(None, 'default', None)
pvl = PointValueList(
instance,
......@@ -1509,8 +1509,8 @@ class Point(List):
itemEqualityFunc=self._listType._equalityFunc,
itemValidateFunc=self._listType.validate,
listValidateFunc=self.validate,
listAttributes=self._defaultConstraints,
itemAttributes=self._listType._defaultConstraints)
listAttributes=self._defaultAttributes,
itemAttributes=self._listType._defaultAttributes)
return pvl
......@@ -1638,7 +1638,7 @@ class Array(props.PropertyBase):
an :class:`.ArrayProxy` for the given ``instance``.
"""
default = self._defaultConstraints.get('default', None)
default = self.getAttribute(None, 'default', None)
ap = ArrayProxy(
instance,
name=self.getLabel(instance),
......@@ -1646,7 +1646,7 @@ class Array(props.PropertyBase):
castFunc=self.cast,
validateFunc=self.validate,
allowInvalid=self._allowInvalid,
**self._defaultConstraints)
**self._defaultAttributes)
return ap
......
......@@ -177,7 +177,7 @@ class PropertyValue(object):
classes, however they are used by the
:class:`.PropertyBase` and
:class:`.ListPropertyBase` classes to store
per-instance property constraints. Listeners
per-instance property attributes. Listeners
may register to be notified when attribute
values change.
"""
......
......@@ -416,8 +416,8 @@ def _FilePath(parent, hasProps, propObj, propVal, **kwargs):
panel.SetAutoLayout(1)
sizer.Fit(panel)
exists = propObj.getConstraint(hasProps, 'exists')
isFile = propObj.getConstraint(hasProps, 'isFile')
exists = propObj.getAttribute(hasProps, 'exists')
isFile = propObj.getAttribute(hasProps, 'isFile')
def _choosePath(ev):
global _lastFilePathDir
......
......@@ -70,7 +70,7 @@ def _Bounds(parent,
ndims = propObj._ndims
real = propObj._real
clamped = propObj.getListType().getConstraint(None, 'clamped')
clamped = propObj.getListType().getAttribute(None, 'clamped')
panel = wx.Panel(parent)
sizer = wx.BoxSizer(wx.VERTICAL)
......@@ -80,7 +80,7 @@ def _Bounds(parent,
labels = [None] * 2 * ndims
for i in range(ndims):
minDistance = propObj.getConstraint(hasProps, 'minDistance')
minDistance = propObj.getAttribute(hasProps, 'minDistance')
minval = propVal.getMin(i)
maxval = propVal.getMax(i)
loval = propVal.getLo(i)
......
......@@ -96,8 +96,8 @@ def _editListDialog(parent, hasProps, propObj):
# min/max values for a spin box which allows the
# user to select the number of items in the list
minval = propObj.getConstraint(hasProps, 'minlen')
maxval = propObj.getConstraint(hasProps, 'maxlen')
minval = propObj.getAttribute(hasProps, 'minlen')
maxval = propObj.getAttribute(hasProps, 'maxlen')
if minval is None: minval = 0
if maxval is None: maxval = 2 ** 31 - 1
......@@ -154,7 +154,7 @@ def _editListDialog(parent, hasProps, propObj):
newLen = numRowsCtrl.GetValue()
# add rows
default = listType.getConstraint(hasProps, 'default')
default = listType.getAttribute(hasProps, 'default')
while oldLen < newLen:
# add a new element to the list
......
......@@ -256,7 +256,7 @@ def _makeSlider(parent,
widgets._propBind(hasProps, propObj, propVal, slider, evt)
# Update slider min/max bounds and labels
# whenever the property constraints change.
# whenever the property attributes change.
def updateSliderRange(*a):
minval = propVal.getAttribute('minval')
maxval = propVal.getAttribute('maxval')
......@@ -284,7 +284,7 @@ def _makeSlider(parent,
if editLimits:
# When the user edits the slider bounds,
# update the property constraints
# update the property attributes
def updatePropRange(ev):
propVal.setAttribute('minval', ev.min)
propVal.setAttribute('maxval', ev.max)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment