Files
kefu/wechat_rpa/tmp/probe_input_blank.py
T
2026-07-31 11:48:16 +08:00

71 lines
3.0 KiB
Python

"""只读诊断:为什么 _input_editor_looks_blank() 认不出空输入框。"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import numpy as np
from PIL import Image, ImageDraw
import wechat_bot as bot_module
_HERE = os.path.dirname(os.path.abspath(__file__))
def main():
bot = bot_module.WeChatBot()
bot.safe_window_mode = True
bot.auto_activate_window = True
if not bot.connect(activate=False, wait_if_missing=False):
print("[-] 未挂载到企业微信窗口")
return
print(f"_ensure_visible(): {bot._ensure_visible()}")
full = bot._capture_full_window()
bot._refresh_message_geometry(full)
full = bot._capture_full_window()
scale = max(0.75, float(getattr(bot, "scale", 1.0) or 1.0))
height, width = full.shape[:2]
print(f"窗口画面 : {width}x{height} scale={scale}")
print(f"_composer_geometry_valid: {getattr(bot, '_composer_geometry_valid', None)}")
print(f"_composer_rel_top : {getattr(bot, '_composer_rel_top', None)}")
print(f"_editor_rel_top : {getattr(bot, '_editor_rel_top', None)}")
print(f"输入框点击点(屏幕) : ({bot.input_x}, {bot.input_y})")
print(f"输入框点击点(窗口内) : ({bot.input_x - bot.L}, {bot.input_y - bot.T})")
x1 = max(0, int(bot._list_x + bot._list_w + 16 * scale))
x2 = min(width, width - int(160 * scale))
y1 = max(0, int(getattr(bot, "_composer_rel_top", height)) + int(42 * scale))
y2 = min(height, height - int(10 * scale))
print(f"编辑区采样框 : x {x1}~{x2} y {y1}~{y2} ({x2 - x1}x{y2 - y1})")
body = full[y1:y2, x1:x2, :3].astype(np.int16)
background = np.median(body.reshape(-1, body.shape[2]), axis=0)
active = np.max(np.abs(body - background), axis=2) >= 18
active_columns = int(active.any(axis=0).sum())
limit = max(4, int(np.ceil(3.5 * scale)))
print(f"背景中位色 : {background.tolist()}")
print(f"活跃列数 : {active_columns} 阈值 <= {limit}")
print(f"判定 : {'空' if active_columns <= limit else '非空(会被当成人工草稿/焦点不明)'}")
print(f"_input_editor_looks_blank(): {bot._input_editor_looks_blank()}")
cols = np.flatnonzero(active.any(axis=0))
if cols.size:
print(f"活跃列窗口内 x 范围: {x1 + int(cols.min())} ~ {x1 + int(cols.max())}")
rows = np.flatnonzero(active.any(axis=1))
print(f"活跃行窗口内 y 范围: {y1 + int(rows.min())} ~ {y1 + int(rows.max())}")
crop = Image.fromarray(full[y1:y2, x1:x2, :3][:, :, ::-1])
crop.save(os.path.join(_HERE, "input_editor_crop.png"))
marked = Image.fromarray(full[:, :, :3][:, :, ::-1])
draw = ImageDraw.Draw(marked)
draw.rectangle([x1, y1, x2, y2], outline=(255, 0, 0), width=4)
marked.save(os.path.join(_HERE, "input_editor_probe.png"))
print("采样区裁剪图: tmp/input_editor_crop.png")
print("整窗标注图 : tmp/input_editor_probe.png")
if __name__ == "__main__":
main()