From 4f43e6ea68efe287241d16a6f9dfc7b2cd9d88d9 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 31 Aug 2022 11:10:47 -0400 Subject: [PATCH] Updated PyAutoGUI types from https://github.com/python/typeshed/pull/8654 --- scripts/requirements-dev.txt | 1 - scripts/requirements.txt | 2 +- typings/pyautogui/__init__.pyi | 413 ++++++++++++++++----------- typings/pyautogui/_pyautogui_osx.pyi | 2 + typings/pyautogui/_pyautogui_win.pyi | 39 +++ typings/pyautogui/_pyautogui_x11.pyi | 2 + 6 files changed, 284 insertions(+), 175 deletions(-) create mode 100644 typings/pyautogui/_pyautogui_osx.pyi create mode 100644 typings/pyautogui/_pyautogui_win.pyi create mode 100644 typings/pyautogui/_pyautogui_x11.pyi diff --git a/scripts/requirements-dev.txt b/scripts/requirements-dev.txt index 01ac6732..a2a742e3 100644 --- a/scripts/requirements-dev.txt +++ b/scripts/requirements-dev.txt @@ -29,5 +29,4 @@ pyright qt6-applications # Types pywin32-stubs>=1.0.7 # Added error types -types-requests typing-extensions diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 0c4e3c0f..5bc12d6c 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -13,7 +13,7 @@ numpy>=1.23 # Updated types opencv-python-headless>=4.5.4,<4.6 # https://github.com/pyinstaller/pyinstaller/issues/6889 PyQt6>=6.2.1 # Python 3.10 support -git+https://github.com/Avasam/imagehash.git@python2-typing#egg=ImageHash # https://github.com/JohannesBuchner/imagehash/issues/151 +git+https://github.com/JohannesBuchner/imagehash#egg=ImageHash # Contains type information keyboard packaging Pillow diff --git a/typings/pyautogui/__init__.pyi b/typings/pyautogui/__init__.pyi index 41f99455..0fe65284 100644 --- a/typings/pyautogui/__init__.pyi +++ b/typings/pyautogui/__init__.pyi @@ -1,17 +1,12 @@ -"""# noqa: Y021 -This type stub file was generated by pyright. -https://github.com/asweigart/pyautogui/issues/645 -""" -from __future__ import absolute_import, division, print_function - -import collections -import sys -from collections.abc import Callable, Sequence -from contextlib import contextmanager +import collections.abc +from collections.abc import Callable, Generator from datetime import datetime -from typing import Literal +from typing import NamedTuple, TypeVar, overload -__version__: str +from _typeshed import Incomplete +from typing_extensions import ParamSpec + +# from pyscreeze import Box class PyAutoGUIException(Exception): @@ -26,206 +21,278 @@ class ImageNotFoundException(PyAutoGUIException): ... -if sys.version_info[0] == 2 or sys.version_info[0: 2] in ((3, 1), (3, 2)): # noqa: Y003 - collectionsSequence = collections.Sequence -else: - collectionsSequence = Sequence +collectionsSequence = collections.abc.Sequence +_P = ParamSpec("_P") +_R = TypeVar("_R") -def raisePyAutoGUIImageNotFoundException(wrappedFunction) -> Callable: - ... +# TODO: Complete types with pyscreeze once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 -def useImageNotFoundException(value=...) -> None: - ... +class _Box(NamedTuple): + left: int + top: int + width: int + height: int -KEY_NAMES = ... -KEYBOARD_KEYS = ... -LEFT = ... -MIDDLE = ... -RIGHT = ... -PRIMARY = ... -SECONDARY = ... -QWERTY = ... -QWERTZ = ... +def raisePyAutoGUIImageNotFoundException(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ... +def locate(*args: Incomplete, **kwargs: Incomplete) -> _Box | None: ... +def locateAll(*args: Incomplete, **kwargs: Incomplete) -> Generator[_Box, None, None]: ... +def locateAllOnScreen(*args: Incomplete, **kwargs: Incomplete) -> Generator[_Box, None, None]: ... +def locateCenterOnScreen(*args: Incomplete, **kwargs: Incomplete) -> Point | None: ... +def locateOnScreen(*args: Incomplete, **kwargs: Incomplete) -> _Box | None: ... +def locateOnWindow(*args: Incomplete, **kwargs: Incomplete) -> _Box | None: ... +def mouseInfo() -> None: ... +def useImageNotFoundException(value: bool | None = ...) -> None: ... -def isShiftCharacter(character) -> bool: - ... +KEY_NAMES: list[str] +KEYBOARD_KEYS: list[str] +LEFT: str +MIDDLE: str +RIGHT: str +PRIMARY: str +SECONDARY: str +QWERTY: str +QWERTZ: str -MINIMUM_DURATION = ... -MINIMUM_SLEEP = ... -PAUSE = ... -DARWIN_CATCH_UP_TIME = ... -FAILSAFE: bool -FAILSAFE_POINTS = ... -LOG_SCREENSHOTS = ... -LOG_SCREENSHOTS_LIMIT = ... -G_LOG_SCREENSHOTS_FILENAMES = ... -Point = ... -Size = ... +def isShiftCharacter(character: str) -> bool: ... -def getPointOnLine(x1: int, y1: int, x2: int, y2: int, n: float) -> tuple[int, int]: - ... +MINIMUM_DURATION: float +MINIMUM_SLEEP: float +PAUSE: float +DARWIN_CATCH_UP_TIME: float +FAILSAFE: bool +FAILSAFE_POINTS: list[tuple[int, int]] +LOG_SCREENSHOTS: bool +LOG_SCREENSHOTS_LIMIT: int +G_LOG_SCREENSHOTS_FILENAMES: list[str] -def linear(n): - ... +class Point(NamedTuple): + x: float + y: float -def position(x=..., y=...) -> Point: - ... +class Size(NamedTuple): + width: int + height: int -def size() -> Size: - ... +def getPointOnLine(x1: float, y1: float, x2: float, y2: float, n: float) -> tuple[float, float]: ... +def linear(n: float) -> float: ... +def position(x: int | None = ..., y: int | None = ...) -> Point: ... +def size() -> Size: ... +@overload +def onScreen(xy: tuple[float, float]) -> bool: ... +@overload +def onScreen(x: float, y: float) -> bool: ... -def onScreen(x, y=...) -> bool: - ... +def mouseDown( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + button: str = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... -def mouseDown(x=..., y=..., button=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def mouseUp(x=..., y=..., button=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... +def mouseUp( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + button: str = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... def click( - x=..., - y=..., - clicks=..., - interval=..., - button=..., - duration=..., - tween=..., - logScreenshot=..., - _pause=...) -> None: - ... - - -def leftClick(x=..., y=..., interval=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def rightClick(x=..., y=..., interval=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def middleClick(x=..., y=..., interval=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def doubleClick(x=..., y=..., interval=..., button=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def tripleClick(x=..., y=..., interval=..., button=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def scroll(clicks, x=..., y=..., logScreenshot=..., _pause=...) -> None: - ... - - -def hscroll(clicks, x=..., y=..., logScreenshot=..., _pause=...) -> None: - ... - - -def vscroll(clicks, x=..., y=..., logScreenshot=..., _pause=...) -> None: - ... - - -def moveTo(x=..., y=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -def moveRel(xOffset=..., yOffset=..., duration=..., tween=..., logScreenshot=..., _pause=...) -> None: - ... - - -move = ... - - -def dragTo(x=..., y=..., duration=..., tween=..., button=..., logScreenshot=..., _pause=..., mouseDownUp=...) -> None: - ... + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + clicks: int = ..., + interval: float = ..., + button: str = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def leftClick( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + interval: float = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def rightClick( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + interval: float = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def middleClick( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + interval: float = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def doubleClick( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + interval: float = ..., + button: str = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def tripleClick( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + interval: float = ..., + button: str = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def scroll( + clicks: float, + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def hscroll( + clicks: float, + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def vscroll( + clicks: float, + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., +) -> None: ... + + +def moveTo( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool = ..., + _pause: bool = ..., +) -> None: ... + + +def moveRel( + xOffset: float | collectionsSequence[int] | None = ..., + yOffset: float | collectionsSequence[int] | None = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + logScreenshot: bool = ..., + _pause: bool = ..., +) -> None: ... + + +move = moveRel + + +def dragTo( + x: float | collectionsSequence[int] | None = ..., + y: float | collectionsSequence[int] | None = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + button: str = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., + mouseDownUp: bool = ..., +) -> None: ... def dragRel( - xOffset=..., - yOffset=..., - duration=..., - tween=..., - button=..., - logScreenshot=..., - _pause=..., - mouseDownUp=...): - ... - - -drag = ... - - -def isValidKey(key) -> bool: - ... - - -def keyDown(key, logScreenshot=..., _pause=...) -> None: - ... - - -def keyUp(key, logScreenshot=..., _pause=...) -> None: - ... + xOffset: float | collectionsSequence[int] = ..., + yOffset: float | collectionsSequence[int] = ..., + duration: float = ..., + tween: Callable[[float], float] = ..., + button: str = ..., + logScreenshot: bool | None = ..., + _pause: bool = ..., + mouseDownUp: bool = ..., +) -> None: ... -def press(keys, presses=..., interval=..., logScreenshot=..., _pause=...): - ... - +drag = dragRel -@contextmanager -def hold(keys, logScreenshot=..., _pause=...): - ... +def isValidKey(key: str) -> bool: ... +def keyDown(key: str, logScreenshot: bool | None = ..., _pause: bool = ...) -> None: ... +def keyUp(key: str, logScreenshot: bool | None = ..., _pause: bool = ...) -> None: ... -def typewrite(message, interval=..., logScreenshot=..., _pause=...) -> None: - ... +def press(keys: str | list[str], presses: int = ..., interval: float = ..., + logScreenshot: bool | None = ..., _pause: bool = ...) -> None: ... -write = ... +def hold(keys: str | list[str], + logScreenshot: bool | None = ..., + _pause: bool = ...) -> Generator[None, + None, + None]: ... -def hotkey(*args: str, **kwargs: int | bool | None) -> None: - ... +def typewrite( + message: str | list[str], + interval: float = ..., + logScreenshot: bool | None = ..., + _pause: bool = ...) -> None: ... -def failSafeCheck() -> None: - ... - -def displayMousePosition(xOffset=..., yOffset=...): - ... - - -def sleep(seconds) -> None: - ... +write = typewrite -def countdown(seconds) -> None: - ... - - -def run(commandStr, _ssCount=...) -> None: - ... - - -def printInfo(dontPrint=...) -> str: - ... - - -def getInfo() -> tuple[str, str, Literal['0.9.53'], str, Size, datetime]: - ... +def hotkey(*args: str, **kwargs: float | bool | None) -> None: ... +def failSafeCheck() -> None: ... +def displayMousePosition(xOffset: float = ..., yOffset: float = ...) -> None: ... +def sleep(seconds: int) -> None: ... +def countdown(seconds: int) -> None: ... +def run(commandStr: str, _ssCount: list[int] | None = ...) -> None: ... +def printInfo(dontPrint: bool = ...) -> str: ... +def getInfo() -> tuple[str, str, str, str, Size, datetime]: ... diff --git a/typings/pyautogui/_pyautogui_osx.pyi b/typings/pyautogui/_pyautogui_osx.pyi new file mode 100644 index 00000000..569791ac --- /dev/null +++ b/typings/pyautogui/_pyautogui_osx.pyi @@ -0,0 +1,2 @@ +keyboardMapping: dict[str, int] +special_key_translate_table: dict[str, int] diff --git a/typings/pyautogui/_pyautogui_win.pyi b/typings/pyautogui/_pyautogui_win.pyi new file mode 100644 index 00000000..738766ce --- /dev/null +++ b/typings/pyautogui/_pyautogui_win.pyi @@ -0,0 +1,39 @@ +import ctypes + +MOUSEEVENTF_MOVE: int +MOUSEEVENTF_LEFTDOWN: int +MOUSEEVENTF_LEFTUP: int +MOUSEEVENTF_LEFTCLICK: int +MOUSEEVENTF_RIGHTDOWN: int +MOUSEEVENTF_RIGHTUP: int +MOUSEEVENTF_RIGHTCLICK: int +MOUSEEVENTF_MIDDLEDOWN: int +MOUSEEVENTF_MIDDLEUP: int +MOUSEEVENTF_MIDDLECLICK: int +MOUSEEVENTF_ABSOLUTE: int +MOUSEEVENTF_WHEEL: int +MOUSEEVENTF_HWHEEL: int +KEYEVENTF_KEYDOWN: int +KEYEVENTF_KEYUP: int +INPUT_MOUSE: int +INPUT_KEYBOARD: int + + +class MOUSEINPUT(ctypes.Structure): + ... + + +class KEYBDINPUT(ctypes.Structure): + ... + + +class HARDWAREINPUT(ctypes.Structure): + ... + + +class INPUT(ctypes.Structure): + class _I(ctypes.Union): + ... + + +keyboardMapping: dict[str, int] diff --git a/typings/pyautogui/_pyautogui_x11.pyi b/typings/pyautogui/_pyautogui_x11.pyi new file mode 100644 index 00000000..24d90ecc --- /dev/null +++ b/typings/pyautogui/_pyautogui_x11.pyi @@ -0,0 +1,2 @@ +BUTTON_NAME_MAPPING: dict[str | int, int] +keyboardMapping: dict[str, int]