Ir para o conteúdo

Positioning

PositionType module-attribute

PositionType = Literal['absolute', 'relative', 'region']

An enumeration of the different types of positions that can be held in an assets.

Position module-attribute

Represents a positioning of an assets in the frame.

convert_position_to_absolute

convert_position_to_absolute(
    position: Position, frame_size: FrameSize
) -> AbsolutePosition

Convert a relative position to an absolute position.

Parameters:

Name Type Description Default
position Position

The position to be converted.

required
frame_size FrameSize

The size of the frame.

required

Returns:

Type Description
AbsolutePosition

The converted absolute positioning object.

Source code in src/mosaico/positioning/utils.py
def convert_position_to_absolute(position: Position, frame_size: FrameSize) -> AbsolutePosition:
    """
    Convert a relative position to an absolute position.

    :param position: The position to be converted.
    :param frame_size: The size of the frame.
    :return: The converted absolute positioning object.
    """
    if isinstance(position, AbsolutePosition):
        return position

    if isinstance(position, RelativePosition):
        return AbsolutePosition.from_relative(position, frame_size)

    return AbsolutePosition.from_region(position, frame_size)

is_region_position

is_region_position(position: Position) -> bool

Check if the position is a region position.

Parameters:

Name Type Description Default
position Position

The position to be checked.

required

Returns:

Type Description
bool

Whether the position is a region position.

Source code in src/mosaico/positioning/utils.py
def is_region_position(position: Position) -> bool:
    """
    Check if the position is a region position.

    :param position: The position to be checked.
    :return: Whether the position is a region position.
    """
    return isinstance(position, RegionPosition)

is_relative_position

is_relative_position(position: Position) -> bool

Check if the position is a relative position.

Parameters:

Name Type Description Default
position Position

The position to be checked.

required

Returns:

Type Description
bool

Whether the position is a relative position.

Source code in src/mosaico/positioning/utils.py
def is_relative_position(position: Position) -> bool:
    """
    Check if the position is a relative position.

    :param position: The position to be checked.
    :return: Whether the position is a relative position.
    """
    return isinstance(position, RelativePosition)

is_absolute_position

is_absolute_position(position: Position) -> bool

Check if the position is an absolute position.

Parameters:

Name Type Description Default
position Position

The position to be checked.

required

Returns:

Type Description
bool

Whether the position is an absolute position.

Source code in src/mosaico/positioning/utils.py
def is_absolute_position(position: Position) -> bool:
    """
    Check if the position is an absolute position.

    :param position: The position to be checked.
    :return: Whether the position is an absolute position.
    """
    return isinstance(position, AbsolutePosition)