psychos.visual.Unit#

class psychos.visual.Unit(window: Window)[source]#

Bases: ABC

Abstract base class for different unit systems that transform normalized or other unit types into pixel values.

__init__(window: Window)[source]#

Methods

__init__(window)

from_name(name, window)

Instantiate a unit system class by name or return the instance if already provided.

inverse_transform(x, y)

Convert coordinates from pixel values to units.

inverse_transform_size(width, height)

Convert size from pixel values to units.

transform(x, y)

Convert coordinates from units to pixel values.

transform_size(width, height)

Convert size from units to pixel values.

classmethod from_name(name: UnitType | Unit, window: Window) Unit[source]#

Instantiate a unit system class by name or return the instance if already provided.

Parameters:
  • name (Union[str, Unit]) – The name of the unit system or an instance of Unit.

  • window (Window) – The window object, used to get the size for the transformation.

Returns:

An instance of the unit system class or the provided Unit instance.

Return type:

Unit

abstract inverse_transform(x: int, y: int) Tuple[float, float][source]#

Convert coordinates from pixel values to units.

Parameters:
  • x (int) – The x-coordinate in pixels.

  • y (int) – The y-coordinate in pixels.

Returns:

The coordinates in the unit system.

Return type:

Tuple[float, float]

abstract inverse_transform_size(width: int, height: int) Tuple[float, float][source]#

Convert size from pixel values to units.

Parameters:
  • width (int) – The width in pixels.

  • height (int) – The height in pixels.

Returns:

The width and height in the unit system.

Return type:

Tuple[float, float]

abstract transform(x: float, y: float) Tuple[int, int][source]#

Convert coordinates from units to pixel values.

Parameters:
  • x (float) – The x-coordinate.

  • y (float) – The y-coordinate.

Returns:

The pixel coordinates.

Return type:

Tuple[int, int]

abstract transform_size(width: float, height: float) Tuple[int, int][source]#

Convert size from units to pixel values.

Parameters:
  • width (float) – The width in the unit system.

  • height (float) – The height in the unit system.

Returns:

The width and height in pixel values.

Return type:

Tuple[int, int]