Merge pull request 'claude/wonderful-brattain-d1cfe0' (#5) from claude/wonderful-brattain-d1cfe0 into main
Reviewed-on: simgreek/douyi_guaji_main#5
This commit is contained in:
commit
c878491163
3 files changed
+24
-277
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
+20
-67
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user