Files
douyi_guaji_main/gui/components/log_viewer.py
T
Your Name 26df350755 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.
2025-12-28 14:47:31 +08:00

58 lines
1.3 KiB
Python

"""日志查看组件
包含日志显示、搜索等功能的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