Skip to content

Commit

Permalink
Update pyscreeze methods reusing locateAll (#10741)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Sep 23, 2023
1 parent 6ed18ec commit c782b47
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions stubs/PyScreeze/pyscreeze/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c782b47

Please sign in to comment.