From 4ad721eb82a404c8722ed8df1e52b30cd708724c Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 2 Oct 2022 19:34:03 -0400 Subject: [PATCH 1/2] Add pyscreeze stubs --- stubs/PyScreeze/METADATA.toml | 5 + stubs/PyScreeze/pyscreeze/__init__.pyi | 196 +++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 stubs/PyScreeze/METADATA.toml create mode 100644 stubs/PyScreeze/pyscreeze/__init__.pyi diff --git a/stubs/PyScreeze/METADATA.toml b/stubs/PyScreeze/METADATA.toml new file mode 100644 index 000000000000..beb02b01908b --- /dev/null +++ b/stubs/PyScreeze/METADATA.toml @@ -0,0 +1,5 @@ +version = "0.1.*" +requires = ["types-Pillow"] + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/PyScreeze/pyscreeze/__init__.pyi b/stubs/PyScreeze/pyscreeze/__init__.pyi new file mode 100644 index 000000000000..9a8680f0aa12 --- /dev/null +++ b/stubs/PyScreeze/pyscreeze/__init__.pyi @@ -0,0 +1,196 @@ +import sys +from _typeshed import Incomplete, StrOrBytesPath +from collections.abc import Callable, Generator +from typing import NamedTuple, SupportsFloat, TypeVar, overload +from typing_extensions import Literal, ParamSpec, SupportsIndex, TypeAlias + +from PIL import Image + +_Unused: TypeAlias = object +_P = ParamSpec("_P") +_R = TypeVar("_R") +# TODO: cv2.Mat is not available as a type yet: https://github.com/microsoft/python-type-stubs/issues/211 +# cv2.Mat is just an alias for a numpy NDArray, but can't import that either. +_Mat: TypeAlias = Incomplete + +useOpenCV: bool +RUNNING_PYTHON_2 = sys.version_info < (3,) +GRAYSCALE_DEFAULT: Literal[False] +USE_IMAGE_NOT_FOUND_EXCEPTION: bool +scrotExists: bool + +class Box(NamedTuple): + left: int + top: int + width: int + height: int + +class Point(NamedTuple): + x: int + y: int + +class RGB(NamedTuple): + red: int + green: int + blue: int + +class PyScreezeException(Exception): ... +class ImageNotFoundException(PyScreezeException): ... + +def requiresPillow(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ... +@overload +def locate( + needleImage: str | Image.Image | _Mat, + haystackImage: str | Image.Image | _Mat, + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Box | None: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locate( + needleImage: str | Image.Image, + haystackImage: str | Image.Image, + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: None = ..., +) -> Box | None: ... + +# _locateAll_opencv +@overload +def locateOnScreen( + image: str | Image.Image | _Mat, + minSearchTime: float = ..., + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Box | None: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locateOnScreen( + image: str | Image.Image, + minSearchTime: float = ..., + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: None = ..., +) -> Box | None: ... + +# _locateAll_opencv +@overload +def locateAllOnScreen( + image: str | Image.Image | _Mat, + *, + grayscale: bool | None = ..., + limit: int = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Generator[Box, None, None]: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locateAllOnScreen( + image: str | Image.Image, + *, + grayscale: bool | None = ..., + limit: int | None = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: None = ..., +) -> Generator[Box, None, None]: ... + +# _locateAll_opencv +@overload +def locateCenterOnScreen( + image: str | Image.Image | _Mat, + *, + minSearchTime: float, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Point | None: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locateCenterOnScreen( + image: str | Image.Image, + *, + minSearchTime: float, + grayscale: bool | None = ..., + limit: _Unused = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: None = ..., +) -> Point | None: ... + +# _locateAll_opencv +@overload +def locateOnWindow( + image: str | Image.Image | _Mat, + title: str, + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Box | None: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locateOnWindow( + image: str | Image.Image, + title: str, + *, + grayscale: bool | None = ..., + limit: _Unused = ..., + step: int = ..., + confidence: None = ..., +) -> Box | None: ... +def showRegionOnScreen(region: tuple[int, int, int, int], outlineColor: str = ..., filename: str = ...) -> None: ... +def center(coords: Box) -> Point: ... +def pixelMatchesColor( + x: int, y: int, expectedRGBColor: tuple[int, int, int] | tuple[int, int, int, int], tolerance: int = ... +) -> bool: ... +def pixel(x: int, y: int) -> tuple[int, int, int]: ... +def screenshot(imageFilename: StrOrBytesPath | None = ..., region: tuple[int, int, int, int] | None = ...) -> Image.Image: ... + +grab = screenshot +# _locateAll_opencv +@overload +def locateAll( + needleImage: str | Image.Image | _Mat, + haystackImage: str | Image.Image | _Mat, + grayscale: bool | None = ..., + limit: int = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: SupportsFloat | SupportsIndex | str = ..., +) -> Generator[Box, None, None]: ... + +# _locateAll_python / _locateAll_pillow +@overload +def locateAll( + needleImage: str | Image.Image, + haystackImage: str | Image.Image, + grayscale: bool | None = ..., + limit: int | None = ..., + region: tuple[int, int, int, int] | None = ..., + step: int = ..., + confidence: None = ..., +) -> Generator[Box, None, None]: ... From 8534fce2f7ba526f36a19b7933fc368f0e9adba8 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 2 Oct 2022 21:21:55 -0400 Subject: [PATCH 2/2] missed a box to tuple --- stubs/PyScreeze/pyscreeze/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/PyScreeze/pyscreeze/__init__.pyi b/stubs/PyScreeze/pyscreeze/__init__.pyi index 9a8680f0aa12..10bf651c0d08 100644 --- a/stubs/PyScreeze/pyscreeze/__init__.pyi +++ b/stubs/PyScreeze/pyscreeze/__init__.pyi @@ -163,7 +163,7 @@ def locateOnWindow( confidence: None = ..., ) -> Box | None: ... def showRegionOnScreen(region: tuple[int, int, int, int], outlineColor: str = ..., filename: str = ...) -> None: ... -def center(coords: Box) -> Point: ... +def center(coords: tuple[int, int, int, int]) -> Point: ... def pixelMatchesColor( x: int, y: int, expectedRGBColor: tuple[int, int, int] | tuple[int, int, int, int], tolerance: int = ... ) -> bool: ...