Skip to content

Gtk.Constraint

class — extends GObject.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

new

@classmethod
def new(cls, target: ConstraintTarget | None, target_attribute: ConstraintAttribute | int, relation: ConstraintRelation | int, source: ConstraintTarget | None, source_attribute: ConstraintAttribute | int, 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

new_constant

@classmethod
def new_constant(cls, target: ConstraintTarget | None, target_attribute: ConstraintAttribute | int, relation: ConstraintRelation | int, 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

get_constant

def get_constant(self) -> float

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

get_multiplier

def get_multiplier(self) -> float

Retrieves the multiplication factor applied to the source attribute's value.

get_relation

def get_relation(self) -> ConstraintRelation

The order relation between the terms of the constraint.

get_source

def get_source(self) -> 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

def get_source_attribute(self) -> ConstraintAttribute

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

get_strength

def get_strength(self) -> int

Retrieves the strength of the constraint.

get_target

def get_target(self) -> 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

def get_target_attribute(self) -> ConstraintAttribute

Retrieves the attribute of the target to be set by the constraint.

is_attached

def is_attached(self) -> bool

Checks whether the constraint is attached to a ConstraintLayout, and it is contributing to the layout.

is_constant

def is_constant(self) -> bool

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

is_required

def is_required(self) -> bool

Checks whether the constraint is a required relation for solving the constraint layout.

Properties

constant

constant: float  # read/write

The constant value to be added to the Constraint.source-attribute.

multiplier

multiplier: float  # read/write

The multiplication factor to be applied to the Constraint.source-attribute.

relation

relation: ConstraintRelation | int  # read/write

The order relation between the terms of the constraint.

source

source: ConstraintTarget  # read/write

The source of the constraint.

The constraint will set the Constraint.target-attribute property of the target using the Constraint.source-attribute property of the source.

source_attribute

source_attribute: ConstraintAttribute | int  # read/write

The attribute of the Constraint.source read by the constraint.

strength

strength: int  # read/write

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.

target

target: ConstraintTarget  # read/write

The target of the constraint.

The constraint will set the Constraint.target-attribute property of the target using the Constraint.source-attribute property of the source widget.

target_attribute

target_attribute: ConstraintAttribute | int  # read/write

The attribute of the Constraint.target set by the constraint.