refactor(gui): 5 个简单文本 Tab 用 simple_tabs 模板复用 (1571 → 1537)
This commit is contained in:
1 parent
32e374e2c2
commit
728ef3cd79
2 files changed
+42
-40
No files matched your search
@@ -0,0 +1,36 @@
|
||||
"""通用的"简单文本 Tab"工厂(顶部按钮区 + ScrolledText + 可选配置)。
|
||||
|
||||
从 ``gui/gui_app.py`` 抽出。多个 Tab(统计信息 / 预约队列 / 高价值房间 /
|
||||
行为日志 / OCR 结果)用相同模式:
|
||||
- top frame
|
||||
- ScrolledText 文本主体(Consolas 10 字体)
|
||||
|
||||
抽出 ``setup_simple_text_tab`` 复用此模板。返回 ``(top_frame, text_widget)``,
|
||||
调用方负责接下来在 ``top_frame`` 中加按钮 / 在 ``text_widget`` 中刷新内容。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter.constants import BOTH, X
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
def setup_simple_text_tab(
|
||||
tab: tk.Misc,
|
||||
*,
|
||||
ScrolledText_cls: Any,
|
||||
) -> Tuple[ttk.Frame, tk.Text]:
|
||||
"""构建 "顶部按钮区 + ScrolledText" 模板,返回 ``(top, text)``。"""
|
||||
top = ttk.Frame(tab)
|
||||
top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
|
||||
text = ScrolledText_cls(tab)
|
||||
text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return top, text
|
||||
+6
-40
@@ -98,6 +98,7 @@ from gui.components.log_text_colors import configure_log_text_colors
|
||||
from gui.components.log_search_toolbar import setup_log_search_toolbar
|
||||
from gui.components.win_record_tab import setup_win_record_tab
|
||||
from gui.components.actions_log_toolbar import setup_actions_log_toolbar
|
||||
from gui.components.simple_tabs import setup_simple_text_tab
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
@@ -1403,14 +1404,7 @@ def main():
|
||||
status_setter=status_var.set,
|
||||
)
|
||||
# 统计信息显示
|
||||
stats_top = ttk.Frame(stats_tab)
|
||||
stats_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
stats_text = ScrolledText(stats_tab)
|
||||
stats_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
stats_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
stats_top, stats_text = setup_simple_text_tab(stats_tab, ScrolledText_cls=ScrolledText)
|
||||
|
||||
def refresh_stats():
|
||||
"""委托给 gui/components/stats_formatter.format_stats(纯字符串构建)。"""
|
||||
@@ -1431,14 +1425,7 @@ def main():
|
||||
ttk.Button(stats_top, text="刷新", command=refresh_stats).pack(side=LEFT)
|
||||
|
||||
# 预约队列显示
|
||||
reservation_top = ttk.Frame(reservation_tab)
|
||||
reservation_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
reservation_text = ScrolledText(reservation_tab)
|
||||
reservation_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
reservation_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
reservation_top, reservation_text = setup_simple_text_tab(reservation_tab, ScrolledText_cls=ScrolledText)
|
||||
|
||||
def refresh_reservations():
|
||||
_refresh_reservations_impl(reservation_text)
|
||||
@@ -1448,14 +1435,7 @@ def main():
|
||||
)
|
||||
|
||||
# 高价值房间显示
|
||||
high_value_top = ttk.Frame(high_value_tab)
|
||||
high_value_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
high_value_text = ScrolledText(high_value_tab)
|
||||
high_value_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
high_value_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
high_value_top, high_value_text = setup_simple_text_tab(high_value_tab, ScrolledText_cls=ScrolledText)
|
||||
|
||||
def refresh_high_value_rooms():
|
||||
_refresh_high_value_rooms_impl(high_value_text)
|
||||
@@ -1465,14 +1445,7 @@ def main():
|
||||
)
|
||||
|
||||
# 行为日志显示(点击/识别/耗时)
|
||||
actions_log_top = ttk.Frame(actions_log_tab)
|
||||
actions_log_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
actions_log_text = ScrolledText(actions_log_tab)
|
||||
actions_log_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
actions_log_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
actions_log_top, actions_log_text = setup_simple_text_tab(actions_log_tab, ScrolledText_cls=ScrolledText)
|
||||
|
||||
_actions_log_handles = setup_actions_log_toolbar(
|
||||
actions_log_top,
|
||||
@@ -1482,14 +1455,7 @@ def main():
|
||||
refresh_actions_log = _actions_log_handles.refresh_actions_log
|
||||
|
||||
# OCR结果显示
|
||||
ocr_results_top = ttk.Frame(ocr_results_tab)
|
||||
ocr_results_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
ocr_results_text = ScrolledText(ocr_results_tab)
|
||||
ocr_results_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
ocr_results_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
ocr_results_top, ocr_results_text = setup_simple_text_tab(ocr_results_tab, ScrolledText_cls=ScrolledText)
|
||||
|
||||
def update_ocr_results(results):
|
||||
_update_ocr_results_impl(ocr_results_text, results)
|
||||
|
||||
Reference in new issue
Block a user