pyclickimage.click_manager#

class pyclickimage.click_manager.ClickManager[source]#

Bases: object

A class to manage user clicks grouped into named categories.

This class stores 2D coordinates of points clicked on an image, grouped by string identifiers.

Points are all the time saved as float but the precision mode (float or integer) apply on output.

_check_exist_group(group_name: str) → None[source]#
static _check_group_name(group_name: str) → None[source]#
static _check_precision(mode: Literal['float', 'int']) → None[source]#
_convert(value: int | float, precision_mode: Literal['float', 'int']) → int | float[source]#

Convert value according to precision mode.

Parameters:

value (Number) – Input coordinate.

Returns:

Converted coordinate.

Return type:

Number

add_click(x: int | float, y: int | float, *, group_name: str) → None[source]#

Add a click to a group.

Parameters:
  • x (Number) – X coordinate of the click.

  • y (Number) – Y coordinate of the click.

  • group_name (str) – Group name.

add_group(group_name: str) → None[source]#

Add a new group.

Note

If the group already exist, nothing is done.

Parameters:

group_name (str) – Name of the group to add.

clear_group(group_name: str) → None[source]#

Clear all clicks in a group.

Parameters:

group_name (str) – Group name.

extract_group(group_name: str, *, precision_mode: Literal['float', 'int'] = 'float') → List[Tuple[int | float | None, int | float | None]][source]#

Extracts the clicks for the specified group.

Parameters:
  • group_name (str) – The name of the group whose clicks are to be extracted.

  • precision_mode (str, default is "float") – The precision mode between “int” and “float”.

Returns:

A list of tuples with the format (Click X, Click Y) for each click in the group.

Return type:

List[Point]

get_click(index: int, *, group_name: str, precision_mode: Literal['float', 'int'] = 'float') → Tuple[int | float | None, int | float | None][source]#

Get a specific click.

Parameters:
  • index (int) – Index of the click.

  • group_name (str) – The group to get the click.

  • precision_mode (str, default is "float") – The precision mode between “int” and “float”.

Returns:

Click coordinates.

Return type:

Tuple[Number, Number]

groups: Dict[str, List[Tuple[int | float | None, int | float | None]]]#
property n_clicks: int#

Return the number of clicks

remove_click(index: int, *, group_name: str) → None[source]#

Remove a click by index.

Parameters:
  • index (int) – Index of the click.

  • group_name (str) – Group name.

remove_group(group_name: str) → None[source]#

Remove a group.

Parameters:

group_name (str) – Name of the group to remove.

rename_group(old_name: str, new_name: str) → None[source]#

Rename a group.

Parameters:
  • old_name (str) – Existing group name.

  • new_name (str) – New group name.

Raises:

KeyError – If new name already used or old name not exist.

to_dict(precision_mode: Literal['float', 'int'] = 'float') → Dict[str, List[Tuple[int | float | None, int | float | None]]][source]#

Return internal data as dictionary.

Parameters:

precision_mode (str, default is "float") – The precision mode between “int” and “float”.

Returns:

Dictionary mapping group names to lists of points. Each point is a tuple (x, y) with values converted using _convert() depending on the current precision mode.

Return type:

dict

to_half_shift_off()[source]#

Reverse the half-pixel shift.

Point (a, b) -> (a + 0.5, b + 0.5)

to_half_shift_on()[source]#

Shift all points by -0.5 to use pixel-centered coordinates.

Point (a, b) -> (a - 0.5, b - 0.5)

class pyclickimage.click_manager.ClickManagerError[source]#

Bases: PyClickImageError

Base ClickManager exception.

class pyclickimage.click_manager.GroupNotFoundError[source]#

Bases: ClickManagerError

class pyclickimage.click_manager.GroupAlreadyExistError[source]#

Bases: ClickManagerError

class pyclickimage.click_manager.InvalidPrecisionError[source]#

Bases: ClickManagerError