Skip to content

Region

RegionX module-attribute

RegionX = Literal['left', 'center', 'right']

The possible region x-coordinates of the assets.

RegionY module-attribute

RegionY = Literal['top', 'center', 'bottom']

The possible region y-coordinates of the assets.

RegionPosition

Bases: BaseModel

Represents a region positioning.

type class-attribute instance-attribute

type: Literal['region'] = 'region'

The type of positioning. Defaults to "region".

x class-attribute instance-attribute

x: RegionX = 'center'

The region x-coordinate of the assets.

y class-attribute instance-attribute

y: RegionY = 'center'

The region y-coordinate of the assets.

from_string classmethod

from_string(string: str) -> RegionPosition

Create a region position from a string.

Parameters:

Name Type Description Default
string str

The string to parse.

required

Returns:

Type Description
RegionPosition

The region position.

Source code in src/mosaico/positioning/region.py
@classmethod
def from_string(cls, string: str) -> RegionPosition:
    """
    Create a region position from a string.

    :param string: The string to parse.
    :return: The region position.
    """
    if string not in {"left", "center", "right", "top", "center", "bottom"}:
        raise ValueError("Invalid region position")
    if string in {"left", "center", "right"}:
        return cls(x=cast(RegionX, string), y="center")
    if string in {"top", "bottom"}:
        return cls(x="center", y=cast(RegionY, string))
    raise ValueError("Invalid region position")