DynamicProperty(doc, func, prop, **kwargs)¶
DynamicProperties are GettableProperties calculated dynamically
These allow for a similar behavior to
@propertywith additional documentation and validation built in. DynamicProperties are not saved to the HasProperties instance (and therefore are not serialized), do not fire change notifications, and don’t allow default values.
These are created by decorating a single-argument method with a Property instance. This method is registered as the DynamicProperty getter. Setters and deleters may also be registered.
import properties class SpatialInfo(properties.HasProperties): x = properties.Float('x-location') y = properties.Float('y-location') z = properties.Float('z-location') @properties.Vector3('my dynamic vector') def location(self): return [self.x, self.y, self.z] @location.setter def location(self, value): self.x, self.y, self.z = value @location.deleter def location(self): del self.x, self.y, self.z
DynamicProperties should not be directly instantiated; they should be constructed with the above decorator method.
Since DynamicProperties have no saved state, the decorating Property is not allowed to have a
defaultvalue. Also, the
requiredattribute will be ignored.
When implementing a DynamicProperty getter, care should be taken around when other properties do not yet have a value. In the example above, if
locationvector will be invalid, so calling
self.locationwill fail. However, if the getter method returns
Noneit will be treated as
properties.undefinedand pass validation.
Register a delete function for the DynamicProperty
This function may only take one argument, self.
Register a set function for the DynamicProperty
This function must take two arguments, self and the new value. Input value to the function is validated with prop validation prior to execution.