chore: Clean up and refactor codebase for improved maintainability
- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality. - Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability. - Updated various components to utilize the new preprocessing function, improving code organization and readability. - Adjusted configuration values in `config.json` for better performance and consistency. - Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines. - Cleaned up excessive blank lines across multiple files to enhance overall readability.
This commit is contained in:
1 parent
efe6e2252f
commit
223c127e11
70 files changed
+17121
-1752
No files matched your search
@@ -17,3 +17,25 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,3 +57,25 @@ def save_ui_to_config(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -67,3 +67,25 @@ def create_device_selector(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,25 @@ def create_image_viewer(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,540 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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": [
|
||||
"耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率"
|
||||
],
|
||||
"error": [
|
||||
"错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout"
|
||||
],
|
||||
"success": [
|
||||
"成功", "SUCCESS", "完成", "完成", "已", "完成"
|
||||
],
|
||||
"info": [
|
||||
"信息", "INFO", "提示", "注意", "开始", "启动", "停止"
|
||||
],
|
||||
"flow": [
|
||||
"流程", "flow", "处理", "执行", "运行", "完成"
|
||||
],
|
||||
"operation": [
|
||||
"操作", "operation", "动作", "行为"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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": [
|
||||
"耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率"
|
||||
],
|
||||
"error": [
|
||||
"错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout"
|
||||
],
|
||||
"success": [
|
||||
"成功", "SUCCESS", "完成", "完成", "已", "完成"
|
||||
],
|
||||
"info": [
|
||||
"信息", "INFO", "提示", "注意", "开始", "启动", "停止"
|
||||
],
|
||||
"flow": [
|
||||
"流程", "flow", "处理", "执行", "运行", "完成"
|
||||
],
|
||||
"operation": [
|
||||
"操作", "operation", "动作", "行为"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
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完成
|
||||
# [GUI] - 滑动上滑切换直播间
|
||||
# [GUI] - 阶段诊断开始阶段诊断
|
||||
# [GUI] - 预约[预约]记录直播间标题
|
||||
|
||||
import re
|
||||
# 提取日志内容部分(去掉时间戳和标签)
|
||||
# 匹配格式: [时间] [标签] - 内容
|
||||
content_match = re.search(r'\]\s*-\s*(.+)$', line)
|
||||
if content_match:
|
||||
content = content_match.group(1).strip()
|
||||
content_lower = content.lower()
|
||||
|
||||
# 操作类型关键词映射(按优先级排序,更具体的在前)
|
||||
operation_type_map = [
|
||||
# 检测相关(最具体)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("并行检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("检测", "detection"),
|
||||
# 滑动相关
|
||||
("滑动", "swipe"),
|
||||
("上滑", "swipe"),
|
||||
("下滑", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("预约", "reservation"),
|
||||
# OCR相关
|
||||
("OCR", "ocr"),
|
||||
("ocr识别", "ocr"),
|
||||
("识别", "ocr"),
|
||||
# 点击相关
|
||||
("点击", "click"),
|
||||
# 截图相关
|
||||
("截图", "screenshot"),
|
||||
# 流程相关
|
||||
("流程", "flow"),
|
||||
# 决策相关
|
||||
("决策", "decision"),
|
||||
("行为识别", "decision"),
|
||||
# 开奖相关
|
||||
("开奖", "lottery"),
|
||||
("抽奖结果", "lottery"),
|
||||
# 粉丝团相关
|
||||
("粉丝团", "fansclub"),
|
||||
# 操作相关(通用,放后面)
|
||||
("操作", "operation"),
|
||||
# 自救相关
|
||||
("自救", "info"),
|
||||
# 错误相关
|
||||
("错误", "error"),
|
||||
("异常", "error"),
|
||||
# 成功相关
|
||||
("成功", "success"),
|
||||
# 信息相关(最通用,放最后)
|
||||
("信息", "info"),
|
||||
]
|
||||
|
||||
# 检查内容开头是否匹配操作类型
|
||||
for keyword, op_type in operation_type_map:
|
||||
# 检查是否在内容开头(更精确)
|
||||
if content_lower.startswith(keyword.lower()):
|
||||
return op_type
|
||||
# 或者检查是否紧跟在 " - " 后面
|
||||
if f" - {keyword.lower()}" in line_lower or f"- {keyword.lower()}" in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用日志标签识别(如果内容中没有匹配到)
|
||||
tag_match = re.search(r'\[([^\]]+)\]', line)
|
||||
if tag_match:
|
||||
tag = tag_match.group(1).lower()
|
||||
|
||||
# 标签到操作类型的映射(精确匹配)
|
||||
tag_to_op_type = {
|
||||
"阶段诊断": "detection",
|
||||
"阶段检测": "detection",
|
||||
"截图": "screenshot",
|
||||
"ocr": "ocr",
|
||||
"ocr识别": "ocr",
|
||||
"点击": "click",
|
||||
"滑动": "swipe",
|
||||
"预约": "reservation",
|
||||
"找福袋图标": "detection",
|
||||
"福袋查找": "detection",
|
||||
"自救": "info",
|
||||
"流程": "flow",
|
||||
"行为识别": "decision",
|
||||
"决策": "decision",
|
||||
"错误": "error",
|
||||
"异常": "error",
|
||||
"成功": "success",
|
||||
"信息": "info",
|
||||
"提示": "info",
|
||||
}
|
||||
|
||||
# 精确匹配标签
|
||||
if tag in tag_to_op_type:
|
||||
return tag_to_op_type[tag]
|
||||
|
||||
# 部分匹配标签(用于更灵活的匹配)
|
||||
for tag_key, op_type in tag_to_op_type.items():
|
||||
if tag_key in tag or tag in tag_key:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用关键词匹配(更具体的短语优先)
|
||||
# 定义更具体的关键词短语(按优先级排序)
|
||||
specific_patterns = [
|
||||
# 检测相关(更具体的短语优先)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("并行检测", "detection"),
|
||||
# OCR相关
|
||||
("OCR识别", "ocr"),
|
||||
("OCR模式", "ocr"),
|
||||
("识别成功", "ocr"),
|
||||
("识别失败", "ocr"),
|
||||
# 点击相关
|
||||
("点击成功", "click"),
|
||||
("点击失败", "click"),
|
||||
("参与按钮", "click"),
|
||||
# 滑动相关
|
||||
("向上滑动", "swipe"),
|
||||
("向下滑动", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("记录预约", "reservation"),
|
||||
("预约窗口", "reservation"),
|
||||
("预约队列", "reservation"),
|
||||
# 开奖相关
|
||||
("抽奖结果", "lottery"),
|
||||
("等待开奖", "lottery"),
|
||||
("开奖时间", "lottery"),
|
||||
# 粉丝团相关
|
||||
("加入粉丝团", "fansclub"),
|
||||
("粉丝团失败", "fansclub"),
|
||||
("粉丝团成功", "fansclub"),
|
||||
]
|
||||
|
||||
# 先检查更具体的短语
|
||||
for pattern, op_type in specific_patterns:
|
||||
if pattern.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
for op_type in priority_order:
|
||||
if op_type in OPERATION_KEYWORDS:
|
||||
for keyword in OPERATION_KEYWORDS[op_type]:
|
||||
# 避免过于宽泛的关键词误匹配
|
||||
if keyword.lower() in ["截图", "检测", "识别", "成功", "完成", "失败", "错误"]:
|
||||
# 这些关键词太宽泛,只在特定上下文中使用
|
||||
# 检查是否在更具体的上下文中
|
||||
if keyword.lower() == "截图" and ("截图成功" in line_lower or "截图失败" in line_lower or "[截图]" in line):
|
||||
return op_type
|
||||
elif keyword.lower() == "检测" and ("阶段检测" in line_lower or "像素检测" in line_lower or "并行检测" in line_lower):
|
||||
return op_type
|
||||
elif keyword.lower() == "识别" and ("OCR识别" in line_lower or "识别成功" in line_lower or "识别失败" in line_lower):
|
||||
return op_type
|
||||
# 其他宽泛关键词跳过,避免误匹配
|
||||
continue
|
||||
|
||||
if keyword.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
light_themes = {"litera", "flatly", "journal", "minty", "cosmo"}
|
||||
is_light = theme.lower() in light_themes
|
||||
|
||||
if is_light:
|
||||
# 明亮主题颜色配置(深色文字,与白色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#0052CC", # 鲜明蓝色 - OCR识别
|
||||
"background": "#D6E8FF", # 浅蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#D32F2F", # 鲜明红色 - 点击操作
|
||||
"background": "#FFE0E0", # 浅红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#2E7D32", # 鲜明绿色 - 滑动操作
|
||||
"background": "#E0F2E8", # 浅绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#7B1FA2", # 鲜明紫色 - 截图操作
|
||||
"background": "#F3E5F5", # 浅紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#F57C00", # 鲜明橙色 - 检测操作
|
||||
"background": "#FFF3E0", # 浅橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#C2185B", # 鲜明品红色 - 决策操作
|
||||
"background": "#FCE4EC", # 浅品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#00897B", # 鲜明青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#E0F2F1", # 浅青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#8E24AA", # 鲜明紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#F3E5F5", # 浅紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#E64A19", # 鲜明橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#FFEBEE", # 浅橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#616161", # 深灰色 - 阶段信息
|
||||
"background": "#F5F5F5", # 浅灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#00796B", # 鲜明青绿色 - 性能信息
|
||||
"background": "#E0F2F1", # 浅青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#C62828", # 鲜明深红色 - 错误
|
||||
"background": "#FFCDD2", # 浅红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#2E7D32", # 鲜明深绿色 - 成功
|
||||
"background": "#C8E6C9", # 浅绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#0277BD", # 鲜明天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#BBDEFB", # 浅天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#5D4037", # 深棕色 - 流程操作
|
||||
"background": "#EFEBE9", # 浅棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#455A64", # 深蓝灰色 - 操作动作
|
||||
"background": "#ECEFF1", # 浅蓝灰色背景
|
||||
},
|
||||
}
|
||||
else:
|
||||
# 暗色主题颜色配置(亮色文字,与深色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#42A5F5", # 鲜明亮蓝色 - OCR识别
|
||||
"background": "#0D47A1", # 深蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#EF5350", # 鲜明亮红色 - 点击操作
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 滑动操作
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#AB47BC", # 鲜明亮紫色 - 截图操作
|
||||
"background": "#4A148C", # 深紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#FFA726", # 鲜明亮橙色 - 检测操作
|
||||
"background": "#E65100", # 深橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#EC407A", # 鲜明亮品红色 - 决策操作
|
||||
"background": "#880E4F", # 深品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#26A69A", # 鲜明亮青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#004D40", # 深青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#BA68C8", # 鲜明亮紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#4A148C", # 深紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#FF7043", # 鲜明亮橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#BF360C", # 深橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#90A4AE", # 亮灰色 - 阶段信息
|
||||
"background": "#263238", # 深灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#26A69A", # 鲜明亮青绿色 - 性能信息
|
||||
"background": "#004D40", # 深青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#F44336", # 鲜明亮红色 - 错误
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 成功
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#29B6F6", # 鲜明亮天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#01579B", # 深天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#A1887F", # 亮棕色 - 流程操作
|
||||
"background": "#3E2723", # 深棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#78909C", # 亮蓝灰色 - 操作动作
|
||||
"background": "#263238", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
try:
|
||||
# 识别操作类型
|
||||
op_type = get_operation_type(line)
|
||||
if not op_type:
|
||||
return
|
||||
|
||||
# 获取颜色配置
|
||||
color_config = get_color_config(theme)
|
||||
if op_type not in color_config:
|
||||
return
|
||||
|
||||
colors = color_config[op_type]
|
||||
tag_name = f"op_{op_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
|
||||
@@ -0,0 +1,943 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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": [
|
||||
"耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率"
|
||||
],
|
||||
"error": [
|
||||
"错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout"
|
||||
],
|
||||
"success": [
|
||||
"成功", "SUCCESS", "完成", "完成", "已", "完成"
|
||||
],
|
||||
"info": [
|
||||
"信息", "INFO", "提示", "注意", "开始", "启动", "停止"
|
||||
],
|
||||
"flow": [
|
||||
"流程", "flow", "处理", "执行", "运行", "完成"
|
||||
],
|
||||
"operation": [
|
||||
"操作", "operation", "动作", "行为"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
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完成
|
||||
# [GUI] - 滑动上滑切换直播间
|
||||
# [GUI] - 阶段诊断开始阶段诊断
|
||||
# [GUI] - 预约[预约]记录直播间标题
|
||||
|
||||
import re
|
||||
# 提取日志内容部分(去掉时间戳和标签)
|
||||
# 匹配格式: [时间] [标签] - 内容
|
||||
content_match = re.search(r'\]\s*-\s*(.+)$', line)
|
||||
if content_match:
|
||||
content = content_match.group(1).strip()
|
||||
content_lower = content.lower()
|
||||
|
||||
# 操作类型关键词映射(按优先级排序,更具体的在前)
|
||||
operation_type_map = [
|
||||
# 检测相关(最具体)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("并行检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("检测", "detection"),
|
||||
# 滑动相关
|
||||
("滑动", "swipe"),
|
||||
("上滑", "swipe"),
|
||||
("下滑", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("预约", "reservation"),
|
||||
# OCR相关
|
||||
("OCR", "ocr"),
|
||||
("ocr识别", "ocr"),
|
||||
("识别", "ocr"),
|
||||
# 点击相关
|
||||
("点击", "click"),
|
||||
# 截图相关
|
||||
("截图", "screenshot"),
|
||||
# 流程相关
|
||||
("流程", "flow"),
|
||||
# 决策相关
|
||||
("决策", "decision"),
|
||||
("行为识别", "decision"),
|
||||
# 开奖相关
|
||||
("开奖", "lottery"),
|
||||
("抽奖结果", "lottery"),
|
||||
# 粉丝团相关
|
||||
("粉丝团", "fansclub"),
|
||||
# 操作相关(通用,放后面)
|
||||
("操作", "operation"),
|
||||
# 自救相关
|
||||
("自救", "info"),
|
||||
# 错误相关
|
||||
("错误", "error"),
|
||||
("异常", "error"),
|
||||
# 成功相关
|
||||
("成功", "success"),
|
||||
# 信息相关(最通用,放最后)
|
||||
("信息", "info"),
|
||||
]
|
||||
|
||||
# 检查内容开头是否匹配操作类型
|
||||
for keyword, op_type in operation_type_map:
|
||||
# 检查是否在内容开头(更精确)
|
||||
if content_lower.startswith(keyword.lower()):
|
||||
return op_type
|
||||
# 或者检查是否紧跟在 " - " 后面
|
||||
if f" - {keyword.lower()}" in line_lower or f"- {keyword.lower()}" in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用日志标签识别(如果内容中没有匹配到)
|
||||
tag_match = re.search(r'\[([^\]]+)\]', line)
|
||||
if tag_match:
|
||||
tag = tag_match.group(1).lower()
|
||||
|
||||
# 标签到操作类型的映射(精确匹配)
|
||||
tag_to_op_type = {
|
||||
"阶段诊断": "detection",
|
||||
"阶段检测": "detection",
|
||||
"截图": "screenshot",
|
||||
"ocr": "ocr",
|
||||
"ocr识别": "ocr",
|
||||
"点击": "click",
|
||||
"滑动": "swipe",
|
||||
"预约": "reservation",
|
||||
"找福袋图标": "detection",
|
||||
"福袋查找": "detection",
|
||||
"自救": "info",
|
||||
"流程": "flow",
|
||||
"行为识别": "decision",
|
||||
"决策": "decision",
|
||||
"错误": "error",
|
||||
"异常": "error",
|
||||
"成功": "success",
|
||||
"信息": "info",
|
||||
"提示": "info",
|
||||
}
|
||||
|
||||
# 精确匹配标签
|
||||
if tag in tag_to_op_type:
|
||||
return tag_to_op_type[tag]
|
||||
|
||||
# 部分匹配标签(用于更灵活的匹配)
|
||||
for tag_key, op_type in tag_to_op_type.items():
|
||||
if tag_key in tag or tag in tag_key:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用关键词匹配(更具体的短语优先)
|
||||
# 定义更具体的关键词短语(按优先级排序)
|
||||
specific_patterns = [
|
||||
# 检测相关(更具体的短语优先)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("并行检测", "detection"),
|
||||
# OCR相关
|
||||
("OCR识别", "ocr"),
|
||||
("OCR模式", "ocr"),
|
||||
("识别成功", "ocr"),
|
||||
("识别失败", "ocr"),
|
||||
# 点击相关
|
||||
("点击成功", "click"),
|
||||
("点击失败", "click"),
|
||||
("参与按钮", "click"),
|
||||
# 滑动相关
|
||||
("向上滑动", "swipe"),
|
||||
("向下滑动", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("记录预约", "reservation"),
|
||||
("预约窗口", "reservation"),
|
||||
("预约队列", "reservation"),
|
||||
# 开奖相关
|
||||
("抽奖结果", "lottery"),
|
||||
("等待开奖", "lottery"),
|
||||
("开奖时间", "lottery"),
|
||||
# 粉丝团相关
|
||||
("加入粉丝团", "fansclub"),
|
||||
("粉丝团失败", "fansclub"),
|
||||
("粉丝团成功", "fansclub"),
|
||||
]
|
||||
|
||||
# 先检查更具体的短语
|
||||
for pattern, op_type in specific_patterns:
|
||||
if pattern.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
for op_type in priority_order:
|
||||
if op_type in OPERATION_KEYWORDS:
|
||||
for keyword in OPERATION_KEYWORDS[op_type]:
|
||||
# 避免过于宽泛的关键词误匹配
|
||||
if keyword.lower() in ["截图", "检测", "识别", "成功", "完成", "失败", "错误"]:
|
||||
# 这些关键词太宽泛,只在特定上下文中使用
|
||||
# 检查是否在更具体的上下文中
|
||||
if keyword.lower() == "截图" and ("截图成功" in line_lower or "截图失败" in line_lower or "[截图]" in line):
|
||||
return op_type
|
||||
elif keyword.lower() == "检测" and ("阶段检测" in line_lower or "像素检测" in line_lower or "并行检测" in line_lower):
|
||||
return op_type
|
||||
elif keyword.lower() == "识别" and ("OCR识别" in line_lower or "识别成功" in line_lower or "识别失败" in line_lower):
|
||||
return op_type
|
||||
# 其他宽泛关键词跳过,避免误匹配
|
||||
continue
|
||||
|
||||
if keyword.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
light_themes = {"litera", "flatly", "journal", "minty", "cosmo"}
|
||||
is_light = theme.lower() in light_themes
|
||||
|
||||
if is_light:
|
||||
# 明亮主题颜色配置(深色文字,与白色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#0052CC", # 鲜明蓝色 - OCR识别
|
||||
"background": "#D6E8FF", # 浅蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#D32F2F", # 鲜明红色 - 点击操作
|
||||
"background": "#FFE0E0", # 浅红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#2E7D32", # 鲜明绿色 - 滑动操作
|
||||
"background": "#E0F2E8", # 浅绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#7B1FA2", # 鲜明紫色 - 截图操作
|
||||
"background": "#F3E5F5", # 浅紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#F57C00", # 鲜明橙色 - 检测操作
|
||||
"background": "#FFF3E0", # 浅橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#C2185B", # 鲜明品红色 - 决策操作
|
||||
"background": "#FCE4EC", # 浅品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#00897B", # 鲜明青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#E0F2F1", # 浅青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#8E24AA", # 鲜明紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#F3E5F5", # 浅紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#E64A19", # 鲜明橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#FFEBEE", # 浅橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#616161", # 深灰色 - 阶段信息
|
||||
"background": "#F5F5F5", # 浅灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#00796B", # 鲜明青绿色 - 性能信息
|
||||
"background": "#E0F2F1", # 浅青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#C62828", # 鲜明深红色 - 错误
|
||||
"background": "#FFCDD2", # 浅红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#2E7D32", # 鲜明深绿色 - 成功
|
||||
"background": "#C8E6C9", # 浅绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#0277BD", # 鲜明天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#BBDEFB", # 浅天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#5D4037", # 深棕色 - 流程操作
|
||||
"background": "#EFEBE9", # 浅棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#455A64", # 深蓝灰色 - 操作动作
|
||||
"background": "#ECEFF1", # 浅蓝灰色背景
|
||||
},
|
||||
}
|
||||
else:
|
||||
# 暗色主题颜色配置(亮色文字,与深色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#42A5F5", # 鲜明亮蓝色 - OCR识别
|
||||
"background": "#0D47A1", # 深蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#EF5350", # 鲜明亮红色 - 点击操作
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 滑动操作
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#AB47BC", # 鲜明亮紫色 - 截图操作
|
||||
"background": "#4A148C", # 深紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#FFA726", # 鲜明亮橙色 - 检测操作
|
||||
"background": "#E65100", # 深橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#EC407A", # 鲜明亮品红色 - 决策操作
|
||||
"background": "#880E4F", # 深品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#26A69A", # 鲜明亮青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#004D40", # 深青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#BA68C8", # 鲜明亮紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#4A148C", # 深紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#FF7043", # 鲜明亮橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#BF360C", # 深橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#90A4AE", # 亮灰色 - 阶段信息
|
||||
"background": "#263238", # 深灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#26A69A", # 鲜明亮青绿色 - 性能信息
|
||||
"background": "#004D40", # 深青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#F44336", # 鲜明亮红色 - 错误
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 成功
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#29B6F6", # 鲜明亮天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#01579B", # 深天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#A1887F", # 亮棕色 - 流程操作
|
||||
"background": "#3E2723", # 深棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#78909C", # 亮蓝灰色 - 操作动作
|
||||
"background": "#263238", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
try:
|
||||
# 识别操作类型
|
||||
op_type = get_operation_type(line)
|
||||
if not op_type:
|
||||
return
|
||||
|
||||
# 获取颜色配置
|
||||
color_config = get_color_config(theme)
|
||||
if op_type not in color_config:
|
||||
return
|
||||
|
||||
colors = color_config[op_type]
|
||||
tag_name = f"op_{op_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
|
||||
|
||||
|
||||
"""
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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": [
|
||||
"耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率"
|
||||
],
|
||||
"error": [
|
||||
"错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout"
|
||||
],
|
||||
"success": [
|
||||
"成功", "SUCCESS", "完成", "完成", "已", "完成"
|
||||
],
|
||||
"info": [
|
||||
"信息", "INFO", "提示", "注意", "开始", "启动", "停止"
|
||||
],
|
||||
"flow": [
|
||||
"流程", "flow", "处理", "执行", "运行", "完成"
|
||||
],
|
||||
"operation": [
|
||||
"操作", "operation", "动作", "行为"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
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完成
|
||||
# [GUI] - 滑动上滑切换直播间
|
||||
# [GUI] - 阶段诊断开始阶段诊断
|
||||
# [GUI] - 预约[预约]记录直播间标题
|
||||
|
||||
import re
|
||||
# 提取日志内容部分(去掉时间戳和标签)
|
||||
# 匹配格式: [时间] [标签] - 内容
|
||||
content_match = re.search(r'\]\s*-\s*(.+)$', line)
|
||||
if content_match:
|
||||
content = content_match.group(1).strip()
|
||||
content_lower = content.lower()
|
||||
|
||||
# 操作类型关键词映射(按优先级排序,更具体的在前)
|
||||
operation_type_map = [
|
||||
# 检测相关(最具体)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("并行检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("检测", "detection"),
|
||||
# 滑动相关
|
||||
("滑动", "swipe"),
|
||||
("上滑", "swipe"),
|
||||
("下滑", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("预约", "reservation"),
|
||||
# OCR相关
|
||||
("OCR", "ocr"),
|
||||
("ocr识别", "ocr"),
|
||||
("识别", "ocr"),
|
||||
# 点击相关
|
||||
("点击", "click"),
|
||||
# 截图相关
|
||||
("截图", "screenshot"),
|
||||
# 流程相关
|
||||
("流程", "flow"),
|
||||
# 决策相关
|
||||
("决策", "decision"),
|
||||
("行为识别", "decision"),
|
||||
# 开奖相关
|
||||
("开奖", "lottery"),
|
||||
("抽奖结果", "lottery"),
|
||||
# 粉丝团相关
|
||||
("粉丝团", "fansclub"),
|
||||
# 操作相关(通用,放后面)
|
||||
("操作", "operation"),
|
||||
# 自救相关
|
||||
("自救", "info"),
|
||||
# 错误相关
|
||||
("错误", "error"),
|
||||
("异常", "error"),
|
||||
# 成功相关
|
||||
("成功", "success"),
|
||||
# 信息相关(最通用,放最后)
|
||||
("信息", "info"),
|
||||
]
|
||||
|
||||
# 检查内容开头是否匹配操作类型
|
||||
for keyword, op_type in operation_type_map:
|
||||
# 检查是否在内容开头(更精确)
|
||||
if content_lower.startswith(keyword.lower()):
|
||||
return op_type
|
||||
# 或者检查是否紧跟在 " - " 后面
|
||||
if f" - {keyword.lower()}" in line_lower or f"- {keyword.lower()}" in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用日志标签识别(如果内容中没有匹配到)
|
||||
tag_match = re.search(r'\[([^\]]+)\]', line)
|
||||
if tag_match:
|
||||
tag = tag_match.group(1).lower()
|
||||
|
||||
# 标签到操作类型的映射(精确匹配)
|
||||
tag_to_op_type = {
|
||||
"阶段诊断": "detection",
|
||||
"阶段检测": "detection",
|
||||
"截图": "screenshot",
|
||||
"ocr": "ocr",
|
||||
"ocr识别": "ocr",
|
||||
"点击": "click",
|
||||
"滑动": "swipe",
|
||||
"预约": "reservation",
|
||||
"找福袋图标": "detection",
|
||||
"福袋查找": "detection",
|
||||
"自救": "info",
|
||||
"流程": "flow",
|
||||
"行为识别": "decision",
|
||||
"决策": "decision",
|
||||
"错误": "error",
|
||||
"异常": "error",
|
||||
"成功": "success",
|
||||
"信息": "info",
|
||||
"提示": "info",
|
||||
}
|
||||
|
||||
# 精确匹配标签
|
||||
if tag in tag_to_op_type:
|
||||
return tag_to_op_type[tag]
|
||||
|
||||
# 部分匹配标签(用于更灵活的匹配)
|
||||
for tag_key, op_type in tag_to_op_type.items():
|
||||
if tag_key in tag or tag in tag_key:
|
||||
return op_type
|
||||
|
||||
# 优先级2: 使用关键词匹配(更具体的短语优先)
|
||||
# 定义更具体的关键词短语(按优先级排序)
|
||||
specific_patterns = [
|
||||
# 检测相关(更具体的短语优先)
|
||||
("阶段诊断", "detection"),
|
||||
("阶段检测", "detection"),
|
||||
("像素检测", "detection"),
|
||||
("模板匹配", "detection"),
|
||||
("并行检测", "detection"),
|
||||
# OCR相关
|
||||
("OCR识别", "ocr"),
|
||||
("OCR模式", "ocr"),
|
||||
("识别成功", "ocr"),
|
||||
("识别失败", "ocr"),
|
||||
# 点击相关
|
||||
("点击成功", "click"),
|
||||
("点击失败", "click"),
|
||||
("参与按钮", "click"),
|
||||
# 滑动相关
|
||||
("向上滑动", "swipe"),
|
||||
("向下滑动", "swipe"),
|
||||
("切换直播间", "swipe"),
|
||||
# 预约相关
|
||||
("记录预约", "reservation"),
|
||||
("预约窗口", "reservation"),
|
||||
("预约队列", "reservation"),
|
||||
# 开奖相关
|
||||
("抽奖结果", "lottery"),
|
||||
("等待开奖", "lottery"),
|
||||
("开奖时间", "lottery"),
|
||||
# 粉丝团相关
|
||||
("加入粉丝团", "fansclub"),
|
||||
("粉丝团失败", "fansclub"),
|
||||
("粉丝团成功", "fansclub"),
|
||||
]
|
||||
|
||||
# 先检查更具体的短语
|
||||
for pattern, op_type in specific_patterns:
|
||||
if pattern.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
for op_type in priority_order:
|
||||
if op_type in OPERATION_KEYWORDS:
|
||||
for keyword in OPERATION_KEYWORDS[op_type]:
|
||||
# 避免过于宽泛的关键词误匹配
|
||||
if keyword.lower() in ["截图", "检测", "识别", "成功", "完成", "失败", "错误"]:
|
||||
# 这些关键词太宽泛,只在特定上下文中使用
|
||||
# 检查是否在更具体的上下文中
|
||||
if keyword.lower() == "截图" and ("截图成功" in line_lower or "截图失败" in line_lower or "[截图]" in line):
|
||||
return op_type
|
||||
elif keyword.lower() == "检测" and ("阶段检测" in line_lower or "像素检测" in line_lower or "并行检测" in line_lower):
|
||||
return op_type
|
||||
elif keyword.lower() == "识别" and ("OCR识别" in line_lower or "识别成功" in line_lower or "识别失败" in line_lower):
|
||||
return op_type
|
||||
# 其他宽泛关键词跳过,避免误匹配
|
||||
continue
|
||||
|
||||
if keyword.lower() in line_lower:
|
||||
return op_type
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
light_themes = {"litera", "flatly", "journal", "minty", "cosmo"}
|
||||
is_light = theme.lower() in light_themes
|
||||
|
||||
if is_light:
|
||||
# 明亮主题颜色配置(深色文字,与白色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#0052CC", # 鲜明蓝色 - OCR识别
|
||||
"background": "#D6E8FF", # 浅蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#D32F2F", # 鲜明红色 - 点击操作
|
||||
"background": "#FFE0E0", # 浅红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#2E7D32", # 鲜明绿色 - 滑动操作
|
||||
"background": "#E0F2E8", # 浅绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#7B1FA2", # 鲜明紫色 - 截图操作
|
||||
"background": "#F3E5F5", # 浅紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#F57C00", # 鲜明橙色 - 检测操作
|
||||
"background": "#FFF3E0", # 浅橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#C2185B", # 鲜明品红色 - 决策操作
|
||||
"background": "#FCE4EC", # 浅品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#00897B", # 鲜明青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#E0F2F1", # 浅青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#8E24AA", # 鲜明紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#F3E5F5", # 浅紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#E64A19", # 鲜明橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#FFEBEE", # 浅橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#616161", # 深灰色 - 阶段信息
|
||||
"background": "#F5F5F5", # 浅灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#00796B", # 鲜明青绿色 - 性能信息
|
||||
"background": "#E0F2F1", # 浅青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#C62828", # 鲜明深红色 - 错误
|
||||
"background": "#FFCDD2", # 浅红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#2E7D32", # 鲜明深绿色 - 成功
|
||||
"background": "#C8E6C9", # 浅绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#0277BD", # 鲜明天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#BBDEFB", # 浅天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#5D4037", # 深棕色 - 流程操作
|
||||
"background": "#EFEBE9", # 浅棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#455A64", # 深蓝灰色 - 操作动作
|
||||
"background": "#ECEFF1", # 浅蓝灰色背景
|
||||
},
|
||||
}
|
||||
else:
|
||||
# 暗色主题颜色配置(亮色文字,与深色背景对比,高区分度)
|
||||
return {
|
||||
"ocr": {
|
||||
"foreground": "#42A5F5", # 鲜明亮蓝色 - OCR识别
|
||||
"background": "#0D47A1", # 深蓝色背景
|
||||
},
|
||||
"click": {
|
||||
"foreground": "#EF5350", # 鲜明亮红色 - 点击操作
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"swipe": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 滑动操作
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"screenshot": {
|
||||
"foreground": "#AB47BC", # 鲜明亮紫色 - 截图操作
|
||||
"background": "#4A148C", # 深紫色背景
|
||||
},
|
||||
"detection": {
|
||||
"foreground": "#FFA726", # 鲜明亮橙色 - 检测操作
|
||||
"background": "#E65100", # 深橙色背景
|
||||
},
|
||||
"decision": {
|
||||
"foreground": "#EC407A", # 鲜明亮品红色 - 决策操作
|
||||
"background": "#880E4F", # 深品红色背景
|
||||
},
|
||||
"reservation": {
|
||||
"foreground": "#26A69A", # 鲜明亮青色 - 预约操作(区别于OCR蓝色)
|
||||
"background": "#004D40", # 深青色背景
|
||||
},
|
||||
"fansclub": {
|
||||
"foreground": "#BA68C8", # 鲜明亮紫红色 - 粉丝团操作(区别于截图紫色)
|
||||
"background": "#4A148C", # 深紫红色背景
|
||||
},
|
||||
"lottery": {
|
||||
"foreground": "#FF7043", # 鲜明亮橙红色 - 开奖相关(区别于点击红色)
|
||||
"background": "#BF360C", # 深橙红色背景
|
||||
},
|
||||
"stage": {
|
||||
"foreground": "#90A4AE", # 亮灰色 - 阶段信息
|
||||
"background": "#263238", # 深灰色背景
|
||||
},
|
||||
"performance": {
|
||||
"foreground": "#26A69A", # 鲜明亮青绿色 - 性能信息
|
||||
"background": "#004D40", # 深青绿色背景
|
||||
},
|
||||
"error": {
|
||||
"foreground": "#F44336", # 鲜明亮红色 - 错误
|
||||
"background": "#B71C1C", # 深红色背景
|
||||
},
|
||||
"success": {
|
||||
"foreground": "#66BB6A", # 鲜明亮绿色 - 成功
|
||||
"background": "#1B5E20", # 深绿色背景
|
||||
},
|
||||
"info": {
|
||||
"foreground": "#29B6F6", # 鲜明亮天蓝色 - 信息(区别于OCR深蓝色)
|
||||
"background": "#01579B", # 深天蓝色背景
|
||||
},
|
||||
"flow": {
|
||||
"foreground": "#A1887F", # 亮棕色 - 流程操作
|
||||
"background": "#3E2723", # 深棕色背景
|
||||
},
|
||||
"operation": {
|
||||
"foreground": "#78909C", # 亮蓝灰色 - 操作动作
|
||||
"background": "#263238", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
try:
|
||||
# 识别操作类型
|
||||
op_type = get_operation_type(line)
|
||||
if not op_type:
|
||||
return
|
||||
|
||||
# 获取颜色配置
|
||||
color_config = get_color_config(theme)
|
||||
if op_type not in color_config:
|
||||
return
|
||||
|
||||
colors = color_config[op_type]
|
||||
tag_name = f"op_{op_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
|
||||
@@ -0,0 +1,200 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Optional, List, Dict
|
||||
from typing import Any, Callable, Optional, List, Dict, Tuple
|
||||
import queue
|
||||
import re
|
||||
import threading
|
||||
@@ -44,7 +44,7 @@ except ImportError:
|
||||
class EnhancedLogViewer(ttk.Frame):
|
||||
"""增强的日志查看器组件"""
|
||||
|
||||
def __init__(self, parent: Any, log_queue: "queue.Queue[str]" = None):
|
||||
def __init__(self, parent: Any, log_queue: Optional[queue.Queue] = None):
|
||||
super().__init__(parent)
|
||||
|
||||
# 初始化数据
|
||||
@@ -372,9 +372,9 @@ def format_gui_log_line(line: str) -> str:
|
||||
|
||||
def create_log_viewer(
|
||||
parent: Any,
|
||||
log_queue: "queue.Queue[str]",
|
||||
log_queue: Optional[queue.Queue],
|
||||
on_line: Callable[[str], None]
|
||||
) -> tuple[ScrolledText, Callable[[], None]]:
|
||||
) -> Any:
|
||||
"""创建日志查看器组件(兼容旧接口)。
|
||||
|
||||
参数:
|
||||
|
||||
@@ -49,3 +49,25 @@ def create_main_window(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,3 +50,25 @@ def create_ocr_panel(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user