-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pyscreeze stubs #8823
Merged
Merged
Add pyscreeze stubs #8823
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version = "0.1.*" | ||
requires = ["types-Pillow"] | ||
|
||
[tool.stubtest] | ||
ignore_missing_stub = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: 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: ... | ||
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]: ... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a strange use of overloads, since it looks like either one variant or the other is used depending on whether cv2 is present. Overloads are normally used when there are complicated relationships between different parameters and/or the return type. On the other hand, I can't think of any concrete ill effect of using overloads here, so I'm fine with keeping them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, since we can't represent that condition in typing, overloads are the next best thing so that both possible signatures are accurate.