130 lines
4.4 KiB
Python
130 lines
4.4 KiB
Python
"""左侧配置区:PanedWindow 布局 + 7 个配置 Tab + load/save_ui_to_config 闭包。
|
|
|
|
从 ``gui/gui_app.py`` 抽出。包括:
|
|
- ``ttk.PanedWindow`` (左/右分栏)
|
|
- 左侧 ``ttk.Notebook`` 容器
|
|
- 7 个配置 Tab(运行/筛选/高价值预约/养号/调试/日志/关键词)
|
|
- ``load_config_to_ui`` / ``save_ui_to_config`` / ``save_logging_config`` 闭包
|
|
- 启动时一次 ``load_config_to_ui()``
|
|
|
|
返回 ``LeftConfigArea`` 暴露给 ``main()`` 的引用:
|
|
- ``right_frame``: 右侧分栏(传给后续 setup_main_notebook)
|
|
- ``save_ui_to_config``: 保存配置回调
|
|
"""
|
|
|
|
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, Dict
|
|
|
|
from gui.components.config_io import (
|
|
load_config_to_ui as _load_config_to_ui_impl,
|
|
save_ui_to_config as _save_ui_to_config_impl,
|
|
)
|
|
from gui.components.logging_config_io import save_logging_config as _save_logging_config_impl
|
|
from gui.components.run_tab import setup_run_tab
|
|
from gui.components.filter_tab import setup_filter_tab
|
|
from gui.components.reservation_tab import setup_reservation_tab
|
|
from gui.components.yanghao_tab import setup_yanghao_tab
|
|
from gui.components.debug_tab import setup_debug_tab
|
|
from gui.components.license_tab import setup_license_tab
|
|
from gui.components.logging_tab import setup_logging_tab
|
|
from gui.components.keywords_tab import setup_keywords_tab
|
|
|
|
|
|
@dataclass
|
|
class LeftConfigArea:
|
|
"""``main()`` 后续仍要用的引用。"""
|
|
|
|
right_frame: ttk.Frame
|
|
save_ui_to_config: Callable[[], None]
|
|
|
|
|
|
def setup_left_config_area(
|
|
root: tk.Misc,
|
|
*,
|
|
vars_: Dict[str, tk.Variable],
|
|
cfg: dict,
|
|
ScrolledText_cls: Any,
|
|
read_config: Callable[[], dict],
|
|
write_config: Callable[[dict], None],
|
|
on_line: Callable[[str], None],
|
|
) -> LeftConfigArea:
|
|
"""构建左侧配置区(PanedWindow + 7 Tabs + load/save 闭包)。
|
|
|
|
``cfg`` 由调用方传入,``load_config_to_ui`` 内部把读到的新 cfg 重新赋回
|
|
``cfg`` dict 的内容(不能 reassign 局部 var,所以用 ``dict.clear() + update``)。
|
|
"""
|
|
# 中部:左侧配置(使用 Notebook 标签页) + 右侧日志/预览(支持拖拽调整宽度)
|
|
mid = ttk.PanedWindow(root, orient="horizontal")
|
|
mid.pack(fill=BOTH, expand=True, padx=12, pady=(0, 12))
|
|
|
|
left_wrap = ttk.Frame(mid)
|
|
right_frame = ttk.Frame(mid)
|
|
mid.add(left_wrap, weight=0) # 左侧配置区域
|
|
mid.add(right_frame, weight=1) # 右侧日志/预览区域
|
|
|
|
# 左侧使用 Notebook 标签页组织配置
|
|
left_notebook = ttk.Notebook(left_wrap)
|
|
left_notebook.pack(fill=BOTH, expand=True)
|
|
|
|
def save_logging_config() -> None:
|
|
_save_logging_config_impl(
|
|
vars_=vars_,
|
|
read_config=read_config,
|
|
write_config=write_config,
|
|
on_line=on_line,
|
|
)
|
|
|
|
# 创建左侧配置标签页
|
|
setup_run_tab(left_notebook, vars_=vars_)
|
|
setup_filter_tab(left_notebook, vars_=vars_)
|
|
setup_reservation_tab(left_notebook, vars_=vars_)
|
|
_, yg_comment_texts, yg_like_keywords_text, yg_fav_keywords_text = setup_yanghao_tab(
|
|
left_notebook, vars_=vars_,
|
|
)
|
|
setup_debug_tab(left_notebook, vars_=vars_)
|
|
setup_license_tab(left_notebook, on_line=on_line)
|
|
setup_logging_tab(left_notebook, vars_=vars_, on_save_logging=save_logging_config)
|
|
want_text, not_want_text = setup_keywords_tab(
|
|
left_notebook, ScrolledText_cls=ScrolledText_cls,
|
|
)
|
|
|
|
texts_ = {
|
|
"not_want_text": not_want_text,
|
|
"want_text": want_text,
|
|
"yg_comment_texts": yg_comment_texts,
|
|
"yg_fav_keywords_text": yg_fav_keywords_text,
|
|
"yg_like_keywords_text": yg_like_keywords_text,
|
|
}
|
|
|
|
def load_config_to_ui() -> None:
|
|
# cfg 是 dict 的 alias,我们替换它的内容(不 reassign 否则丢失 main 的引用)
|
|
new_cfg = _load_config_to_ui_impl(
|
|
vars_=vars_,
|
|
texts_=texts_,
|
|
read_config=read_config,
|
|
)
|
|
cfg.clear()
|
|
cfg.update(new_cfg)
|
|
|
|
def save_ui_to_config() -> None:
|
|
_save_ui_to_config_impl(
|
|
vars_=vars_,
|
|
texts_=texts_,
|
|
cfg=cfg,
|
|
read_config=read_config,
|
|
write_config=write_config,
|
|
on_line=on_line,
|
|
)
|
|
|
|
load_config_to_ui()
|
|
|
|
return LeftConfigArea(
|
|
right_frame=right_frame,
|
|
save_ui_to_config=save_ui_to_config,
|
|
)
|