Skip to content
Snippets Groups Projects
Commit 5933d784 authored by Benedikt Burger's avatar Benedikt Burger
Browse files

Rename Position into Point

parent 1ebdb44c
No related branches found
No related tags found
No related merge requests found
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.
......
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),
......
......@@ -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),
......
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'."""
......
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment