-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathcomputer.py
107 lines (80 loc) · 2.46 KB
/
computer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import abc
from typing import Literal
Environment = Literal["mac", "windows", "ubuntu", "browser"]
Button = Literal["left", "right", "wheel", "back", "forward"]
class Computer(abc.ABC):
"""A computer implemented with sync operations. The Computer interface abstracts the
operations needed to control a computer or browser."""
@property
@abc.abstractmethod
def environment(self) -> Environment:
pass
@property
@abc.abstractmethod
def dimensions(self) -> tuple[int, int]:
pass
@abc.abstractmethod
def screenshot(self) -> str:
pass
@abc.abstractmethod
def click(self, x: int, y: int, button: Button) -> None:
pass
@abc.abstractmethod
def double_click(self, x: int, y: int) -> None:
pass
@abc.abstractmethod
def scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None:
pass
@abc.abstractmethod
def type(self, text: str) -> None:
pass
@abc.abstractmethod
def wait(self) -> None:
pass
@abc.abstractmethod
def move(self, x: int, y: int) -> None:
pass
@abc.abstractmethod
def keypress(self, keys: list[str]) -> None:
pass
@abc.abstractmethod
def drag(self, path: list[tuple[int, int]]) -> None:
pass
class AsyncComputer(abc.ABC):
"""A computer implemented with async operations. The Computer interface abstracts the
operations needed to control a computer or browser."""
@property
@abc.abstractmethod
def environment(self) -> Environment:
pass
@property
@abc.abstractmethod
def dimensions(self) -> tuple[int, int]:
pass
@abc.abstractmethod
async def screenshot(self) -> str:
pass
@abc.abstractmethod
async def click(self, x: int, y: int, button: Button) -> None:
pass
@abc.abstractmethod
async def double_click(self, x: int, y: int) -> None:
pass
@abc.abstractmethod
async def scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None:
pass
@abc.abstractmethod
async def type(self, text: str) -> None:
pass
@abc.abstractmethod
async def wait(self) -> None:
pass
@abc.abstractmethod
async def move(self, x: int, y: int) -> None:
pass
@abc.abstractmethod
async def keypress(self, keys: list[str]) -> None:
pass
@abc.abstractmethod
async def drag(self, path: list[tuple[int, int]]) -> None:
pass