MaaFw 2.2.0b2__py3-none-macosx_13_0_x86_64.whl → 5.3.0b2__py3-none-macosx_13_0_x86_64.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.
Files changed (47) hide show
  1. maa/__init__.py +7 -5
  2. maa/agent/__init__.py +12 -0
  3. maa/agent/agent_server.py +237 -0
  4. maa/agent_client.py +218 -0
  5. maa/bin/libMaaAdbControlUnit.dylib +0 -0
  6. maa/bin/libMaaAgentClient.dylib +0 -0
  7. maa/bin/libMaaAgentServer.dylib +0 -0
  8. maa/bin/libMaaCustomControlUnit.dylib +0 -0
  9. maa/bin/libMaaFramework.dylib +0 -0
  10. maa/bin/libMaaToolkit.dylib +0 -0
  11. maa/bin/libMaaUtils.dylib +0 -0
  12. maa/bin/libfastdeploy_ppocr.dylib +0 -0
  13. maa/bin/{libopencv_world4.4.8.0.dylib → libonnxruntime.1.19.2.dylib} +0 -0
  14. maa/bin/{libonnxruntime.1.18.0.dylib → libopencv_world4.4.11.0.dylib} +0 -0
  15. maa/bin/plugins/libMaaPluginDemo.dylib +0 -0
  16. maa/buffer.py +133 -153
  17. maa/context.py +441 -34
  18. maa/controller.py +581 -107
  19. maa/custom_action.py +6 -3
  20. maa/custom_recognition.py +25 -11
  21. maa/define.py +355 -39
  22. maa/event_sink.py +73 -0
  23. maa/job.py +12 -5
  24. maa/library.py +103 -43
  25. maa/pipeline.py +492 -0
  26. maa/resource.py +505 -72
  27. maa/tasker.py +652 -149
  28. maa/toolkit.py +95 -165
  29. maafw-5.3.0b2.dist-info/METADATA +288 -0
  30. maafw-5.3.0b2.dist-info/RECORD +32 -0
  31. maafw-5.3.0b2.dist-info/WHEEL +4 -0
  32. MaaFw-2.2.0b2.dist-info/METADATA +0 -174
  33. MaaFw-2.2.0b2.dist-info/RECORD +0 -35
  34. MaaFw-2.2.0b2.dist-info/WHEEL +0 -4
  35. MaaFw-2.2.0b2.dist-info/top_level.txt +0 -1
  36. maa/bin/libMaaDbgControlUnit.dylib +0 -0
  37. maa/bin/libc++.1.0.dylib +0 -0
  38. maa/bin/libc++.1.dylib +0 -0
  39. maa/bin/libc++.dylib +0 -0
  40. maa/bin/libc++abi.1.0.dylib +0 -0
  41. maa/bin/libc++abi.1.dylib +0 -0
  42. maa/bin/libc++abi.dylib +0 -0
  43. maa/bin/libunwind.1.0.dylib +0 -0
  44. maa/bin/libunwind.1.dylib +0 -0
  45. maa/bin/libunwind.dylib +0 -0
  46. maa/notification_handler.py +0 -191
  47. {MaaFw-2.2.0b2.dist-info → maafw-5.3.0b2.dist-info/licenses}/LICENSE.md +0 -0
maa/__init__.py CHANGED
@@ -1,10 +1,12 @@
1
1
  import os
2
+ from pathlib import Path
2
3
 
3
4
  from .library import Library
4
5
 
5
- __PATH = os.path.join(os.path.dirname(__file__), "bin")
6
+ env_path = os.environ.get("MAAFW_BINARY_PATH")
7
+ if env_path:
8
+ __PATH = Path(env_path)
9
+ else:
10
+ __PATH = Path(Path(__file__).parent, "bin")
6
11
 
7
- if os.path.exists(__PATH):
8
- ver = Library.open(__PATH)
9
- if ver:
10
- print(f"MaaFw version: {ver}")
12
+ Library.open(__PATH, agent_server=False)
maa/agent/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ import os
2
+ from pathlib import Path
3
+
4
+ from ..library import Library
5
+
6
+ env_path = os.environ.get("MAAFW_BINARY_PATH")
7
+ if env_path:
8
+ __PATH = Path(env_path)
9
+ else:
10
+ __PATH = Path(Path(__file__).parent.parent, "bin")
11
+
12
+ Library.open(__PATH, agent_server=True)
@@ -0,0 +1,237 @@
1
+ import ctypes
2
+
3
+ from ..define import *
4
+ from ..library import Library
5
+ from ..event_sink import EventSink
6
+
7
+
8
+ class AgentServer:
9
+
10
+ @staticmethod
11
+ def custom_recognition(name: str):
12
+
13
+ def wrapper_recognition(recognition):
14
+ AgentServer.register_custom_recognition(
15
+ name=name, recognition=recognition()
16
+ )
17
+ return recognition
18
+
19
+ return wrapper_recognition
20
+
21
+ _custom_recognition_holder = {}
22
+
23
+ @staticmethod
24
+ def register_custom_recognition(
25
+ name: str, recognition: "CustomRecognition" # type: ignore
26
+ ) -> bool:
27
+
28
+ AgentServer._set_api_properties()
29
+
30
+ # avoid gc
31
+ AgentServer._custom_recognition_holder[name] = recognition
32
+
33
+ return bool(
34
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition(
35
+ name.encode(),
36
+ recognition.c_handle,
37
+ recognition.c_arg,
38
+ )
39
+ )
40
+
41
+ @staticmethod
42
+ def custom_action(name: str):
43
+
44
+ def wrapper_action(action):
45
+ AgentServer.register_custom_action(name=name, action=action())
46
+ return action
47
+
48
+ return wrapper_action
49
+
50
+ _custom_action_holder = {}
51
+
52
+ @staticmethod
53
+ def register_custom_action(name: str, action: "CustomAction") -> bool: # type: ignore
54
+
55
+ AgentServer._set_api_properties()
56
+
57
+ # avoid gc
58
+ AgentServer._custom_action_holder[name] = action
59
+
60
+ return bool(
61
+ Library.agent_server().MaaAgentServerRegisterCustomAction(
62
+ name.encode(),
63
+ action.c_handle,
64
+ action.c_arg,
65
+ )
66
+ )
67
+
68
+ @staticmethod
69
+ def start_up(identifier: str) -> bool:
70
+
71
+ AgentServer._set_api_properties()
72
+
73
+ return bool(Library.agent_server().MaaAgentServerStartUp(identifier.encode()))
74
+
75
+ @staticmethod
76
+ def shut_down() -> None:
77
+
78
+ AgentServer._set_api_properties()
79
+
80
+ Library.agent_server().MaaAgentServerShutDown()
81
+
82
+ @staticmethod
83
+ def join() -> None:
84
+
85
+ AgentServer._set_api_properties()
86
+
87
+ Library.agent_server().MaaAgentServerJoin()
88
+
89
+ @staticmethod
90
+ def detach() -> None:
91
+
92
+ AgentServer._set_api_properties()
93
+
94
+ Library.agent_server().MaaAgentServerDetach()
95
+
96
+ _sink_holder: Dict[int, "EventSink"] = {}
97
+
98
+ @staticmethod
99
+ def resource_sink():
100
+ def wrapper_sink(sink):
101
+ AgentServer.add_resource_sink(sink=sink())
102
+ return sink
103
+
104
+ return wrapper_sink
105
+
106
+ @staticmethod
107
+ def add_resource_sink(sink: "ResourceEventSink") -> None:
108
+ sink_id = int(
109
+ Library.agent_server().MaaAgentServerAddResourceSink(
110
+ *EventSink._gen_c_param(sink)
111
+ )
112
+ )
113
+ if sink_id == MaaInvalidId:
114
+ return None
115
+
116
+ AgentServer._sink_holder[sink_id] = sink
117
+
118
+ @staticmethod
119
+ def controller_sink():
120
+ def wrapper_sink(sink):
121
+ AgentServer.add_controller_sink(sink=sink())
122
+ return sink
123
+
124
+ return wrapper_sink
125
+
126
+ @staticmethod
127
+ def add_controller_sink(sink: "ControllerEventSink") -> None:
128
+ sink_id = int(
129
+ Library.agent_server().MaaAgentServerAddControllerSink(
130
+ *EventSink._gen_c_param(sink)
131
+ )
132
+ )
133
+ if sink_id == MaaInvalidId:
134
+ return None
135
+
136
+ AgentServer._sink_holder[sink_id] = sink
137
+
138
+ @staticmethod
139
+ def tasker_sink():
140
+ def wrapper_sink(sink):
141
+ AgentServer.add_tasker_sink(sink=sink())
142
+ return sink
143
+
144
+ return wrapper_sink
145
+
146
+ @staticmethod
147
+ def add_tasker_sink(sink: "TaskerEventSink") -> None:
148
+ sink_id = int(
149
+ Library.agent_server().MaaAgentServerAddTaskerSink(
150
+ *EventSink._gen_c_param(sink)
151
+ )
152
+ )
153
+ if sink_id == MaaInvalidId:
154
+ return None
155
+
156
+ AgentServer._sink_holder[sink_id] = sink
157
+
158
+ @staticmethod
159
+ def context_sink():
160
+ def wrapper_sink(sink):
161
+ AgentServer.add_context_sink(sink=sink())
162
+ return sink
163
+
164
+ return wrapper_sink
165
+
166
+ @staticmethod
167
+ def add_context_sink(sink: "ContextEventSink") -> None:
168
+ sink_id = int(
169
+ Library.agent_server().MaaAgentServerAddContextSink(
170
+ *EventSink._gen_c_param(sink)
171
+ )
172
+ )
173
+ if sink_id == MaaInvalidId:
174
+ return None
175
+
176
+ AgentServer._sink_holder[sink_id] = sink
177
+
178
+ _api_properties_initialized: bool = False
179
+
180
+ @staticmethod
181
+ def _set_api_properties():
182
+ if AgentServer._api_properties_initialized:
183
+ return
184
+
185
+ AgentServer._api_properties_initialized = True
186
+
187
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition.restype = MaaBool
188
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition.argtypes = [
189
+ ctypes.c_char_p,
190
+ MaaCustomRecognitionCallback,
191
+ ctypes.c_void_p,
192
+ ]
193
+
194
+ Library.agent_server().MaaAgentServerRegisterCustomAction.restype = MaaBool
195
+ Library.agent_server().MaaAgentServerRegisterCustomAction.argtypes = [
196
+ ctypes.c_char_p,
197
+ MaaCustomActionCallback,
198
+ ctypes.c_void_p,
199
+ ]
200
+
201
+ Library.agent_server().MaaAgentServerStartUp.restype = MaaBool
202
+ Library.agent_server().MaaAgentServerStartUp.argtypes = [
203
+ ctypes.c_char_p,
204
+ ]
205
+
206
+ Library.agent_server().MaaAgentServerShutDown.restype = None
207
+ Library.agent_server().MaaAgentServerShutDown.argtypes = []
208
+
209
+ Library.agent_server().MaaAgentServerJoin.restype = None
210
+ Library.agent_server().MaaAgentServerJoin.argtypes = []
211
+
212
+ Library.agent_server().MaaAgentServerDetach.restype = None
213
+ Library.agent_server().MaaAgentServerDetach.argtypes = []
214
+
215
+ Library.agent_server().MaaAgentServerAddResourceSink.restype = MaaSinkId
216
+ Library.agent_server().MaaAgentServerAddResourceSink.argtypes = [
217
+ MaaEventCallback,
218
+ ctypes.c_void_p,
219
+ ]
220
+
221
+ Library.agent_server().MaaAgentServerAddControllerSink.restype = MaaSinkId
222
+ Library.agent_server().MaaAgentServerAddControllerSink.argtypes = [
223
+ MaaEventCallback,
224
+ ctypes.c_void_p,
225
+ ]
226
+
227
+ Library.agent_server().MaaAgentServerAddTaskerSink.restype = MaaSinkId
228
+ Library.agent_server().MaaAgentServerAddTaskerSink.argtypes = [
229
+ MaaEventCallback,
230
+ ctypes.c_void_p,
231
+ ]
232
+
233
+ Library.agent_server().MaaAgentServerAddContextSink.restype = MaaSinkId
234
+ Library.agent_server().MaaAgentServerAddContextSink.argtypes = [
235
+ MaaEventCallback,
236
+ ctypes.c_void_p,
237
+ ]
maa/agent_client.py ADDED
@@ -0,0 +1,218 @@
1
+ import ctypes
2
+ from typing import List
3
+
4
+ from .define import *
5
+ from .library import Library
6
+ from .resource import Resource
7
+ from .controller import Controller
8
+ from .tasker import Tasker
9
+ from .buffer import StringBuffer, StringListBuffer
10
+
11
+
12
+ class AgentClient:
13
+ _handle: MaaAgentClientHandle
14
+
15
+ def __init__(self, identifier: Optional[str] = None):
16
+ self._set_api_properties()
17
+
18
+ if identifier:
19
+ id_buffer = StringBuffer()
20
+ id_buffer.set(identifier)
21
+ id_buffer_handle = id_buffer._handle
22
+ else:
23
+ id_buffer_handle = None
24
+
25
+ self._handle = Library.agent_client().MaaAgentClientCreateV2(id_buffer_handle)
26
+ if not self._handle:
27
+ raise RuntimeError("Failed to create agent client.")
28
+
29
+ def __del__(self):
30
+ if self._handle:
31
+ Library.agent_client().MaaAgentClientDestroy(self._handle)
32
+
33
+ @property
34
+ def identifier(self) -> Optional[str]:
35
+ id_buffer = StringBuffer()
36
+ if not Library.agent_client().MaaAgentClientIdentifier(
37
+ self._handle, id_buffer._handle
38
+ ):
39
+ return None
40
+
41
+ return id_buffer.get()
42
+
43
+ def bind(self, resource: Resource) -> bool:
44
+ # avoid gc
45
+ self._resource = resource
46
+
47
+ return bool(
48
+ Library.agent_client().MaaAgentClientBindResource(
49
+ self._handle, resource._handle
50
+ )
51
+ )
52
+
53
+ def register_sink(
54
+ self, resource: Resource, controller: Controller, tasker: Tasker
55
+ ) -> bool:
56
+ # avoid gc
57
+ self._sinks = [resource, controller, tasker]
58
+
59
+ return (
60
+ bool(
61
+ Library.agent_client().MaaAgentClientRegisterResourceSink(
62
+ self._handle, resource._handle
63
+ )
64
+ )
65
+ and bool(
66
+ Library.agent_client().MaaAgentClientRegisterControllerSink(
67
+ self._handle, controller._handle
68
+ )
69
+ )
70
+ and bool(
71
+ Library.agent_client().MaaAgentClientRegisterTaskerSink(
72
+ self._handle, tasker._handle
73
+ )
74
+ )
75
+ )
76
+
77
+ def connect(self) -> bool:
78
+ return bool(Library.agent_client().MaaAgentClientConnect(self._handle))
79
+
80
+ def disconnect(self) -> bool:
81
+ return bool(Library.agent_client().MaaAgentClientDisconnect(self._handle))
82
+
83
+ @property
84
+ def connected(self) -> bool:
85
+ return bool(Library.agent_client().MaaAgentClientConnected(self._handle))
86
+
87
+ @property
88
+ def alive(self) -> bool:
89
+ return bool(Library.agent_client().MaaAgentClientAlive(self._handle))
90
+
91
+ def set_timeout(self, milliseconds: int) -> bool:
92
+ return bool(
93
+ Library.agent_client().MaaAgentClientSetTimeout(
94
+ self._handle, ctypes.c_int64(milliseconds)
95
+ )
96
+ )
97
+
98
+ @property
99
+ def custom_recognition_list(self) -> List[str]:
100
+ """获取已注册的自定义识别器列表 / Get registered custom recognizer list
101
+
102
+ Returns:
103
+ list[str]: 自定义识别器名列表 / List of custom recognizer names
104
+
105
+ Raises:
106
+ RuntimeError: 如果获取失败
107
+ """
108
+ buffer = StringListBuffer()
109
+ if not Library.agent_client().MaaAgentClientGetCustomRecognitionList(
110
+ self._handle, buffer._handle
111
+ ):
112
+ raise RuntimeError("Failed to get custom recognition list.")
113
+ return buffer.get()
114
+
115
+ @property
116
+ def custom_action_list(self) -> List[str]:
117
+ """获取已注册的自定义操作列表 / Get registered custom action list
118
+
119
+ Returns:
120
+ list[str]: 自定义操作名列表 / List of custom action names
121
+
122
+ Raises:
123
+ RuntimeError: 如果获取失败
124
+ """
125
+ buffer = StringListBuffer()
126
+ if not Library.agent_client().MaaAgentClientGetCustomActionList(
127
+ self._handle, buffer._handle
128
+ ):
129
+ raise RuntimeError("Failed to get custom action list.")
130
+ return buffer.get()
131
+
132
+ _api_properties_initialized: bool = False
133
+
134
+ @staticmethod
135
+ def _set_api_properties():
136
+ if AgentClient._api_properties_initialized:
137
+ return
138
+
139
+ if Library.is_agent_server():
140
+ raise RuntimeError("AgentClient is not available in AgentServer.")
141
+
142
+ AgentClient._api_properties_initialized = True
143
+
144
+ Library.agent_client().MaaAgentClientCreateV2.restype = MaaAgentClientHandle
145
+ Library.agent_client().MaaAgentClientCreateV2.argtypes = [
146
+ MaaStringBufferHandle,
147
+ ]
148
+
149
+ Library.agent_client().MaaAgentClientIdentifier.restype = MaaBool
150
+ Library.agent_client().MaaAgentClientIdentifier.argtypes = [
151
+ MaaAgentClientHandle,
152
+ MaaStringBufferHandle,
153
+ ]
154
+
155
+ Library.agent_client().MaaAgentClientDestroy.restype = None
156
+ Library.agent_client().MaaAgentClientDestroy.argtypes = [MaaAgentClientHandle]
157
+
158
+ Library.agent_client().MaaAgentClientBindResource.restype = MaaBool
159
+ Library.agent_client().MaaAgentClientBindResource.argtypes = [
160
+ MaaAgentClientHandle,
161
+ MaaResourceHandle,
162
+ ]
163
+
164
+ Library.agent_client().MaaAgentClientRegisterResourceSink.restype = MaaBool
165
+ Library.agent_client().MaaAgentClientRegisterResourceSink.argtypes = [
166
+ MaaAgentClientHandle,
167
+ MaaResourceHandle,
168
+ ]
169
+
170
+ Library.agent_client().MaaAgentClientRegisterControllerSink.restype = MaaBool
171
+ Library.agent_client().MaaAgentClientRegisterControllerSink.argtypes = [
172
+ MaaAgentClientHandle,
173
+ MaaControllerHandle,
174
+ ]
175
+
176
+ Library.agent_client().MaaAgentClientRegisterTaskerSink.restype = MaaBool
177
+ Library.agent_client().MaaAgentClientRegisterTaskerSink.argtypes = [
178
+ MaaAgentClientHandle,
179
+ MaaTaskerHandle,
180
+ ]
181
+
182
+ Library.agent_client().MaaAgentClientConnect.restype = MaaBool
183
+ Library.agent_client().MaaAgentClientConnect.argtypes = [
184
+ MaaAgentClientHandle,
185
+ ]
186
+
187
+ Library.agent_client().MaaAgentClientDisconnect.restype = MaaBool
188
+ Library.agent_client().MaaAgentClientDisconnect.argtypes = [
189
+ MaaAgentClientHandle,
190
+ ]
191
+
192
+ Library.agent_client().MaaAgentClientConnected.restype = MaaBool
193
+ Library.agent_client().MaaAgentClientConnected.argtypes = [
194
+ MaaAgentClientHandle,
195
+ ]
196
+
197
+ Library.agent_client().MaaAgentClientAlive.restype = MaaBool
198
+ Library.agent_client().MaaAgentClientAlive.argtypes = [
199
+ MaaAgentClientHandle,
200
+ ]
201
+
202
+ Library.agent_client().MaaAgentClientSetTimeout.restype = MaaBool
203
+ Library.agent_client().MaaAgentClientSetTimeout.argtypes = [
204
+ MaaAgentClientHandle,
205
+ ctypes.c_int64,
206
+ ]
207
+
208
+ Library.agent_client().MaaAgentClientGetCustomRecognitionList.restype = MaaBool
209
+ Library.agent_client().MaaAgentClientGetCustomRecognitionList.argtypes = [
210
+ MaaAgentClientHandle,
211
+ MaaStringListBufferHandle,
212
+ ]
213
+
214
+ Library.agent_client().MaaAgentClientGetCustomActionList.restype = MaaBool
215
+ Library.agent_client().MaaAgentClientGetCustomActionList.argtypes = [
216
+ MaaAgentClientHandle,
217
+ MaaStringListBufferHandle,
218
+ ]
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
maa/bin/libMaaUtils.dylib CHANGED
Binary file
Binary file
Binary file