WechatOnCloud/bridge/woc_bridge/ui/locators/base.py
Kris 15fc62d478 feat: 完成微信UI自动化新架构全量开发与集成
- 新增六层UI自动化架构:从Backend到Capabilities的完整分层实现
- 添加WeChat 4.0分辨率适配Profile与图像模板资源
- 实现幂等缓存、熔断器、重试策略、链路追踪与监控指标
- 新增头像下载安全校验、发布朋友圈路径白名单防护
- 优化密钥缓存、DB校验逻辑与初始化流程
- 补充完整错误码体系与启动清场机制
2026-07-16 01:19:47 +08:00

81 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""L2 Locator 抽象层基类GeomSpec + Selector + ElementHandle。
GeomSpec几何定位规格relative_to / ratio / offset
SelectorUI 元素选择器kind / by_image / by_geom / threshold / require_image
ElementHandle定位结果句柄绝对坐标 + 置信度 + 策略)
L3 Actions 通过 Selector 描述要找的元素LocatorRegistry 解析为
ElementHandle图像命中或几何兜底Actions 据此调 Backend 执行点击。
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional
@dataclass
class GeomSpec:
"""几何定位规格。
relative_to 取值window / window_top_left / window_bottom_right语义占位
实际计算统一用 ratio + offsetoffset 已含正负号区分方向)。
所有字段带默认值,避免构造时必填字段顺序问题。
"""
relative_to: str = "window"
x_ratio: float = 0.0
y_ratio: float = 0.0
x_offset: int = 0
y_offset: int = 0
@dataclass
class Selector:
"""UI 元素选择器。
kind元素类别键如 search_box / send_button / input_box
by_image图像模板名P2 启用),非空时优先图像匹配
by_geom几何规格非空时图像失败或 P1 阶段走几何兜底
threshold图像匹配置信度阈值默认 0.80
require_image高风险操作为 True 时,图像失败即拒绝执行
description人类可读描述
所有字段带默认值。
"""
kind: str = ""
by_image: Optional[str] = None
by_geom: Optional[GeomSpec] = None
threshold: float = 0.80
require_image: bool = False
description: str = ""
@dataclass
class ElementHandle:
"""定位结果句柄。
selector来源 Selector回溯用
x / y元素中心绝对坐标点击点
w / h元素宽高图像匹配时返回几何兜底为 0
confidence匹配置信度图像命中时为模型分数几何兜底为 1.0
strategy定位策略 image / geom
所有字段带默认值。
"""
selector: Optional[Selector] = None
x: int = 0
y: int = 0
w: int = 0
h: int = 0
confidence: float = 1.0
strategy: str = "geom"
@property
def center(self) -> tuple[int, int]:
"""返回元素中心点x, y"""
return (self.x, self.y)