Skip to content

Defining custom properties

A custom property gives an entity a named animation target. This example adds level to a meter, then uses it to control a rectangle’s width with the standard renderer.

from manifest import AbsoluteTransition, Group, Inheritance, InheritanceInput, Rectangle, vector

class Meter(Group):
    pass

Meter.defineProp('level', 0.25)

def build(seq, frame):
    meter = Meter(frame, (40, 60))
    bar = Rectangle(meter, (0, 0), (200, 24), fill=(60, 100, 190))
    bar.props.size.inheritance = Inheritance(
        lambda size, level, scale: vector(size[0] * level, size[1]) * scale,
        InheritanceInput('self', 'size'),
        InheritanceInput('parent', 'level'),
        InheritanceInput('parent', 'scale'),
    )
    seq.show(AbsoluteTransition('level', meter, 1.0, time=1))

The bar starts 50 units wide (200 × 0.25) and ends 200 units wide. The expression reads the rectangle’s local size and the parent’s level and coordinate scale. It keeps the bar’s height constant as the level changes.

Register a class property before constructing the first instance of that class or its subclasses. Registration is process-wide. In a package, put shared declarations in the Python plugin’s register() hook. Use a constructor property when only that component needs the value.

To read the authored value, call meter.props.level(). For an immediate scheduled change, pass the uncalled target to SetProperty(meter.props.level, 0.5). For an effect that paints custom pixels, see Creating render plugins.