From c782b47aa0e3da3fb64f804cd1cfec94635235f5 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 22 Sep 2023 22:42:34 -0400 Subject: [PATCH] Update pyscreeze methods reusing `locateAll` (#10741) --- stubs/PyScreeze/pyscreeze/__init__.pyi | 59 ++++++++++++-------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/stubs/PyScreeze/pyscreeze/__init__.pyi b/stubs/PyScreeze/pyscreeze/__init__.pyi index be6db8189072..97b730bf5a93 100644 --- a/stubs/PyScreeze/pyscreeze/__init__.pyi +++ b/stubs/PyScreeze/pyscreeze/__init__.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete, StrOrBytesPath, Unused +from _typeshed import Incomplete, ReadableBuffer, StrOrBytesPath, Unused from collections.abc import Callable, Generator from typing import NamedTuple, SupportsFloat, TypeVar, overload from typing_extensions import Final, ParamSpec, SupportsIndex, TypeAlias @@ -7,13 +7,9 @@ from PIL import Image _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 -# https://github.com/microsoft/python-type-stubs/tree/main/cv2 -# https://github.com/opencv/opencv/pull/20370 -# cv2.Mat is just an alias for a numpy NDArray, but can't import that either. -# Because pyscreeze does not declare it as a dependency, stub_uploader won't let it. -_Mat: TypeAlias = Incomplete +# cv2.typing.MatLike: is an alias for `numpy.ndarray | cv2.mat_wrapper.Mat`, Mat extends ndarray. +# But can't import either, because pyscreeze does not declare them as dependencies, stub_uploader won't let it. +_MatLike: TypeAlias = Incomplete useOpenCV: Final[bool] RUNNING_PYTHON_2: Final = False @@ -40,21 +36,22 @@ class RGB(NamedTuple): class PyScreezeException(Exception): ... class ImageNotFoundException(PyScreezeException): ... -# _locateAll_opencv def requiresPyGetWindow(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ... + +# _locateAll_opencv @overload def locate( - needleImage: str | Image.Image | _Mat, - haystackImage: str | Image.Image | _Mat, + needleImage: str | Image.Image | _MatLike, + haystackImage: str | Image.Image | _MatLike, *, grayscale: bool | None = None, limit: Unused = 1, region: tuple[int, int, int, int] | None = None, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Box | None: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locate( needleImage: str | Image.Image, @@ -70,17 +67,17 @@ def locate( # _locateAll_opencv @overload def locateOnScreen( - image: str | Image.Image | _Mat, + image: str | Image.Image | _MatLike, minSearchTime: float = 0, *, grayscale: bool | None = None, limit: Unused = 1, region: tuple[int, int, int, int] | None = None, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Box | None: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locateOnScreen( image: str | Image.Image, @@ -96,16 +93,16 @@ def locateOnScreen( # _locateAll_opencv @overload def locateAllOnScreen( - image: str | Image.Image | _Mat, + image: str | Image.Image | _MatLike, *, grayscale: bool | None = None, limit: int = 1000, region: tuple[int, int, int, int] | None = None, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Generator[Box, None, None]: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locateAllOnScreen( image: str | Image.Image, @@ -120,17 +117,17 @@ def locateAllOnScreen( # _locateAll_opencv @overload def locateCenterOnScreen( - image: str | Image.Image | _Mat, + image: str | Image.Image | _MatLike, *, minSearchTime: float, grayscale: bool | None = None, limit: Unused = 1, region: tuple[int, int, int, int] | None = None, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Point | None: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locateCenterOnScreen( image: str | Image.Image, @@ -142,22 +139,22 @@ def locateCenterOnScreen( step: int = 1, confidence: None = None, ) -> Point | None: ... -def locateOnScreenNear(image: str | Image.Image | _Mat, x: int, y: int) -> Box: ... -def locateCenterOnScreenNear(image: str | Image.Image | _Mat, x: int, y: int) -> Point | None: ... +def locateOnScreenNear(image: str | Image.Image | _MatLike, x: int, y: int) -> Box: ... +def locateCenterOnScreenNear(image: str | Image.Image | _MatLike, x: int, y: int) -> Point | None: ... # _locateAll_opencv @overload def locateOnWindow( - image: str | Image.Image | _Mat, + image: str | Image.Image | _MatLike, title: str, *, grayscale: bool | None = None, limit: Unused = 1, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Box | None: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locateOnWindow( image: str | Image.Image, @@ -181,16 +178,16 @@ def screenshot(imageFilename: StrOrBytesPath | None = None, region: tuple[int, i # _locateAll_opencv @overload def locateAll( - needleImage: str | Image.Image | _Mat, - haystackImage: str | Image.Image | _Mat, + needleImage: str | Image.Image | _MatLike, + haystackImage: str | Image.Image | _MatLike, grayscale: bool | None = None, limit: int = 1000, region: tuple[int, int, int, int] | None = None, step: int = 1, - confidence: SupportsFloat | SupportsIndex | str = 0.999, + confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999, ) -> Generator[Box, None, None]: ... -# _locateAll_python / _locateAll_pillow +# _locateAll_pillow @overload def locateAll( needleImage: str | Image.Image,