BreakpointCondition

Added in version 1.4.

class BreakpointCondition(*args, **kwargs)

Describes condition for an Breakpoint.

Constructors

class BreakpointCondition
classmethod new_and(condition_1: BreakpointCondition, condition_2: BreakpointCondition) BreakpointCondition

Creates a condition that triggers when condition_1 and condition_2 are both true.

Added in version 1.4.

Parameters:
  • condition_1 – first condition

  • condition_2 – second condition

classmethod new_length(type: BreakpointConditionLengthType, value: float, unit: LengthUnit) BreakpointCondition

Creates a condition that triggers on length changes.

Added in version 1.4.

Parameters:
  • type – the length type

  • value – the length value

  • unit – the length unit

classmethod new_or(condition_1: BreakpointCondition, condition_2: BreakpointCondition) BreakpointCondition

Creates a condition that triggers when either condition_1 or condition_2 is true.

Added in version 1.4.

Parameters:
  • condition_1 – first condition

  • condition_2 – second condition

classmethod new_ratio(type: BreakpointConditionRatioType, width: int, height: int) BreakpointCondition

Creates a condition that triggers on ratio changes.

The ratio is represented as width divided by height.

Added in version 1.4.

Parameters:
  • type – the ratio type

  • width – ratio width

  • height – ratio height

Methods

class BreakpointCondition
free() None

Frees self.

Added in version 1.4.

parse(str: str) BreakpointCondition

Parses a condition from a string.

Length conditions are specified as <type>: <value>[<unit>], where:

  • <type> can be min-width, max-width, min-height or max-height

  • <value> is a fractional number

  • <unit> can be px, pt or sp

If the unit is omitted, px is assumed.

See new_length.

Examples:

  • min-width: 500px

  • min-height: 400pt

  • max-width: 100sp

  • max-height: 500

Ratio conditions are specified as <type>: <width>[/<height>], where:

  • <type> can be min-aspect-ratio or max-aspect-ratio

  • <width> and <height> are integer numbers

See new_ratio.

The ratio is represented as <width> divided by <height>.

If <height> is omitted, it’s assumed to be 1.

Examples:

  • min-aspect-ratio: 4/3

  • max-aspect-ratio: 1

The logical operators and, or can be used to compose a complex condition as follows:

  • <condition> and: the condition is true when both <condition>’s are true, same as when using new_and

  • <condition> or: the condition is true when either of the <condition>’s is true, same as when using new_or

Examples:

  • min-width: 400px and max-aspect-ratio: 4/3

  • max-width: 360sp or max-width: 360px

Conditions can be further nested using parentheses, for example:

  • min-width: 400px and (max-aspect-ratio: 4/3 or max-height: 400px)

If parentheses are omitted, the first operator takes priority.

Added in version 1.4.

Parameters:

str – the string specifying the condition

to_string() str

Returns a textual representation of self.

The returned string can be parsed by parse.

Added in version 1.4.