chore: 删除重复的 log_color_config_fixed.py

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 <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.5 committed 2026-05-21 10:12:38 +08:00
1 parent 2e811e71b3
commit 7d63a36125
2 files changed
+4 -210

No files matched your search

+4 -12
View File
@@ -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
-198
View File
@@ -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