From 7d63a3612550302623d20ac17a7ed7ac69ee5d90 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 10:00:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=20log=5Fcolor=5Fconfig=5Ffixed.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit log_color_config.py (540行) 与 log_color_config_fixed.py (198行) 的 get_operation_type / get_color_config / apply_operation_color 行为完全一致。 保留前者(更完整),删除后者,简化 actions_log_viewer.py 的双 try import。 Co-Authored-By: Claude Opus 4.5 --- gui/components/actions_log_viewer.py | 16 +- gui/components/log_color_config_fixed.py | 198 ----------------------- 2 files changed, 4 insertions(+), 210 deletions(-) delete mode 100644 gui/components/log_color_config_fixed.py diff --git a/gui/components/actions_log_viewer.py b/gui/components/actions_log_viewer.py index 159e0e8..04c1df2 100644 --- a/gui/components/actions_log_viewer.py +++ b/gui/components/actions_log_viewer.py @@ -13,23 +13,15 @@ import os from typing import List try: - from gui.components.log_color_config_fixed import ( + from gui.components.log_color_config import ( get_operation_type, get_color_config, apply_operation_color, ) except Exception: - # 回退到旧配置模块名(兼容旧代码) - try: - from gui.components.log_color_config import ( - get_operation_type, - get_color_config, - apply_operation_color, - ) - except Exception: - get_operation_type = None - get_color_config = None - apply_operation_color = None + get_operation_type = None + get_color_config = None + apply_operation_color = None try: from ttkbootstrap.scrolled import ScrolledText as TBSrolledText diff --git a/gui/components/log_color_config_fixed.py b/gui/components/log_color_config_fixed.py deleted file mode 100644 index 36551b4..0000000 --- a/gui/components/log_color_config_fixed.py +++ /dev/null @@ -1,198 +0,0 @@ -""" -日志颜色配置模块 -================ - -为不同的操作类型定义颜色标签,支持明亮和暗色主题。 -""" - -from typing import Dict, Optional - - -# 操作类型关键词映射(用于识别日志中的操作类型) -OPERATION_KEYWORDS: Dict[str, list] = { - "ocr": [ - "OCR", "ocr", "识别", "读取", "analyse_pic_word", "识别成功", "识别失败", - "直播间标题", "福袋内容", "福袋倒计时", "福袋价值", "参与人数", "开奖结果" - ], - "click": [ - "点击", "click", "点击成功", "点击失败", "参与按钮", "福袋图标", - "返回", "确认", "关闭", "发送", "加入" - ], - "swipe": [ - "滑动", "swipe", "向上滑动", "向下滑动", "向左滑动", "向右滑动", - "回退", "切换直播间", "切换房间" - ], - "screenshot": [ - "截图", "screenshot", "get_screenshot", "保存截图", "截图成功", "截图失败" - ], - "detection": [ - "检测", "detect", "阶段检测", "阶段诊断", "像素检测", "模板匹配", - "检测成功", "检测失败", "匹配成功", "匹配失败", "识别到", "未识别到" - ], - "decision": [ - "决策", "判断", "决定", "选择", "跳过", "参与", "不参与", "筛选", - "价值过低", "人数过少", "人数过多", "倒计时", "内容不符合" - ], - "reservation": [ - "预约", "reservation", "记录预约", "回退到预约", "预约窗口", "预约队列", - "高价值预约", "预约回退", "预约校验" - ], - "fansclub": [ - "粉丝团", "fansclub", "加入粉丝团", "粉丝团失败", "粉丝团成功" - ], - "lottery": [ - "开奖", "lottery", "中奖", "未中奖", "抽奖结果", "等待开奖", "开奖时间" - ], - "stage": [ - "阶段", "stage", "IN_LIVE_ROOM", "FUDai_DETAIL", "RECOMMEND_PAGE", - "LIVE_OR_UNKNOWN", "阶段变化", "阶段流转" - ], - "performance": [ - "性能", "耗时", "time", "duration", "elapsed", "ms", "毫秒", "秒", - "执行时间", "处理时间", "检测时间" - ], - "error": [ - "错误", "error", "exception", "失败", "fail", "timeout", "超时", - "异常", "崩溃", "中断", "连接失败" - ], - "info": [ - "信息", "info", "开始", "完成", "初始化", "启动", "停止", - "日志", "debug", "调试" - ], - "network": [ - "网络", "network", "连接", "请求", "响应", "http", "api", - "服务器", "接口", "上传", "下载" - ] -} - - -def get_operation_type(line: str) -> Optional[str]: - """ - 根据日志行内容识别操作类型 - - 日志格式通常是: [时间] [GUI] - 操作类型 内容 - 优先识别日志内容中的操作类型关键词(如 "流程"、"滑动"、"阶段诊断"、"预约" 等) - - Args: - line: 日志行内容 - - Returns: - 操作类型名称,如果无法识别则返回None - """ - line_lower = line.lower() - - # 优先级1: 识别日志内容开头的操作类型(最精确) - # 日志格式: [时间] [GUI] - 操作类型 内容 - # 例如: [GUI] - 流程 find_and_open_fudai_detail完成 - if "[gui] -" in line_lower: - parts = line_lower.split("[gui] -") - if len(parts) > 1: - content = parts[1].strip() - # 提取操作类型(第一个词) - first_word = content.split()[0] if content.split() else "" - if first_word in ["流程", "滑动", "阶段诊断", "预约", "截图", "点击", "识别", "检测"]: - return first_word - - # 优先级2: 关键词匹配(更全面的识别) - for operation_type, keywords in OPERATION_KEYWORDS.items(): - for keyword in keywords: - if keyword.lower() in line_lower: - return operation_type - - return None - - -def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]: - """ - 根据主题获取颜色配置 - - Args: - theme: 主题名称,如 'litera'(明亮), 'darkly'(暗色), 'cyborg'(深色) - - Returns: - 颜色配置字典,包含各操作类型的颜色设置 - """ - # 基础颜色配置 - if theme in ["litera", "minty", "pulse", "solar", "united", "yeti"]: - # 明亮主题 - base_config = { - "ocr": {"foreground": "#2E8B57", "background": "#F0FFF0"}, # 绿色 - "click": {"foreground": "#4169E1", "background": "#F0F8FF"}, # 蓝色 - "swipe": {"foreground": "#FF6347", "background": "#FFF5EE"}, # 红色 - "screenshot": {"foreground": "#8B4513", "background": "#FFF8DC"}, # 棕色 - "detection": {"foreground": "#9932CC", "background": "#F8F8FF"}, # 紫色 - "decision": {"foreground": "#FF8C00", "background": "#FFFACD"}, # 橙色 - "reservation": {"foreground": "#20B2AA", "background": "#F0FFFF"}, # 青色 - "fansclub": {"foreground": "#DC143C", "background": "#FFE4E1"}, # 粉红 - "lottery": {"foreground": "#FFD700", "background": "#FFFFE0"}, # 金色 - "stage": {"foreground": "#8B008B", "background": "#F0F0F0"}, # 深紫 - "performance": {"foreground": "#696969", "background": "#F5F5F5"}, # 灰色 - "error": {"foreground": "#B22222", "background": "#FFE4E1"}, # 深红 - "info": {"foreground": "#000000", "background": "#FFFFFF"}, # 黑色 - "network": {"foreground": "#4682B4", "background": "#F0F8FF"} # 钢蓝 - } - else: - # 暗色主题 - base_config = { - "ocr": {"foreground": "#98FB98", "background": "#2F4F2F"}, # 亮绿 - "click": {"foreground": "#87CEEB", "background": "#191970"}, # 亮蓝 - "swipe": {"foreground": "#FFA07A", "background": "#8B0000"}, # 亮红 - "screenshot": {"foreground": "#F4A460", "background": "#8B4513"}, # 沙色 - "detection": {"foreground": "#DDA0DD", "background": "#4B0082"}, # 梅红 - "decision": {"foreground": "#FFDAB9", "background": "#FF8C00"}, # 桃色 - "reservation": {"foreground": "#AFEEEE", "background": "#008B8B"}, # 淡青 - "fansclub": {"foreground": "#FFB6C1", "background": "#8B0000"}, # 浅粉 - "lottery": {"foreground": "#FFFF00", "background": "#FFD700"}, # 亮黄 - "stage": {"foreground": "#DDA0DD", "background": "#2F2F2F"}, # 梅红 - "performance": {"foreground": "#D3D3D3", "background": "#696969"}, # 浅灰 - "error": {"foreground": "#FFA07A", "background": "#B22222"}, # 亮红 - "info": {"foreground": "#FFFFFF", "background": "#000000"}, # 白色 - "network": {"foreground": "#87CEEB", "background": "#4682B4"} # 亮蓝 - } - - return base_config - - -def apply_operation_color( - text_widget, - start_pos: str, - end_pos: str, - operation_type: Optional[str], - theme: str = "litera" -) -> None: - """ - 为日志文本中的指定范围应用操作类型颜色标签 - - Args: - text_widget: Tkinter文本控件 - start_pos: 开始位置(如 "1.0") - end_pos: 结束位置(如 "1.end") - operation_type: 操作类型(None表示不应用颜色) - theme: 主题名称 - """ - try: - if operation_type is None: - return - - # 获取颜色配置 - color_config = get_color_config(theme) - colors = color_config.get(operation_type) - - if colors is None: - return - - # 创建唯一标签名 - tag_name = f"operation_{operation_type}" - - # 配置标签(总是重新配置,确保主题改变时颜色也会更新) - text_widget.tag_configure( - tag_name, - foreground=colors["foreground"], - background=colors["background"], - ) - - # 应用标签 - text_widget.tag_add(tag_name, start_pos, end_pos) - except Exception: - # 忽略颜色应用失败,不影响日志显示 - pass -- 2.39.5 From b96a67b6b81e8c6dd0b8a02a6e2bb049254eb7ff Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 10:09:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20web=5Fgui=20=E4=B8=AD=205=20?= =?UTF-8?q?=E4=B8=AA=20ADB/config=20=E5=87=BD=E6=95=B0=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=96=84=E5=8C=85=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit find_adb_executable / list_adb_devices / resolve_adb_device / read_config / write_config 在 gui_core.py 中已有完全相同的实现。 web_gui.py 中改为薄包装,所有外部使用保持兼容。 注:get_nested_value 是 web_gui 独有,保留。 文件行数:gui/web_gui.py 原 2253 行减至 2210 行(约减 43 行) Co-Authored-By: Claude Opus 4.5 --- gui/web_gui.py | 87 ++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 67 deletions(-) diff --git a/gui/web_gui.py b/gui/web_gui.py index 451e99d..4ff9ebe 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -64,65 +64,31 @@ def strip_ansi_escape_codes(text: str) -> str: def find_adb_executable() -> str: - adb = shutil.which("adb") - if adb: - return adb - localapp = os.environ.get("LOCALAPPDATA") or "" - candidates = [] - if localapp: - candidates.append(os.path.join(localapp, "platform-tools", "adb.exe")) - userprofile = os.environ.get("USERPROFILE") or "" - if userprofile: - candidates.append( - os.path.join(userprofile, "AppData", "Local", "platform-tools", "adb.exe") - ) - for p in candidates: - if os.path.exists(p): - return p - return "" + """[兼容] 已迁移到 gui.gui_core。""" + from gui.gui_core import find_adb_executable as _impl + + return _impl() def list_adb_devices(adb_exe: str) -> list[str]: - try: - if not adb_exe: - return [] - proc = subprocess.run( - [adb_exe, "devices", "-l"], - capture_output=True, - text=True, - encoding="utf-8", - errors="replace", - check=False, - ) - except FileNotFoundError: - return [] - devices: list[str] = [] - for line in (proc.stdout or "").splitlines()[1:]: - parts = line.split() - if len(parts) >= 2 and parts[1] == "device": - devices.append(parts[0]) - return devices + """[兼容] 已迁移到 gui.gui_core。""" + from gui.gui_core import list_adb_devices as _impl + + return _impl(adb_exe) def resolve_adb_device(adb_exe: str, requested_device_id: str = "") -> str: - device_id = str(requested_device_id or "").strip() - devices = list_adb_devices(adb_exe) - if device_id: - if device_id in devices: - return device_id - raise RuntimeError(f"指定的 device_id '{device_id}' 当前不可用") - if len(devices) == 1: - return devices[0] - if len(devices) > 1: - raise RuntimeError(f"检测到多台 adb 设备,请先明确选择 device_id: {', '.join(devices)}") - raise RuntimeError("未检测到可用的 adb 设备") + """[兼容] 已迁移到 gui.gui_core。""" + from gui.gui_core import resolve_adb_device as _impl + + return _impl(adb_exe, requested_device_id) def read_config() -> dict: - if not os.path.exists(CONFIG_PATH): - return {} - with open(CONFIG_PATH, "r", encoding="utf-8") as f: - return json.load(f) + """[兼容] 已迁移到 gui.gui_core。""" + from gui.gui_core import read_config as _impl + + return _impl() def get_nested_value(obj: dict, key: str, default=None): @@ -139,23 +105,10 @@ def get_nested_value(obj: dict, key: str, default=None): def write_config(cfg: dict) -> None: - # Web 表单通常只生成“已知字段”的子集;直接覆盖写会丢失其它键(例如 ROI rect/poly 等扩展配置)。 - # 这里做一次 merge:保留原配置中的未知键,再用新 cfg 覆盖同名键。 - merged = {} - try: - merged = read_config() - if not isinstance(merged, dict): - merged = {} - except Exception: - merged = {} - try: - if isinstance(cfg, dict): - merged.update(cfg) - except Exception: - pass - with open(CONFIG_PATH, "w", encoding="utf-8") as f: - json.dump(merged, f, ensure_ascii=False, indent=4) - f.write("\n") + """[兼容] 已迁移到 gui.gui_core。""" + from gui.gui_core import write_config as _impl + + return _impl(cfg) class ProcRunner: -- 2.39.5