chore: update python API (#9538)

* chore: update python API

* fix: remove non-exist return value

* style: docstring of param of set_static_option

* feat: python API get_image
This commit is contained in:
EvATive7
2024-07-08 21:52:01 +08:00
committed by GitHub
parent b59f47d87e
commit e6555b4e44
2 changed files with 65 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ import pathlib
import platform
from typing import Union, Optional
from .utils import InstanceOptionType, JSON
from .utils import InstanceOptionType, StaticOptionType, JSON
class Asst:
@@ -110,6 +110,19 @@ class Asst:
return Asst.__lib.AsstSetInstanceOption(self.__ptr,
int(option_type), option_value.encode('utf-8'))
def set_static_option(option_type: StaticOptionType, option_value: str):
"""
设置进程级参数
参见${MaaAssistantArknights}/src/MaaCore/Assistant.cpp#set_static_option
:params:
``option_type``: 进程级参数类型
``option_value``: 进程级参数的值
:return: 是否设置成功
"""
return Asst.__lib.AsstSetStaticOption(int(option_type), option_value.encode('utf-8'))
def connect(self, adb_path: str, address: str, config: str = 'General'):
"""
连接设备
@@ -124,6 +137,33 @@ class Asst:
return Asst.__lib.AsstConnect(self.__ptr,
adb_path.encode('utf-8'), address.encode('utf-8'), config.encode('utf-8'))
def get_image(self, size: int) -> bytes | None:
"""
获取上次截图
:params:
``size``: 图像字节数, 如 1280*720*3
: return: 成功时图像的字节; 失败时 None
"""
buffer_type = ctypes.c_byte * size
buffer = buffer_type()
buffer.value = b'\000' * size
if (got := Asst.__lib.AsstGetImage(self.__ptr, buffer, size)) \
and got > 0:
return bytes(buffer)
else:
return None
def set_connection_extras(name: str, extras: JSON):
"""
连接模拟器端的Extras
:params:
``name``: Extras名称
``extras``: Extras配置
"""
Asst.__lib.AsstSetConnectionExtras(name.encode('utf-8'), json.dumps(extras, ensure_ascii=False).encode('utf-8'))
TaskId = int
def append_task(self, type_name: str, params: JSON = {}) -> TaskId:
@@ -205,6 +245,18 @@ class Asst:
Asst.__lib.AsstLoadResource.argtypes = (
ctypes.c_char_p,)
Asst.__lib.AsstSetStaticOption.restype = ctypes.c_bool
Asst.__lib.AsstSetStaticOption.argtypes = (
ctypes.c_int, ctypes.c_char_p,)
Asst.__lib.AsstSetConnectionExtras.restype = ctypes.c_void_p
Asst.__lib.AsstSetConnectionExtras.argtypes = (
ctypes.c_char_p, ctypes.c_char_p,)
Asst.__lib.AsstGetImage.restype = ctypes.c_uint64
Asst.__lib.AsstGetImage.argtypes = (
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint64)
Asst.__lib.AsstCreate.restype = ctypes.c_void_p
Asst.__lib.AsstCreate.argtypes = ()
@@ -222,6 +274,10 @@ class Asst:
Asst.__lib.AsstConnect.argtypes = (
ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p,)
Asst.__lib.AsstAsyncConnect.restype = ctypes.c_int
Asst.__lib.AsstAsyncConnect.argtypes = (
ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_bool)
Asst.__lib.AsstAppendTask.restype = ctypes.c_int
Asst.__lib.AsstAppendTask.argtypes = (
ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p)

View File

@@ -7,6 +7,14 @@ JSON = Union[Dict[str, Any], List[Any], int, str, float, bool, Type[None]]
class InstanceOptionType(IntEnum):
touch_type = 2
deployment_with_pause = 3
adblite_enabled = 4
kill_on_adb_exit = 5
class StaticOptionType(IntEnum):
invalid = 0
cpu_ocr = 1
gpu_ocr = 2
@unique