Constraint

class Constraint(**properties: Any)

Superclasses: Object

GtkConstraint 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 target to be set

  • relation – the relation equivalence between target_attribute and source_attribute

  • source – the source of the constraint

  • source_attribute – the attribute of source to be read

  • multiplier – a multiplication factor to be applied to source_attribute

  • constant – a constant factor to be added to source_attribute

  • strength – 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 target to be set

  • relation – the relation equivalence between target_attribute and constant

  • constant – a constant factor to be set on target_attribute

  • strength – the strength of the constraint

Methods

class Constraint
get_constant() float

Retrieves the constant factor added to the source attributes’ value.

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 ConstraintTarget used as the source for the constraint.

If the source is set to NULL at creation, the constraint will use the widget using the ConstraintLayout as the source.

get_source_attribute() ConstraintAttribute

Retrieves the attribute of the source to be read by the constraint.

get_strength() int

Retrieves the strength of the constraint.

get_target() ConstraintTarget | None

Retrieves the ConstraintTarget used as the target for the constraint.

If the targe is set to NULL at creation, the constraint will use the widget using the ConstraintLayout as 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.

is_constant() bool

Checks whether the constraint describes a relation between an attribute on the target and a constant value.

is_required() bool

Checks whether the constraint is a required relation for solving the constraint 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_attribute property of the target using the source_attribute property of the source.

props.source_attribute: ConstraintAttribute

The attribute of the source read 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 ConstraintStrength enumeration, or any positive integer value.

props.target: ConstraintTarget

The target of the constraint.

The constraint will set the target_attribute property of the target using the source_attribute property of the source widget.

props.target_attribute: ConstraintAttribute

The attribute of the target set by the constraint.