refactor(gui): 抽中奖记录 Tab 整段 UI 到 components/win_record_tab (1739 → 1649)
This commit is contained in:
1 parent
5e3015f59b
commit
aa0f4e05f2
2 files changed
+157
-100
No files matched your search
@@ -0,0 +1,147 @@
|
||||
"""中奖记录 Tab 的 widget 创建段。
|
||||
|
||||
从 ``gui/gui_app.py`` 抽出。包括:
|
||||
- 截图列表 / 预览的左右两栏布局
|
||||
- 操作按钮(刷新列表 / 打开目录 / 实时查看)
|
||||
- 误识别记录管理(刷新/保存)
|
||||
|
||||
依赖通过显式参数注入。返回 ``WinRecordTabHandles`` 让 ``main()`` 后续仍能调度
|
||||
``refresh_win_record`` 与 ``load_false_positives``。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from dataclasses import dataclass
|
||||
from tkinter import ttk
|
||||
from tkinter.constants import BOTH, LEFT, RIGHT, X, Y
|
||||
from typing import Any, Callable, Dict
|
||||
|
||||
from gui.components.win_record_view import (
|
||||
WinRecordView,
|
||||
refresh_win_record as _refresh_win_record_impl,
|
||||
on_win_list_select as _on_win_list_select_impl,
|
||||
open_win_folder as _open_win_folder_impl,
|
||||
load_false_positives as _load_false_positives_impl,
|
||||
save_false_positives as _save_false_positives_impl,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class WinRecordTabHandles:
|
||||
"""``main()`` 后续仍要用的 handles。"""
|
||||
|
||||
refresh_win_record: Callable[[], None]
|
||||
load_false_positives: Callable[[], None]
|
||||
|
||||
|
||||
def setup_win_record_tab(
|
||||
win_record_tab: tk.Misc,
|
||||
*,
|
||||
on_line: Callable[[str], None],
|
||||
ScrolledText_cls: Any,
|
||||
open_realtime_viewer: Callable[[], None],
|
||||
) -> WinRecordTabHandles:
|
||||
"""构建中奖记录 Tab 的 UI 与回调绑定。"""
|
||||
# 中奖记录显示
|
||||
win_record_top = ttk.Frame(win_record_tab)
|
||||
win_record_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
|
||||
win_record_left = ttk.Frame(win_record_tab)
|
||||
win_record_left.pack(side=LEFT, fill=BOTH, expand=True, padx=(10, 5), pady=10)
|
||||
|
||||
win_record_right = ttk.Frame(win_record_tab)
|
||||
win_record_right.pack(
|
||||
side=RIGHT, fill=BOTH, expand=False, padx=(5, 10), pady=10, ipadx=10
|
||||
)
|
||||
|
||||
# 左侧:中奖截图列表
|
||||
win_list_label = ttk.Label(win_record_left, text="中奖截图列表:")
|
||||
win_list_label.pack(anchor="w", padx=(0, 10), pady=(0, 5))
|
||||
|
||||
win_list_frame = ttk.Frame(win_record_left)
|
||||
win_list_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_list_scrollbar = ttk.Scrollbar(win_list_frame)
|
||||
win_list_scrollbar.pack(side=RIGHT, fill=Y)
|
||||
|
||||
win_listbox = tk.Listbox(
|
||||
win_list_frame, yscrollcommand=win_list_scrollbar.set, font=("Consolas", 9)
|
||||
)
|
||||
win_listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
||||
win_list_scrollbar.config(command=win_listbox.yview)
|
||||
|
||||
# 存储文件路径映射(索引 -> 文件路径)
|
||||
_win_file_paths: Dict[int, str] = {}
|
||||
|
||||
# 右侧:截图预览
|
||||
win_preview_label = ttk.Label(win_record_right, text="截图预览:")
|
||||
win_preview_label.pack(anchor="w", pady=(0, 5))
|
||||
|
||||
win_preview_frame = ttk.Frame(win_record_right)
|
||||
win_preview_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_image_label = ttk.Label(win_preview_frame)
|
||||
win_image_label.pack(fill=BOTH, expand=True)
|
||||
_win_img_ref: Dict[str, Any] = {"photo": None}
|
||||
|
||||
# 误识别记录管理
|
||||
false_positive_frame = ttk.LabelFrame(win_record_right, text="误识别记录管理")
|
||||
false_positive_frame.pack(fill=X, pady=(10, 0))
|
||||
|
||||
false_positive_text = ScrolledText_cls(false_positive_frame, height=6)
|
||||
false_positive_text.pack(fill=X, padx=10, pady=10)
|
||||
|
||||
view = WinRecordView(
|
||||
listbox=win_listbox,
|
||||
image_label=win_image_label,
|
||||
preview_frame=win_preview_frame,
|
||||
false_positive_text=false_positive_text,
|
||||
on_line=on_line,
|
||||
file_paths=_win_file_paths,
|
||||
img_ref=_win_img_ref,
|
||||
)
|
||||
|
||||
def refresh_win_record() -> None:
|
||||
_refresh_win_record_impl(view)
|
||||
|
||||
def on_win_list_select(event):
|
||||
_on_win_list_select_impl(view, event)
|
||||
|
||||
win_listbox.bind("<<ListboxSelect>>", on_win_list_select)
|
||||
|
||||
ttk.Button(win_record_top, text="刷新列表", command=refresh_win_record).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
def open_win_folder() -> None:
|
||||
_open_win_folder_impl(view)
|
||||
|
||||
ttk.Button(win_record_top, text="打开目录", command=open_win_folder).pack(side=LEFT)
|
||||
ttk.Button(
|
||||
win_record_top,
|
||||
text="实时查看",
|
||||
command=open_realtime_viewer,
|
||||
).pack(side=LEFT, padx=(8, 0))
|
||||
|
||||
def load_false_positives() -> None:
|
||||
_load_false_positives_impl(view)
|
||||
|
||||
def save_false_positives() -> None:
|
||||
_save_false_positives_impl(view)
|
||||
|
||||
false_positive_btn_frame = ttk.Frame(false_positive_frame)
|
||||
false_positive_btn_frame.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Button(
|
||||
false_positive_btn_frame, text="刷新", command=load_false_positives
|
||||
).pack(side=LEFT, padx=(0, 5))
|
||||
ttk.Button(
|
||||
false_positive_btn_frame, text="保存", command=save_false_positives
|
||||
).pack(side=LEFT)
|
||||
|
||||
load_false_positives()
|
||||
|
||||
return WinRecordTabHandles(
|
||||
refresh_win_record=refresh_win_record,
|
||||
load_false_positives=load_false_positives,
|
||||
)
|
||||
+10
-100
@@ -96,6 +96,7 @@ from gui.components.filter_tab import setup_filter_tab
|
||||
from gui.components.realtime_tab import setup_realtime_tab
|
||||
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
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
@@ -1577,108 +1578,17 @@ def main():
|
||||
side=LEFT, padx=(10, 0)
|
||||
)
|
||||
|
||||
# 中奖记录显示
|
||||
win_record_top = ttk.Frame(win_record_tab)
|
||||
win_record_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
|
||||
win_record_left = ttk.Frame(win_record_tab)
|
||||
win_record_left.pack(side=LEFT, fill=BOTH, expand=True, padx=(10, 5), pady=10)
|
||||
|
||||
win_record_right = ttk.Frame(win_record_tab)
|
||||
win_record_right.pack(
|
||||
side=RIGHT, fill=BOTH, expand=False, padx=(5, 10), pady=10, ipadx=10
|
||||
)
|
||||
|
||||
# 左侧:中奖截图列表
|
||||
win_list_label = ttk.Label(win_record_left, text="中奖截图列表:")
|
||||
win_list_label.pack(anchor="w", padx=(0, 10), pady=(0, 5))
|
||||
|
||||
win_list_frame = ttk.Frame(win_record_left)
|
||||
win_list_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_list_scrollbar = ttk.Scrollbar(win_list_frame)
|
||||
win_list_scrollbar.pack(side=RIGHT, fill=Y)
|
||||
|
||||
win_listbox = tk.Listbox(
|
||||
win_list_frame, yscrollcommand=win_list_scrollbar.set, font=("Consolas", 9)
|
||||
)
|
||||
win_listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
||||
win_list_scrollbar.config(command=win_listbox.yview)
|
||||
|
||||
# 存储文件路径映射(索引 -> 文件路径)
|
||||
_win_file_paths: dict[int, str] = {}
|
||||
|
||||
# 右侧:截图预览
|
||||
win_preview_label = ttk.Label(win_record_right, text="截图预览:")
|
||||
win_preview_label.pack(anchor="w", pady=(0, 5))
|
||||
|
||||
win_preview_frame = ttk.Frame(win_record_right)
|
||||
win_preview_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_image_label = ttk.Label(win_preview_frame)
|
||||
win_image_label.pack(fill=BOTH, expand=True)
|
||||
_win_img_ref: dict[str, Any] = {"photo": None}
|
||||
|
||||
def refresh_win_record():
|
||||
_refresh_win_record_impl(_win_record_view)
|
||||
|
||||
def on_win_list_select(event):
|
||||
_on_win_list_select_impl(_win_record_view, event)
|
||||
win_listbox.bind("<<ListboxSelect>>", on_win_list_select)
|
||||
|
||||
ttk.Button(win_record_top, text="刷新列表", command=refresh_win_record).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
def open_win_folder():
|
||||
_open_win_folder_impl(_win_record_view)
|
||||
|
||||
ttk.Button(win_record_top, text="打开目录", command=open_win_folder).pack(side=LEFT)
|
||||
ttk.Button(
|
||||
win_record_top,
|
||||
text="实时查看",
|
||||
command=(
|
||||
lambda: (
|
||||
_open_realtime_viewer_impl()
|
||||
if callable(_open_realtime_viewer_impl)
|
||||
else None
|
||||
)
|
||||
),
|
||||
).pack(side=LEFT, padx=(8, 0))
|
||||
|
||||
# 误识别记录管理
|
||||
false_positive_frame = ttk.LabelFrame(win_record_right, text="误识别记录管理")
|
||||
false_positive_frame.pack(fill=X, pady=(10, 0))
|
||||
|
||||
false_positive_text = ScrolledText(false_positive_frame, height=6)
|
||||
false_positive_text.pack(fill=X, padx=10, pady=10)
|
||||
|
||||
_win_record_view = _WinRecordView(
|
||||
listbox=win_listbox,
|
||||
image_label=win_image_label,
|
||||
preview_frame=win_preview_frame,
|
||||
false_positive_text=false_positive_text,
|
||||
_win_record_handles = setup_win_record_tab(
|
||||
win_record_tab,
|
||||
on_line=on_line,
|
||||
file_paths=_win_file_paths,
|
||||
img_ref=_win_img_ref,
|
||||
ScrolledText_cls=ScrolledText,
|
||||
open_realtime_viewer=lambda: (
|
||||
_open_realtime_viewer_impl()
|
||||
if callable(_open_realtime_viewer_impl)
|
||||
else None
|
||||
),
|
||||
)
|
||||
|
||||
def load_false_positives():
|
||||
_load_false_positives_impl(_win_record_view)
|
||||
|
||||
def save_false_positives():
|
||||
_save_false_positives_impl(_win_record_view)
|
||||
|
||||
false_positive_btn_frame = ttk.Frame(false_positive_frame)
|
||||
false_positive_btn_frame.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Button(
|
||||
false_positive_btn_frame, text="刷新", command=load_false_positives
|
||||
).pack(side=LEFT, padx=(0, 5))
|
||||
ttk.Button(
|
||||
false_positive_btn_frame, text="保存", command=save_false_positives
|
||||
).pack(side=LEFT)
|
||||
|
||||
load_false_positives()
|
||||
refresh_win_record = _win_record_handles.refresh_win_record
|
||||
|
||||
pump_logs()
|
||||
|
||||
|
||||
Reference in new issue
Block a user