Skip to content

Commit 4c100fe

Browse files
Avasampre-commit-ci[bot]AlexWaygood
authored
Add stubs for pyautogui (#8654)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alex Waygood <[email protected]>
1 parent 61831c0 commit 4c100fe

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"stubs/pep8-naming",
7070
"stubs/psutil",
7171
"stubs/psycopg2",
72+
"stubs/PyAutoGUI",
7273
"stubs/pyflakes",
7374
"stubs/Pygments",
7475
"stubs/PyMySQL",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pyautogui requires a display, resulting in the following error on the CI:
2+
# failed to import, KeyError: 'DISPLAY'
3+
pyautogui

stubs/PyAutoGUI/METADATA.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version = "0.9.*"
2+
3+
[tool.stubtest]
4+
ignore_missing_stub = false
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
import contextlib
2+
from collections.abc import Callable, Generator, Iterable, Sequence
3+
from datetime import datetime
4+
from typing import NamedTuple, TypeVar, overload
5+
from typing_extensions import ParamSpec
6+
7+
# from pyscreeze import Box
8+
9+
class PyAutoGUIException(Exception): ...
10+
class FailSafeException(PyAutoGUIException): ...
11+
class ImageNotFoundException(PyAutoGUIException): ...
12+
13+
_P = ParamSpec("_P")
14+
_R = TypeVar("_R")
15+
16+
# TODO: Complete types with pyscreeze once we can import it as a type dependency
17+
# Actually `pyscreeze.Box`, but typeshed doesn't currently have stubs for pyscreeze
18+
# (and the library doesn't have type annotations either)
19+
20+
class _Box(NamedTuple):
21+
left: int
22+
top: int
23+
width: int
24+
height: int
25+
26+
def raisePyAutoGUIImageNotFoundException(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ...
27+
28+
# These functions reuse pyscreeze functions directly. See above TODO.
29+
def locate(*args, **kwargs) -> _Box | None: ...
30+
def locateAll(*args, **kwargs) -> Generator[_Box, None, None]: ...
31+
def locateAllOnScreen(*args, **kwargs) -> Generator[_Box, None, None]: ...
32+
def locateCenterOnScreen(*args, **kwargs) -> Point | None: ...
33+
def locateOnScreen(*args, **kwargs) -> _Box | None: ...
34+
def locateOnWindow(*args, **kwargs) -> _Box | None: ...
35+
def mouseInfo() -> None: ...
36+
def useImageNotFoundException(value: bool | None = ...) -> None: ...
37+
38+
KEY_NAMES: list[str]
39+
KEYBOARD_KEYS: list[str]
40+
LEFT: str
41+
MIDDLE: str
42+
RIGHT: str
43+
PRIMARY: str
44+
SECONDARY: str
45+
QWERTY: str
46+
QWERTZ: str
47+
48+
def isShiftCharacter(character: str) -> bool: ...
49+
50+
MINIMUM_DURATION: float
51+
MINIMUM_SLEEP: float
52+
PAUSE: float
53+
DARWIN_CATCH_UP_TIME: float
54+
FAILSAFE: bool
55+
FAILSAFE_POINTS: list[tuple[int, int]]
56+
LOG_SCREENSHOTS: bool
57+
LOG_SCREENSHOTS_LIMIT: int
58+
G_LOG_SCREENSHOTS_FILENAMES: list[str]
59+
60+
class Point(NamedTuple):
61+
x: float
62+
y: float
63+
64+
class Size(NamedTuple):
65+
width: int
66+
height: int
67+
68+
def getPointOnLine(x1: float, y1: float, x2: float, y2: float, n: float) -> tuple[float, float]: ...
69+
def linear(n: float) -> float: ...
70+
def position(x: int | None = ..., y: int | None = ...) -> Point: ...
71+
def size() -> Size: ...
72+
@overload
73+
def onScreen(x: tuple[float, float], y: None = ...) -> bool: ...
74+
@overload
75+
def onScreen(x: float, y: float) -> bool: ...
76+
def mouseDown(
77+
x: float | Sequence[float] | str | None = ...,
78+
y: float | None = ...,
79+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
80+
button: str = ...,
81+
duration: float = ...,
82+
tween: Callable[[float], float] = ...,
83+
logScreenshot: bool | None = ...,
84+
_pause: bool = ...,
85+
) -> None: ...
86+
def mouseUp(
87+
x: float | Sequence[float] | str | None = ...,
88+
y: float | None = ...,
89+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
90+
button: str = ...,
91+
duration: float = ...,
92+
tween: Callable[[float], float] = ...,
93+
logScreenshot: bool | None = ...,
94+
_pause: bool = ...,
95+
) -> None: ...
96+
def click(
97+
x: float | Sequence[float] | str | None = ...,
98+
y: float | None = ...,
99+
clicks: int = ...,
100+
interval: float = ...,
101+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
102+
button: str = ...,
103+
duration: float = ...,
104+
tween: Callable[[float], float] = ...,
105+
logScreenshot: bool | None = ...,
106+
_pause: bool = ...,
107+
) -> None: ...
108+
def leftClick(
109+
x: float | Sequence[float] | str | None = ...,
110+
y: float | None = ...,
111+
interval: float = ...,
112+
duration: float = ...,
113+
tween: Callable[[float], float] = ...,
114+
logScreenshot: bool | None = ...,
115+
_pause: bool = ...,
116+
) -> None: ...
117+
def rightClick(
118+
x: float | Sequence[float] | str | None = ...,
119+
y: float | None = ...,
120+
interval: float = ...,
121+
duration: float = ...,
122+
tween: Callable[[float], float] = ...,
123+
logScreenshot: bool | None = ...,
124+
_pause: bool = ...,
125+
) -> None: ...
126+
def middleClick(
127+
x: float | Sequence[float] | str | None = ...,
128+
y: float | None = ...,
129+
interval: float = ...,
130+
duration: float = ...,
131+
tween: Callable[[float], float] = ...,
132+
logScreenshot: bool | None = ...,
133+
_pause: bool = ...,
134+
) -> None: ...
135+
def doubleClick(
136+
x: float | Sequence[float] | str | None = ...,
137+
y: float | None = ...,
138+
interval: float = ...,
139+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
140+
button: str = ...,
141+
duration: float = ...,
142+
tween: Callable[[float], float] = ...,
143+
logScreenshot: bool | None = ...,
144+
_pause: bool = ...,
145+
) -> None: ...
146+
def tripleClick(
147+
x: float | Sequence[float] | str | None = ...,
148+
y: float | None = ...,
149+
interval: float = ...,
150+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
151+
button: str = ...,
152+
duration: float = ...,
153+
tween: Callable[[float], float] = ...,
154+
logScreenshot: bool | None = ...,
155+
_pause: bool = ...,
156+
) -> None: ...
157+
def scroll(
158+
clicks: float,
159+
x: float | Sequence[float] | str | None = ...,
160+
y: float | None = ...,
161+
logScreenshot: bool | None = ...,
162+
_pause: bool = ...,
163+
) -> None: ...
164+
def hscroll(
165+
clicks: float,
166+
x: float | Sequence[float] | str | None = ...,
167+
y: float | None = ...,
168+
logScreenshot: bool | None = ...,
169+
_pause: bool = ...,
170+
) -> None: ...
171+
def vscroll(
172+
clicks: float,
173+
x: float | Sequence[float] | str | None = ...,
174+
y: float | None = ...,
175+
logScreenshot: bool | None = ...,
176+
_pause: bool = ...,
177+
) -> None: ...
178+
def moveTo(
179+
x: float | Sequence[float] | str | None = ...,
180+
y: float | None = ...,
181+
duration: float = ...,
182+
tween: Callable[[float], float] = ...,
183+
logScreenshot: bool = ...,
184+
_pause: bool = ...,
185+
) -> None: ...
186+
def moveRel(
187+
xOffset: float | Sequence[float] | str | None = ...,
188+
yOffset: float | None = ...,
189+
duration: float = ...,
190+
tween: Callable[[float], float] = ...,
191+
logScreenshot: bool = ...,
192+
_pause: bool = ...,
193+
) -> None: ...
194+
195+
move = moveRel
196+
197+
def dragTo(
198+
x: float | Sequence[float] | str | None = ...,
199+
y: float | None = ...,
200+
duration: float = ...,
201+
tween: Callable[[float], float] = ...,
202+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
203+
button: str = ...,
204+
logScreenshot: bool | None = ...,
205+
_pause: bool = ...,
206+
mouseDownUp: bool = ...,
207+
) -> None: ...
208+
def dragRel(
209+
xOffset: float | Sequence[float] | str = ...,
210+
yOffset: float = ...,
211+
duration: float = ...,
212+
tween: Callable[[float], float] = ...,
213+
# Docstring says `button` can also be `int`, but `.lower()` is called unconditionally in `_normalizeButton()`
214+
button: str = ...,
215+
logScreenshot: bool | None = ...,
216+
_pause: bool = ...,
217+
mouseDownUp: bool = ...,
218+
) -> None: ...
219+
220+
drag = dragRel
221+
222+
def isValidKey(key: str) -> bool: ...
223+
def keyDown(key: str, logScreenshot: bool | None = ..., _pause: bool = ...) -> None: ...
224+
def keyUp(key: str, logScreenshot: bool | None = ..., _pause: bool = ...) -> None: ...
225+
def press(
226+
keys: str | Iterable[str], presses: int = ..., interval: float = ..., logScreenshot: bool | None = ..., _pause: bool = ...
227+
) -> None: ...
228+
def hold(
229+
keys: str | Iterable[str], logScreenshot: bool | None = ..., _pause: bool = ...
230+
) -> contextlib._GeneratorContextManager[None]: ...
231+
def typewrite(
232+
message: str | Sequence[str], interval: float = ..., logScreenshot: bool | None = ..., _pause: bool = ...
233+
) -> None: ...
234+
235+
write = typewrite
236+
237+
def hotkey(*args: str, logScreenshot: bool | None = ..., interval: float = ...) -> None: ...
238+
def failSafeCheck() -> None: ...
239+
def displayMousePosition(xOffset: float = ..., yOffset: float = ...) -> None: ...
240+
def sleep(seconds: float) -> None: ...
241+
def countdown(seconds: int) -> None: ...
242+
def run(commandStr: str, _ssCount: Sequence[int] | None = ...) -> None: ...
243+
def printInfo(dontPrint: bool = ...) -> str: ...
244+
def getInfo() -> tuple[str, str, str, str, Size, datetime]: ...

0 commit comments

Comments
 (0)