refactor(gui): 抽 keywords_tab UI 到 components/keywords_tab (1461 → 1444)

This commit is contained in:
Your Name committed 2026-05-30 16:58:53 +08:00
1 parent 8575f04ab9
commit 3a7a7a3b75
2 files changed
+43 -19

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
"""关键词 Tab UI 创建逻辑(白名单 + 黑名单)。
从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内长 18 行的 widget 创建段。
返回 ``(want_text, not_want_text)`` 两个 ScrolledText widget,供 main() 后续
绑定到 ``_config_io_texts`` 字典用于 load/save 配置。
"""
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_keywords_tab(
parent: ttk.Notebook,
*,
ScrolledText_cls: Any,
) -> Tuple[tk.Text, tk.Text]:
"""构建关键词 Tab,返回 ``(want_text, not_want_text)``。"""
keywords_tab = ttk.Frame(parent)
parent.add(keywords_tab, text="关键词")
kw_box = ttk.LabelFrame(keywords_tab, text="关键词(每行一个)")
kw_box.pack(fill=BOTH, expand=True, padx=10, pady=(10, 10))
ttk.Label(kw_box, text="想要 contains_want(白名单,空=不限制)").pack(
anchor="w", padx=10, pady=(10, 4)
)
want_text = ScrolledText_cls(kw_box, height=6)
want_text.pack(fill=X, padx=10, pady=(0, 10))
ttk.Label(kw_box, text="不想要 contains_not_want(黑名单)").pack(
anchor="w", padx=10, pady=(0, 4)
)
not_want_text = ScrolledText_cls(kw_box, height=8)
not_want_text.pack(fill=X, padx=10, pady=(0, 10))
return want_text, not_want_text
+2 -19
View File
@@ -100,6 +100,7 @@ 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
from gui.components.preview_tab import setup_preview_tab
from gui.components.keywords_tab import setup_keywords_tab
# 导入日志颜色配置模块
try:
@@ -912,25 +913,7 @@ def main():
on_save_logging=save_logging_config,
)
# 标签页7:关键词
keywords_tab = ttk.Frame(left_notebook)
left_notebook.add(keywords_tab, text="关键词")
kw_box = ttk.LabelFrame(keywords_tab, text="关键词(每行一个)")
kw_box.pack(fill=BOTH, expand=True, padx=10, pady=(10, 10))
ttk.Label(kw_box, text="想要 contains_want(白名单,空=不限制)").pack(
anchor="w", padx=10, pady=(10, 4)
)
want_text = ScrolledText(kw_box, height=6)
want_text.pack(fill=X, padx=10, pady=(0, 10))
ttk.Label(kw_box, text="不想要 contains_not_want(黑名单)").pack(
anchor="w", padx=10, pady=(0, 4)
)
not_want_text = ScrolledText(kw_box, height=8)
not_want_text.pack(fill=X, padx=10, pady=(0, 10))
want_text, not_want_text = setup_keywords_tab(left_notebook, ScrolledText_cls=ScrolledText)
_config_io_vars = {
"attend_button_red_ratio_threshold_var": attend_button_red_ratio_threshold_var,
"auto_join_var": auto_join_var,