diff --git a/snlohelper/base_function.py b/snlohelper/base_function.py index cd011c7db9f5e8c1a7136ade3e82c801ff5181e9..8c38479128ca96bd6c8ff6b4889ff24946caac9e 100644 --- a/snlohelper/base_function.py +++ b/snlohelper/base_function.py @@ -1,7 +1,7 @@ import time from typing import Any, Optional, Protocol -from .utils import Position, gui, scale, get_content_complete, set_value +from .utils import Point, gui, scale, get_content_complete, set_value from .main_window import Functions, open_function @@ -10,10 +10,10 @@ class BaseFunction(Protocol): _function: Functions # Positions - _run_pos: Position # of the run field - _result_pos: Position # of the results field - _close_pos: Position - _configuration_pos: dict[str, list[Position]] # of the configuration fields + _run_pos: Point # of the run field + _result_pos: Point # of the results field + _close_pos: Point + _configuration_pos: dict[str, list[Point]] # of the configuration fields def open(self) -> None: """Open the function.""" @@ -112,11 +112,11 @@ class BaseFunction(Protocol): def generate_position_dict( - first_position: Position, + first_position: Point, configuration_names: list[str], columns: int = 3, column_distance: int = 60, -) -> dict[str, list[Position]]: +) -> dict[str, list[Point]]: """Generate a position dictionary for functions. This utility makes it easier to generate a position matrix with three fields per entry. diff --git a/snlohelper/focus.py b/snlohelper/focus.py index f4ab1ab0ed1208f0b645396bf2db3ffea76a3413..53f8826f4c325ad43bfe992cfb394d9d8b88d74a 100644 --- a/snlohelper/focus.py +++ b/snlohelper/focus.py @@ -1,9 +1,9 @@ from .main_window import open_function, Functions -from .utils import Position, gui, scale, set_value, get_value_complete +from .utils import Point, gui, scale, set_value, get_value_complete # coordinates of the Focus-function (in FHD standard) -_dict_focus: dict[str, Position] = { +_dict_focus: dict[str, Point] = { "Wavelength (nm)": (366, 220), "Refractive Index": (366, 240), "Waist size (mm)": (366, 260), diff --git a/snlohelper/main_window.py b/snlohelper/main_window.py index 3eda17cab1636f55204b1d54f65937ebcf31d75a..8a79ccdb017134a6ec8e7690ba4361d038cc5bf9 100644 --- a/snlohelper/main_window.py +++ b/snlohelper/main_window.py @@ -4,10 +4,10 @@ The SNLO main window from enum import StrEnum -from .utils import Position, gui, scale +from .utils import Point, gui, scale # coordinates of the functions (in FHD standard) -_functions_coord: dict[str, Position] = { +_functions_coord: dict[str, Point] = { "Ref. Ind.": (66, 46), "Qmix": (66, 66), "Bmix": (66, 93), diff --git a/snlohelper/mix_methods.py b/snlohelper/mix_methods.py index 9deae485a728c13362abb8ce64859ab7f21c3d48..1b9dc2138f7e533bbd022f6044a6dcddd79729e8 100644 --- a/snlohelper/mix_methods.py +++ b/snlohelper/mix_methods.py @@ -1,6 +1,6 @@ from typing import Any, Optional, Protocol -from .utils import Position, gui, scale +from .utils import Point, gui, scale from .base_function import BaseFunction @@ -10,8 +10,8 @@ class MixMethods(BaseFunction, Protocol): Subclass it for specific methods. You should define the positions and the result interpretation. """ - _accept_pos: Position - _change_inputs_pos: Position + _accept_pos: Point + _change_inputs_pos: Point def accept(self) -> None: """Click 'Accept'.""" diff --git a/snlohelper/utils.py b/snlohelper/utils.py index 583e915f0e61e820006b0be0f9d821b915146073..a409c47f6e09c4c240867514040604f74f3e640c 100644 --- a/snlohelper/utils.py +++ b/snlohelper/utils.py @@ -6,7 +6,7 @@ General methods for the autoclicker """ import logging -from typing import Any, Optional +from typing import Any, Optional, Union import pyautogui as gui from pyperclip import paste @@ -15,7 +15,7 @@ from pyperclip import paste log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) -Position = tuple[float, float] +Point = Union[gui.Point, tuple[float, float]] """ @@ -28,7 +28,7 @@ screen resolution. """ -def get_screenfactors(standard: Position = (1920, 1080)) -> Position: +def get_screenfactors(standard: Point = (1920, 1080)) -> Point: """Get the scaling factor from Full HD to the current display resolution.""" width, height = gui.size() return standard[0] / width, standard[1] / height @@ -41,7 +41,7 @@ def set_screenfactors(new_factors: Optional[tuple[float, float]] = None) -> tupl return factors -def scale(x: float | Position, y: float | None = None) -> Position: +def scale(x: float | Point, y: float | None = None) -> Point: """Scale coordinates from the definition standard to the current screen.""" global factors if isinstance(x, (list, tuple)): @@ -59,7 +59,7 @@ def scale(x: float | Position, y: float | None = None) -> Position: return x / factors[0], y / factors[1] -def standard_position() -> Position: +def standard_position() -> Point: """Get the mouse position in standard coordinates (x, y).""" point = gui.position() global factors @@ -74,7 +74,7 @@ GUI functions to get/set content from/into data fields. """ -def get_content(position: Position) -> str: +def get_content(position: Point) -> str: """Get the content of the field at position via double click. If there is a "-" in the text, the extraction fails! @@ -84,12 +84,12 @@ def get_content(position: Position) -> str: return paste() -def get_value(position: Position) -> float: +def get_value(position: Point) -> float: """Move to position, retrieve value and return float.""" return float(get_content(position)) -def get_content_complete(position: Position) -> str: +def get_content_complete(position: Point) -> str: """Go to position and retrieve the content there, marking all.""" gui.click(*scale(*position)) gui.hotkey("ctrl", "home") @@ -99,12 +99,12 @@ def get_content_complete(position: Position) -> str: return paste() -def get_value_complete(position: Position) -> float: +def get_value_complete(position: Point) -> float: """Move to position, retrieve value via context menu (slower) and return float.""" return float(get_content_complete(position)) -def set_value(position: Position, value: Any) -> None: +def set_value(position: Point, value: Any) -> None: """Move to position, insert value as string.""" gui.doubleClick(*scale(*position)) gui.press("delete")