kotonebot 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kotonebot/__init__.py +39 -39
- kotonebot/backend/bot.py +312 -312
- kotonebot/backend/color.py +525 -525
- kotonebot/backend/context/__init__.py +3 -3
- kotonebot/backend/context/task_action.py +183 -183
- kotonebot/backend/core.py +129 -129
- kotonebot/backend/debug/entry.py +89 -89
- kotonebot/backend/debug/mock.py +78 -78
- kotonebot/backend/debug/server.py +222 -222
- kotonebot/backend/debug/vars.py +351 -351
- kotonebot/backend/dispatch.py +227 -227
- kotonebot/backend/flow_controller.py +196 -196
- kotonebot/backend/ocr.py +535 -529
- kotonebot/backend/preprocessor.py +103 -103
- kotonebot/client/__init__.py +9 -9
- kotonebot/client/device.py +528 -503
- kotonebot/client/fast_screenshot.py +377 -377
- kotonebot/client/host/__init__.py +43 -12
- kotonebot/client/host/adb_common.py +107 -103
- kotonebot/client/host/custom.py +118 -114
- kotonebot/client/host/leidian_host.py +196 -201
- kotonebot/client/host/mumu12_host.py +353 -358
- kotonebot/client/host/protocol.py +214 -213
- kotonebot/client/host/windows_common.py +58 -58
- kotonebot/client/implements/__init__.py +71 -15
- kotonebot/client/implements/adb.py +89 -85
- kotonebot/client/implements/adb_raw.py +162 -158
- kotonebot/client/implements/nemu_ipc/__init__.py +11 -7
- kotonebot/client/implements/nemu_ipc/external_renderer_ipc.py +284 -284
- kotonebot/client/implements/nemu_ipc/nemu_ipc.py +327 -327
- kotonebot/client/implements/remote_windows.py +188 -188
- kotonebot/client/implements/uiautomator2.py +85 -81
- kotonebot/client/implements/windows.py +176 -172
- kotonebot/client/protocol.py +69 -69
- kotonebot/client/registration.py +24 -24
- kotonebot/config/base_config.py +96 -96
- kotonebot/config/manager.py +36 -36
- kotonebot/errors.py +76 -71
- kotonebot/interop/win/__init__.py +10 -3
- kotonebot/interop/win/_mouse.py +311 -0
- kotonebot/interop/win/message_box.py +313 -313
- kotonebot/interop/win/reg.py +37 -37
- kotonebot/interop/win/shortcut.py +43 -43
- kotonebot/interop/win/task_dialog.py +513 -513
- kotonebot/logging/__init__.py +2 -2
- kotonebot/logging/log.py +17 -17
- kotonebot/primitives/__init__.py +17 -17
- kotonebot/primitives/geometry.py +862 -290
- kotonebot/primitives/visual.py +63 -63
- kotonebot/tools/mirror.py +354 -354
- kotonebot/ui/file_host/sensio.py +36 -36
- kotonebot/ui/file_host/tmp_send.py +54 -54
- kotonebot/ui/pushkit/__init__.py +3 -3
- kotonebot/ui/pushkit/image_host.py +88 -87
- kotonebot/ui/pushkit/protocol.py +13 -13
- kotonebot/ui/pushkit/wxpusher.py +54 -53
- kotonebot/ui/user.py +148 -148
- kotonebot/util.py +436 -436
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/METADATA +82 -81
- kotonebot-0.5.0.dist-info/RECORD +71 -0
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/licenses/LICENSE +673 -673
- kotonebot-0.4.0.dist-info/RECORD +0 -70
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/WHEEL +0 -0
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,172 +1,176 @@
|
|
|
1
|
-
# ruff: noqa: E402
|
|
2
|
-
from kotonebot.util import require_windows
|
|
3
|
-
require_windows('"WindowsImpl" implementation')
|
|
4
|
-
|
|
5
|
-
from ctypes import windll
|
|
6
|
-
from typing import Literal
|
|
7
|
-
from importlib import resources
|
|
8
|
-
from functools import cached_property
|
|
9
|
-
from dataclasses import dataclass
|
|
10
|
-
|
|
11
|
-
import cv2
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
from
|
|
17
|
-
|
|
18
|
-
from
|
|
19
|
-
|
|
20
|
-
from
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
self.ahk.msg_box('
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
self.ahk.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
def
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
device
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
#
|
|
172
|
-
#
|
|
1
|
+
# ruff: noqa: E402
|
|
2
|
+
from kotonebot.util import require_windows
|
|
3
|
+
require_windows('"WindowsImpl" implementation')
|
|
4
|
+
|
|
5
|
+
from ctypes import windll
|
|
6
|
+
from typing import Literal
|
|
7
|
+
from importlib import resources
|
|
8
|
+
from functools import cached_property
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
|
|
11
|
+
import cv2
|
|
12
|
+
import numpy as np
|
|
13
|
+
try:
|
|
14
|
+
import win32ui
|
|
15
|
+
import win32gui
|
|
16
|
+
from ahk import AHK, MsgBoxIcon
|
|
17
|
+
except ImportError as _e:
|
|
18
|
+
from kotonebot.errors import MissingDependencyError
|
|
19
|
+
raise MissingDependencyError(_e, 'windows')
|
|
20
|
+
from cv2.typing import MatLike
|
|
21
|
+
|
|
22
|
+
from ..device import Device, WindowsDevice
|
|
23
|
+
from ..protocol import Commandable, Touchable, Screenshotable
|
|
24
|
+
from ..registration import ImplConfig
|
|
25
|
+
|
|
26
|
+
# 1. 定义配置模型
|
|
27
|
+
@dataclass
|
|
28
|
+
class WindowsImplConfig(ImplConfig):
|
|
29
|
+
window_title: str
|
|
30
|
+
ahk_exe_path: str
|
|
31
|
+
|
|
32
|
+
class WindowsImpl(Touchable, Screenshotable):
|
|
33
|
+
def __init__(self, device: Device, window_title: str, ahk_exe_path: str):
|
|
34
|
+
self.__hwnd: int | None = None
|
|
35
|
+
self.window_title = window_title
|
|
36
|
+
self.ahk = AHK(executable_path=ahk_exe_path)
|
|
37
|
+
self.device = device
|
|
38
|
+
|
|
39
|
+
# 设置 DPI aware,否则高缩放显示器上返回的坐标会错误
|
|
40
|
+
windll.user32.SetProcessDPIAware()
|
|
41
|
+
# TODO: 这个应该移动到其他地方去
|
|
42
|
+
def _stop():
|
|
43
|
+
from kotonebot.backend.context.context import vars
|
|
44
|
+
vars.flow.request_interrupt()
|
|
45
|
+
self.ahk.msg_box('任务已停止。', title='琴音小助手', icon=MsgBoxIcon.EXCLAMATION)
|
|
46
|
+
|
|
47
|
+
def _toggle_pause():
|
|
48
|
+
from kotonebot.backend.context.context import vars
|
|
49
|
+
if vars.flow.is_paused:
|
|
50
|
+
self.ahk.msg_box('任务即将恢复。\n关闭此消息框后将会继续执行', title='琴音小助手', icon=MsgBoxIcon.EXCLAMATION)
|
|
51
|
+
vars.flow.request_resume()
|
|
52
|
+
else:
|
|
53
|
+
vars.flow.request_pause()
|
|
54
|
+
self.ahk.msg_box('任务已暂停。\n关闭此消息框后再按一次快捷键恢复执行。', title='琴音小助手', icon=MsgBoxIcon.EXCLAMATION)
|
|
55
|
+
|
|
56
|
+
self.ahk.add_hotkey('^F4', _toggle_pause) # Ctrl+F4 暂停/恢复
|
|
57
|
+
self.ahk.add_hotkey('^F3', _stop) # Ctrl+F3 停止
|
|
58
|
+
self.ahk.start_hotkeys()
|
|
59
|
+
# 将点击坐标设置为相对 Client
|
|
60
|
+
self.ahk.set_coord_mode('Mouse', 'Client')
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def hwnd(self) -> int:
|
|
64
|
+
if self.__hwnd is None:
|
|
65
|
+
self.__hwnd = win32gui.FindWindow(None, self.window_title)
|
|
66
|
+
if self.__hwnd is None or self.__hwnd == 0:
|
|
67
|
+
raise RuntimeError(f'Failed to find window: {self.window_title}')
|
|
68
|
+
return self.__hwnd
|
|
69
|
+
|
|
70
|
+
def __client_rect(self) -> tuple[int, int, int, int]:
|
|
71
|
+
"""获取 Client 区域屏幕坐标"""
|
|
72
|
+
hwnd = self.hwnd
|
|
73
|
+
client_left, client_top, client_right, client_bottom = win32gui.GetClientRect(hwnd)
|
|
74
|
+
client_left, client_top = win32gui.ClientToScreen(hwnd, (client_left, client_top))
|
|
75
|
+
client_right, client_bottom = win32gui.ClientToScreen(hwnd, (client_right, client_bottom))
|
|
76
|
+
return client_left, client_top, client_right, client_bottom
|
|
77
|
+
|
|
78
|
+
def __client_to_screen(self, hwnd: int, x: int, y: int) -> tuple[int, int]:
|
|
79
|
+
"""将 Client 区域坐标转换为屏幕坐标"""
|
|
80
|
+
return win32gui.ClientToScreen(hwnd, (x, y))
|
|
81
|
+
|
|
82
|
+
def screenshot(self) -> MatLike:
|
|
83
|
+
if not self.ahk.win_is_active(self.window_title):
|
|
84
|
+
self.ahk.win_activate(self.window_title)
|
|
85
|
+
hwnd = self.hwnd
|
|
86
|
+
|
|
87
|
+
# TODO: 需要检查下面这些 WinAPI 的返回结果
|
|
88
|
+
# 获取整个窗口的坐标
|
|
89
|
+
left, top, right, bot = win32gui.GetWindowRect(hwnd)
|
|
90
|
+
w = right - left
|
|
91
|
+
h = bot - top
|
|
92
|
+
|
|
93
|
+
# 获取客户区域的坐标
|
|
94
|
+
client_left, client_top, client_right, client_bot = self.__client_rect()
|
|
95
|
+
|
|
96
|
+
# 获取整个屏幕的截图
|
|
97
|
+
hwndDC = win32gui.GetWindowDC(0)
|
|
98
|
+
mfcDC = win32ui.CreateDCFromHandle(hwndDC)
|
|
99
|
+
saveDC = mfcDC.CreateCompatibleDC()
|
|
100
|
+
|
|
101
|
+
saveBitMap = win32ui.CreateBitmap()
|
|
102
|
+
saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
|
|
103
|
+
|
|
104
|
+
saveDC.SelectObject(saveBitMap)
|
|
105
|
+
|
|
106
|
+
# 截图整个屏幕
|
|
107
|
+
result = windll.gdi32.BitBlt(saveDC.GetSafeHdc(), 0, 0, w, h, mfcDC.GetSafeHdc(), left, top, 0x00CC0020)
|
|
108
|
+
|
|
109
|
+
# 将截图转换为OpenCV格式
|
|
110
|
+
bmpinfo = saveBitMap.GetInfo()
|
|
111
|
+
bmpstr = saveBitMap.GetBitmapBits(True)
|
|
112
|
+
im = np.frombuffer(bmpstr, dtype=np.uint8)
|
|
113
|
+
im = im.reshape((bmpinfo['bmHeight'], bmpinfo['bmWidth'], 4))
|
|
114
|
+
|
|
115
|
+
# 裁剪出客户区域
|
|
116
|
+
cropped_im = im[client_top - top:client_bot - top, client_left - left:client_right - left]
|
|
117
|
+
|
|
118
|
+
# 释放资源
|
|
119
|
+
win32gui.DeleteObject(saveBitMap.GetHandle())
|
|
120
|
+
saveDC.DeleteDC()
|
|
121
|
+
mfcDC.DeleteDC()
|
|
122
|
+
win32gui.ReleaseDC(hwnd, hwndDC)
|
|
123
|
+
|
|
124
|
+
# 将 RGBA 转换为 RGB
|
|
125
|
+
cropped_im = cv2.cvtColor(cropped_im, cv2.COLOR_RGBA2RGB)
|
|
126
|
+
return cropped_im
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def screen_size(self) -> tuple[int, int]:
|
|
130
|
+
left, top, right, bot = self.__client_rect()
|
|
131
|
+
w = right - left
|
|
132
|
+
h = bot - top
|
|
133
|
+
return w, h
|
|
134
|
+
|
|
135
|
+
def detect_orientation(self) -> None | Literal['portrait'] | Literal['landscape']:
|
|
136
|
+
pos = self.ahk.win_get_position(self.window_title)
|
|
137
|
+
if pos is None:
|
|
138
|
+
return None
|
|
139
|
+
w, h = pos.width, pos.height
|
|
140
|
+
if w > h:
|
|
141
|
+
return 'landscape'
|
|
142
|
+
else:
|
|
143
|
+
return 'portrait'
|
|
144
|
+
|
|
145
|
+
def click(self, x: int, y: int) -> None:
|
|
146
|
+
# x, y = self.__client_to_screen(self.hwnd, x, y)
|
|
147
|
+
# (0, 0) 很可能会点到窗口边框上
|
|
148
|
+
if x == 0:
|
|
149
|
+
x = 2
|
|
150
|
+
if y == 0:
|
|
151
|
+
y = 2
|
|
152
|
+
if not self.ahk.win_is_active(self.window_title):
|
|
153
|
+
self.ahk.win_activate(self.window_title)
|
|
154
|
+
self.ahk.click(x, y)
|
|
155
|
+
|
|
156
|
+
def swipe(self, x1: int, y1: int, x2: int, y2: int, duration: float | None = None) -> None:
|
|
157
|
+
if not self.ahk.win_is_active(self.window_title):
|
|
158
|
+
self.ahk.win_activate(self.window_title)
|
|
159
|
+
# TODO: 这个 speed 的单位是什么?
|
|
160
|
+
self.ahk.mouse_drag(x2, y2, from_position=(x1, y1), coord_mode='Client', speed=10)
|
|
161
|
+
|
|
162
|
+
if __name__ == '__main__':
|
|
163
|
+
from ..device import Device
|
|
164
|
+
device = Device()
|
|
165
|
+
# 在测试环境中直接使用默认路径
|
|
166
|
+
ahk_path = str(resources.files('kaa.res.bin') / 'AutoHotkey.exe')
|
|
167
|
+
impl = WindowsImpl(device, window_title='gakumas', ahk_exe_path=ahk_path)
|
|
168
|
+
device._screenshot = impl
|
|
169
|
+
device._touch = impl
|
|
170
|
+
device.swipe_scaled(0.5, 0.8, 0.5, 0.2)
|
|
171
|
+
# impl.swipe(0, 100, 0, 0)
|
|
172
|
+
# impl.click(100, 100)
|
|
173
|
+
# while True:
|
|
174
|
+
# im = impl.screenshot()
|
|
175
|
+
# cv2.imshow('test', im)
|
|
176
|
+
# cv2.waitKey(1)
|
kotonebot/client/protocol.py
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
from typing import Protocol, TYPE_CHECKING, runtime_checkable, Literal
|
|
2
|
-
|
|
3
|
-
from cv2.typing import MatLike
|
|
4
|
-
|
|
5
|
-
from kotonebot.primitives import Rect
|
|
6
|
-
if TYPE_CHECKING:
|
|
7
|
-
from .device import Device
|
|
8
|
-
|
|
9
|
-
@runtime_checkable
|
|
10
|
-
class ClickableObjectProtocol(Protocol):
|
|
11
|
-
"""
|
|
12
|
-
可点击对象的协议
|
|
13
|
-
"""
|
|
14
|
-
@property
|
|
15
|
-
def rect(self) -> Rect:
|
|
16
|
-
...
|
|
17
|
-
|
|
18
|
-
class DeviceScreenshotProtocol(Protocol):
|
|
19
|
-
def screenshot(self) -> MatLike:
|
|
20
|
-
"""
|
|
21
|
-
截图
|
|
22
|
-
"""
|
|
23
|
-
...
|
|
24
|
-
|
|
25
|
-
@runtime_checkable
|
|
26
|
-
class Commandable(Protocol):
|
|
27
|
-
def __init__(self, device: 'Device'): ...
|
|
28
|
-
def launch_app(self, package_name: str) -> None: ...
|
|
29
|
-
def current_package(self) -> str | None: ...
|
|
30
|
-
|
|
31
|
-
@runtime_checkable
|
|
32
|
-
class AndroidCommandable(Protocol):
|
|
33
|
-
"""定义 Android 平台的特定命令"""
|
|
34
|
-
def launch_app(self, package_name: str) -> None: ...
|
|
35
|
-
def current_package(self) -> str | None: ...
|
|
36
|
-
def adb_shell(self, cmd: str) -> str: ...
|
|
37
|
-
|
|
38
|
-
@runtime_checkable
|
|
39
|
-
class WindowsCommandable(Protocol):
|
|
40
|
-
"""定义 Windows 平台的特定命令"""
|
|
41
|
-
def get_foreground_window(self) -> tuple[int, str]: ...
|
|
42
|
-
def exec_command(self, command: str) -> tuple[int, str, str]: ...
|
|
43
|
-
|
|
44
|
-
@runtime_checkable
|
|
45
|
-
class Screenshotable(Protocol):
|
|
46
|
-
def __init__(self, device: 'Device'): ...
|
|
47
|
-
@property
|
|
48
|
-
def screen_size(self) -> tuple[int, int]:
|
|
49
|
-
"""
|
|
50
|
-
屏幕尺寸。格式为 `(width, height)`。
|
|
51
|
-
|
|
52
|
-
**注意**: 此属性返回的分辨率会随设备方向变化。
|
|
53
|
-
如果 `self.orientation` 为 `landscape`,则返回的分辨率是横屏下的分辨率,
|
|
54
|
-
否则返回竖屏下的分辨率。
|
|
55
|
-
|
|
56
|
-
`self.orientation` 属性默认为竖屏。如果需要自动检测,
|
|
57
|
-
调用 `self.detect_orientation()` 方法。
|
|
58
|
-
如果已知方向,也可以直接设置 `self.orientation` 属性。
|
|
59
|
-
"""
|
|
60
|
-
...
|
|
61
|
-
|
|
62
|
-
def detect_orientation(self) -> Literal['portrait', 'landscape'] | None: ...
|
|
63
|
-
def screenshot(self) -> MatLike: ...
|
|
64
|
-
|
|
65
|
-
@runtime_checkable
|
|
66
|
-
class Touchable(Protocol):
|
|
67
|
-
def __init__(self, device: 'Device'): ...
|
|
68
|
-
def click(self, x: int, y: int) -> None: ...
|
|
69
|
-
def swipe(self, x1: int, y1: int, x2: int, y2: int, duration: float|None = None) -> None: ...
|
|
1
|
+
from typing import Protocol, TYPE_CHECKING, runtime_checkable, Literal
|
|
2
|
+
|
|
3
|
+
from cv2.typing import MatLike
|
|
4
|
+
|
|
5
|
+
from kotonebot.primitives import Rect
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from .device import Device
|
|
8
|
+
|
|
9
|
+
@runtime_checkable
|
|
10
|
+
class ClickableObjectProtocol(Protocol):
|
|
11
|
+
"""
|
|
12
|
+
可点击对象的协议
|
|
13
|
+
"""
|
|
14
|
+
@property
|
|
15
|
+
def rect(self) -> Rect:
|
|
16
|
+
...
|
|
17
|
+
|
|
18
|
+
class DeviceScreenshotProtocol(Protocol):
|
|
19
|
+
def screenshot(self) -> MatLike:
|
|
20
|
+
"""
|
|
21
|
+
截图
|
|
22
|
+
"""
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
@runtime_checkable
|
|
26
|
+
class Commandable(Protocol):
|
|
27
|
+
def __init__(self, device: 'Device'): ...
|
|
28
|
+
def launch_app(self, package_name: str) -> None: ...
|
|
29
|
+
def current_package(self) -> str | None: ...
|
|
30
|
+
|
|
31
|
+
@runtime_checkable
|
|
32
|
+
class AndroidCommandable(Protocol):
|
|
33
|
+
"""定义 Android 平台的特定命令"""
|
|
34
|
+
def launch_app(self, package_name: str) -> None: ...
|
|
35
|
+
def current_package(self) -> str | None: ...
|
|
36
|
+
def adb_shell(self, cmd: str) -> str: ...
|
|
37
|
+
|
|
38
|
+
@runtime_checkable
|
|
39
|
+
class WindowsCommandable(Protocol):
|
|
40
|
+
"""定义 Windows 平台的特定命令"""
|
|
41
|
+
def get_foreground_window(self) -> tuple[int, str]: ...
|
|
42
|
+
def exec_command(self, command: str) -> tuple[int, str, str]: ...
|
|
43
|
+
|
|
44
|
+
@runtime_checkable
|
|
45
|
+
class Screenshotable(Protocol):
|
|
46
|
+
def __init__(self, device: 'Device'): ...
|
|
47
|
+
@property
|
|
48
|
+
def screen_size(self) -> tuple[int, int]:
|
|
49
|
+
"""
|
|
50
|
+
屏幕尺寸。格式为 `(width, height)`。
|
|
51
|
+
|
|
52
|
+
**注意**: 此属性返回的分辨率会随设备方向变化。
|
|
53
|
+
如果 `self.orientation` 为 `landscape`,则返回的分辨率是横屏下的分辨率,
|
|
54
|
+
否则返回竖屏下的分辨率。
|
|
55
|
+
|
|
56
|
+
`self.orientation` 属性默认为竖屏。如果需要自动检测,
|
|
57
|
+
调用 `self.detect_orientation()` 方法。
|
|
58
|
+
如果已知方向,也可以直接设置 `self.orientation` 属性。
|
|
59
|
+
"""
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
def detect_orientation(self) -> Literal['portrait', 'landscape'] | None: ...
|
|
63
|
+
def screenshot(self) -> MatLike: ...
|
|
64
|
+
|
|
65
|
+
@runtime_checkable
|
|
66
|
+
class Touchable(Protocol):
|
|
67
|
+
def __init__(self, device: 'Device'): ...
|
|
68
|
+
def click(self, x: int, y: int) -> None: ...
|
|
69
|
+
def swipe(self, x1: int, y1: int, x2: int, y2: int, duration: float|None = None) -> None: ...
|
kotonebot/client/registration.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import TypeVar, Callable, Dict, Type, Any, overload, Literal, cast, TYPE_CHECKING
|
|
3
|
-
|
|
4
|
-
from ..errors import KotonebotError
|
|
5
|
-
from .device import Device
|
|
6
|
-
if TYPE_CHECKING:
|
|
7
|
-
from .implements.adb import AdbImplConfig
|
|
8
|
-
from .implements.remote_windows import RemoteWindowsImplConfig
|
|
9
|
-
from .implements.windows import WindowsImplConfig
|
|
10
|
-
from .implements.nemu_ipc import NemuIpcImplConfig
|
|
11
|
-
|
|
12
|
-
AdbBasedImpl = Literal['adb', 'adb_raw', 'uiautomator2']
|
|
13
|
-
DeviceImpl = str | AdbBasedImpl | Literal['windows', 'remote_windows', 'nemu_ipc']
|
|
14
|
-
|
|
15
|
-
# --- 核心类型定义 ---
|
|
16
|
-
|
|
17
|
-
class ImplRegistrationError(KotonebotError):
|
|
18
|
-
"""与 impl 注册相关的错误"""
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
@dataclass
|
|
22
|
-
class ImplConfig:
|
|
23
|
-
"""所有设备实现配置模型的名义上的基类,便于类型约束。"""
|
|
24
|
-
pass
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import TypeVar, Callable, Dict, Type, Any, overload, Literal, cast, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from ..errors import KotonebotError
|
|
5
|
+
from .device import Device
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from .implements.adb import AdbImplConfig
|
|
8
|
+
from .implements.remote_windows import RemoteWindowsImplConfig
|
|
9
|
+
from .implements.windows import WindowsImplConfig
|
|
10
|
+
from .implements.nemu_ipc import NemuIpcImplConfig
|
|
11
|
+
|
|
12
|
+
AdbBasedImpl = Literal['adb', 'adb_raw', 'uiautomator2']
|
|
13
|
+
DeviceImpl = str | AdbBasedImpl | Literal['windows', 'remote_windows', 'nemu_ipc']
|
|
14
|
+
|
|
15
|
+
# --- 核心类型定义 ---
|
|
16
|
+
|
|
17
|
+
class ImplRegistrationError(KotonebotError):
|
|
18
|
+
"""与 impl 注册相关的错误"""
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class ImplConfig:
|
|
23
|
+
"""所有设备实现配置模型的名义上的基类,便于类型约束。"""
|
|
24
|
+
pass
|