feat: Implement 30-minute timeout protection and unify path configurations

- Introduced a 30-minute timeout mechanism to prevent the script from getting stuck in invalid states, with configurable timeout settings.
- Unified path configurations across the project to enhance maintainability and avoid hardcoded paths.
- Updated documentation and flowcharts to reflect the new timeout feature and improved path management.
- Fixed issues with template and screenshot path configurations to ensure consistency across the project.
This commit is contained in:
Your Name committed 2025-12-28 14:47:31 +08:00
1 parent 686dde5cc0
commit 26df350755
64 files changed
+7568 -414

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
"""GUI组件模块
本目录包含从 gui_app.py 模块化后的GUI组件。
"""
+45
View File
@@ -0,0 +1,45 @@
"""行为日志查看组件
包含行为日志显示、搜索等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable, Tuple
import tkinter as tk
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
ScrolledText = TBSrolledText
except ImportError:
from tkinter.scrolledtext import ScrolledText
def create_actions_log_viewer(
parent: Any
):
"""创建行为日志查看器组件。
参数:
parent: 父容器
返回:
(actions_log_text, refresh_actions_log_func)
"""
actions_log_text = ScrolledText(parent)
actions_log_text.pack(fill="both", expand=True, padx=10, pady=10)
try:
actions_log_text.configure(font=("Consolas", 10))
except Exception:
pass
def refresh_actions_log() -> None:
"""刷新行为日志。"""
# TODO: 从原文件迁移函数实现
pass
return actions_log_text, refresh_actions_log
+48
View File
@@ -0,0 +1,48 @@
"""配置管理组件
包含配置加载、保存等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import tkinter as tk
from tkinter import ttk
from gui.gui_core import read_config, write_config
def load_config_to_ui(
cfg: dict[str, Any],
vars_dict: dict[str, Any],
on_line: Callable[[str], None],
) -> None:
"""从配置文件加载到UI变量。
参数:
cfg: 配置字典
vars_dict: UI变量字典
on_line: 日志输出回调
"""
# TODO: 实现配置加载逻辑
# 临时从原文件导入
pass
def save_ui_to_config(
vars_dict: dict[str, Any],
on_line: Callable[[str], None],
) -> None:
"""将UI变量保存到配置文件。
参数:
vars_dict: UI变量字典
on_line: 日志输出回调
"""
# TODO: 实现配置保存逻辑
# 临时从原文件导入
pass
+58
View File
@@ -0,0 +1,58 @@
"""设备选择组件
包含设备选择、刷新设备等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import tkinter as tk
from tkinter import ttk
from gui.gui_core import find_adb_executable, list_adb_devices
def create_device_selector(
parent: Any,
on_line: Callable[[str], None],
device_var: tk.StringVar,
) -> tuple[ttk.Combobox, Callable[[], None]]:
"""创建设备选择组件。
参数:
parent: 父容器
on_line: 日志输出回调
device_var: 设备ID变量
返回:
(device_combo, refresh_devices_func) 设备下拉框和刷新函数
"""
adb_exe = find_adb_executable()
devices = list_adb_devices(adb_exe)
device_var.set(devices[0] if devices else "")
ttk.Label(parent, text="设备:").pack(side="left")
device_combo = ttk.Combobox(parent, textvariable=device_var, values=devices, width=28)
device_combo.pack(side="left", padx=(0, 10))
def refresh_devices():
nonlocal adb_exe
adb_exe = find_adb_executable()
devs = list_adb_devices(adb_exe)
device_combo["values"] = devs
if devs and not device_var.get():
device_var.set(devs[0])
if not adb_exe:
on_line("[设备] 未找到 adb.exe(请确认已安装 platform-tools)")
elif not devs:
on_line("[设备] adb 可用,但未发现 device 状态设备(可能未授权/未连接)")
ttk.Button(parent, text="刷新设备", command=refresh_devices).pack(
side="left", padx=(0, 20)
)
return device_combo, refresh_devices
@@ -0,0 +1,43 @@
"""高价值房间显示组件
包含高价值房间显示和刷新功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable, Tuple
from tkinter.scrolledtext import ScrolledText
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
ScrolledText = TBSrolledText
except ImportError:
from tkinter.scrolledtext import ScrolledText
def create_high_value_rooms_display(
parent: Any
):
"""创建高价值房间显示组件。
参数:
parent: 父容器
返回:
(high_value_text, refresh_high_value_rooms_func)
"""
high_value_text = ScrolledText(parent)
high_value_text.pack(fill="both", expand=True, padx=10, pady=10)
try:
high_value_text.configure(font=("Consolas", 10))
except Exception:
pass
def refresh_high_value_rooms() -> None:
"""刷新高价值房间。"""
# TODO: 从原文件迁移函数实现
pass
return high_value_text, refresh_high_value_rooms
+44
View File
@@ -0,0 +1,44 @@
"""图像查看组件
包含图像预览、列表等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import os
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
def create_image_viewer(
parent: Any,
on_line: Callable[[str], None],
) -> tuple[Any, Callable[[], None], Callable[[], None]]:
"""创建图像查看器组件。
参数:
parent: 父容器
on_line: 日志输出回调
返回:
(image_var, update_image_list_func, refresh_preview_func)
"""
image_var = tk.StringVar()
def update_image_list(refresh_after: bool = True) -> None:
"""更新图像列表。"""
# TODO: 从原文件迁移函数实现
pass
def refresh_preview() -> None:
"""刷新图像预览。"""
# TODO: 从原文件迁移函数实现
pass
return image_var, update_image_list, refresh_preview
+57
View File
@@ -0,0 +1,57 @@
"""日志查看组件
包含日志显示、搜索等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable, Tuple, Callable
import queue
import re
import tkinter as tk
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
ScrolledText = TBSrolledText
except ImportError:
from tkinter.scrolledtext import ScrolledText
def format_gui_log_line(line: str) -> str:
"""将完整日志行转换为GUI显示用的精简版本。"""
# TODO: 从原文件迁移函数实现
return line
def create_log_viewer(
parent: Any,
log_queue: "queue.Queue[str]",
on_line: Callable[[str], None]
):
"""创建日志查看器组件。
参数:
parent: 父容器
log_queue: 日志队列
on_line: 日志输出回调
返回:
(log_text, pump_logs_func) 日志文本框和日志泵函数
"""
log_text = ScrolledText(parent)
log_text.pack(fill="both", expand=True, padx=10, pady=10)
try:
log_text.configure(font=("Consolas", 10))
except Exception:
pass
def pump_logs():
"""从队列中取出日志并显示。"""
# TODO: 从原文件迁移函数实现
pass
return log_text, pump_logs
+40
View File
@@ -0,0 +1,40 @@
"""主窗口组件
包含主窗口布局和事件绑定的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import tkinter as tk
from tkinter import ttk
def create_main_window(
title: str = "抖音福袋挂机 - 可视化控制台",
geometry: str = "1400x900",
) -> Any:
"""创建主窗口。
参数:
title: 窗口标题
geometry: 窗口尺寸
返回:
root窗口对象
"""
# ttkbootstrap 优先(更美观);没装则回退到原生 tkinter
try:
import ttkbootstrap as tb
root = tb.Window(themename="darkly")
except Exception:
root = tk.Tk()
root.title(title)
root.geometry(geometry)
return root
+41
View File
@@ -0,0 +1,41 @@
"""OCR面板组件
包含OCR区域配置、截图OCR等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import tkinter as tk
from tkinter import ttk
def create_ocr_panel(
parent: Any,
device_var: tk.StringVar,
y_var: tk.IntVar,
on_line: Callable[[str], None],
) -> tuple[Any, Callable[[], None]]:
"""创建OCR面板组件。
参数:
parent: 父容器
device_var: 设备ID变量
y_var: Y偏移变量
on_line: 日志输出回调
返回:
(ocr_results_var, do_screenshot_func)
"""
ocr_results_var = {"results": []}
def do_screenshot() -> None:
"""执行截图和OCR识别。"""
# TODO: 从原文件迁移函数实现
pass
return ocr_results_var, do_screenshot
+43
View File
@@ -0,0 +1,43 @@
"""预约显示组件
包含预约队列显示和刷新功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable, Tuple
from tkinter.scrolledtext import ScrolledText
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
ScrolledText = TBSrolledText
except ImportError:
from tkinter.scrolledtext import ScrolledText
def create_reservation_display(
parent: Any
):
"""创建预约显示组件。
参数:
parent: 父容器
返回:
(reservation_text, refresh_reservations_func)
"""
reservation_text = ScrolledText(parent)
reservation_text.pack(fill="both", expand=True, padx=10, pady=10)
try:
reservation_text.configure(font=("Consolas", 10))
except Exception:
pass
def refresh_reservations() -> None:
"""刷新预约队列。"""
# TODO: 从原文件迁移函数实现
pass
return reservation_text, refresh_reservations
+47
View File
@@ -0,0 +1,47 @@
"""统计显示组件
包含统计信息显示和刷新功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable, Tuple
from tkinter.scrolledtext import ScrolledText
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
ScrolledText = TBSrolledText
except ImportError:
from tkinter.scrolledtext import ScrolledText
def create_stats_display(
parent: Any,
runner: Any,
status_var: Any
):
"""创建统计显示组件。
参数:
parent: 父容器
runner: 运行器对象
status_var: 状态变量
返回:
(stats_text, refresh_stats_func) 统计文本框和刷新函数
"""
stats_text = ScrolledText(parent)
stats_text.pack(fill="both", expand=True, padx=10, pady=10)
try:
stats_text.configure(font=("Consolas", 10))
except Exception:
pass
def refresh_stats() -> None:
"""刷新统计信息。"""
# TODO: 从原文件迁移函数实现
pass
return stats_text, refresh_stats