Files

62 lines
1.6 KiB
Python

"""运行日志 Tab 的 widget 创建段(log_box + log_text + 搜索工具栏 + 配色)。
从 ``gui/gui_app.py`` 抽出。返回 ``LogTabHandles`` 暴露给 ``main()`` 后续 pump_logs。
"""
from __future__ import annotations
import tkinter as tk
from dataclasses import dataclass
from tkinter import ttk
from tkinter.constants import BOTH
from typing import Any, Callable
from gui.components.log_search_toolbar import (
setup_log_search_toolbar,
LogSearchToolbarHandles,
)
from gui.components.log_text_colors import configure_log_text_colors
@dataclass
class LogTabHandles:
"""``main()`` 后续仍要用的 handles。"""
log_text: tk.Text
log_filter_var: tk.StringVar
refresh_run_log: Callable[[], None]
def setup_log_tab(
log_tab: tk.Misc,
*,
runner: Any,
ScrolledText_cls: Any,
theme_getter: Callable[[], str],
) -> LogTabHandles:
"""构建运行日志 Tab(log_box + log_text + 搜索工具栏 + 配色)。"""
log_box = ttk.Frame(log_tab)
log_box.pack(fill=BOTH, expand=True)
log_text = ScrolledText_cls(log_box)
try:
log_text.configure(font=("Consolas", 10))
except Exception:
pass
log_text.pack(fill=BOTH, expand=True, padx=10, pady=(0, 10))
handles: LogSearchToolbarHandles = setup_log_search_toolbar(
log_box,
log_text=log_text,
runner=runner,
theme_getter=theme_getter,
)
configure_log_text_colors(log_text, theme_getter=theme_getter)
return LogTabHandles(
log_text=log_text,
log_filter_var=handles.log_filter_var,
refresh_run_log=handles.refresh_run_log,
)