Constraint#
Superclasses: Object
- Describes a constraint between attributes of two widgets,
expressed as a linear equation.
The typical equation for a constraint is:
target.target_attr = source.source_attr × multiplier + constant
Each GtkConstraint is part of a system that will be solved by a
ConstraintLayout in order to allocate and position each
child widget or guide.
The source and target, as well as their attributes, of a GtkConstraint
instance are immutable after creation.
Constructors#
- class Constraint
- classmethod new(target: ConstraintTarget | None, target_attribute: ConstraintAttribute, relation: ConstraintRelation, source: ConstraintTarget | None, source_attribute: ConstraintAttribute, multiplier: float, constant: float, strength: int) Constraint#
Creates a new constraint representing a relation between a layout attribute on a source and a layout attribute on a target.
- Parameters:
target – the target of the constraint
target_attribute – the attribute of
targetto be setrelation – the relation equivalence between
target_attributeandsource_attributesource – the source of the constraint
source_attribute – the attribute of
sourceto be readmultiplier – a multiplication factor to be applied to
source_attributeconstant – a constant factor to be added to
source_attributestrength – the strength of the constraint
- classmethod new_constant(target: ConstraintTarget | None, target_attribute: ConstraintAttribute, relation: ConstraintRelation, constant: float, strength: int) Constraint#
Creates a new constraint representing a relation between a layout attribute on a target and a constant value.
- Parameters:
target – a the target of the constraint
target_attribute – the attribute of
targetto be setrelation – the relation equivalence between
target_attributeandconstantconstant – a constant factor to be set on
target_attributestrength – the strength of the constraint
Methods#
- class Constraint
-
- get_multiplier() float#
Retrieves the multiplication factor applied to the source attribute’s value.
- get_relation() ConstraintRelation#
The order relation between the terms of the constraint.
- get_source() ConstraintTarget | None#
Retrieves the
ConstraintTargetused as the source for the constraint.If the source is set to
NULLat creation, the constraint will use the widget using theConstraintLayoutas the source.
- get_source_attribute() ConstraintAttribute#
Retrieves the attribute of the source to be read by the constraint.
- get_target() ConstraintTarget | None#
Retrieves the
ConstraintTargetused as the target for the constraint.If the targe is set to
NULLat creation, the constraint will use the widget using theConstraintLayoutas the target.
- get_target_attribute() ConstraintAttribute#
Retrieves the attribute of the target to be set by the constraint.
- is_attached() bool#
Checks whether the constraint is attached to a
ConstraintLayout, and it is contributing to the layout.
Properties#
- class Constraint
- props.constant: float#
The constant value to be added to the
source_attribute.
- props.multiplier: float#
The multiplication factor to be applied to the
source_attribute.
- props.relation: ConstraintRelation#
The order relation between the terms of the constraint.
- props.source: ConstraintTarget#
The source of the constraint.
The constraint will set the
target_attributeproperty of the target using thesource_attributeproperty of the source.
- props.source_attribute: ConstraintAttribute#
The attribute of the
sourceread by the constraint.
- props.strength: int#
The strength of the constraint.
The strength can be expressed either using one of the symbolic values of the
ConstraintStrengthenumeration, or any positive integer value.
- props.target: ConstraintTarget#
The target of the constraint.
The constraint will set the
target_attributeproperty of the target using thesource_attributeproperty of the source widget.
- props.target_attribute: ConstraintAttribute#
The attribute of the
targetset by the constraint.