"""养号设置 Tab UI 创建逻辑(16 个 var)。 从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内长 144 行的 widget 创建段。 依赖通过显式参数注入: - ``parent`` - ``left_notebook`` (tab 父容器) - ``vars_`` - 名→Var 的 ``Dict[str, tk.Variable]`` 返回 ``(yanghao_tab, yg_comment_texts, yg_like_keywords_text, yg_fav_keywords_text)``, 后 3 个 widget 由 ``main()`` 收集到 ``_config_io_texts`` 用于 load/save 配置。 """ from __future__ import annotations import tkinter as tk from tkinter import ttk from tkinter.constants import BOTH, LEFT, X from typing import Dict, Tuple try: from ttkbootstrap.scrolled import ScrolledText # type: ignore[import] except ImportError: from tkinter.scrolledtext import ScrolledText # type: ignore[no-redef] def setup_yanghao_tab( parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable], ) -> Tuple[ttk.Frame, tk.Text, tk.Text, tk.Text]: yanghao_tab = ttk.Frame(parent) parent.add(yanghao_tab, text="养号设置") yg_box = ttk.LabelFrame(yanghao_tab, text="推荐页养号(爱心/收藏/评论)") yg_box.pack(fill=X, padx=10, pady=(10, 10)) yg_switch = ttk.Frame(yg_box) yg_switch.pack(fill=X, padx=10, pady=(10, 6)) ttk.Checkbutton( yg_switch, text="养号总开关(关闭则跳过推荐页养号)", variable=vars_["yg_enabled_var"] ).pack(side=LEFT) ttk.Checkbutton( yg_switch, text="启用养号动作(爱心/收藏/评论)", variable=vars_["yg_actions_enabled_var"], ).pack(side=LEFT, padx=(10, 0)) ttk.Checkbutton( yg_switch, text="只养号(仅执行推荐页养号,跳过抽奖/参与)", variable=vars_["yg_only_var"], ).pack(side=LEFT, padx=(10, 0)) yg0 = ttk.Frame(yg_box) yg0.pack(fill=X, padx=10, pady=(0, 8)) ttk.Checkbutton( yg0, text="逐步截图(调试用,生成 pic/*/latest.png)", variable=vars_["yg_step_screenshot_var"], ).pack(side=LEFT) yg_time = ttk.Frame(yg_box) yg_time.pack(fill=X, padx=10, pady=(0, 8)) ttk.Label(yg_time, text="养号时长(秒):").pack(side=LEFT) ttk.Spinbox( yg_time, from_=1, to=3600, increment=5, textvariable=vars_["yg_recommend_duration_var"], width=8, ).pack(side=LEFT) ttk.Label(yg_time, text="养号间隔(秒):").pack(side=LEFT, padx=(12, 0)) ttk.Spinbox( yg_time, from_=0, to=3600, increment=10, textvariable=vars_["yg_recommend_interval_var"], width=8, ).pack(side=LEFT) ttk.Label(yg_time, text="(0=每次触发都执行)").pack(side=LEFT, padx=(6, 0)) yg1 = ttk.Frame(yg_box) yg1.pack(fill=X, padx=10, pady=(0, 8)) ttk.Label(yg1, text="爱心概率:").pack(side=LEFT) ttk.Spinbox( yg1, from_=0.0, to=1.0, increment=0.05, textvariable=vars_["yg_like_prob_var"], width=6 ).pack(side=LEFT) ttk.Label(yg1, text="收藏概率:").pack(side=LEFT, padx=(10, 0)) ttk.Spinbox( yg1, from_=0.0, to=1.0, increment=0.05, textvariable=vars_["yg_fav_prob_var"], width=6 ).pack(side=LEFT) ttk.Label(yg1, text="评论概率:").pack(side=LEFT, padx=(10, 0)) ttk.Spinbox( yg1, from_=0.0, to=1.0, increment=0.05, textvariable=vars_["yg_comment_prob_var"], width=6, ).pack(side=LEFT) ttk.Label(yg1, text="(0~1)").pack(side=LEFT, padx=(6, 0)) yg1b = ttk.Frame(yg_box) yg1b.pack(fill=X, padx=10, pady=(0, 8)) ttk.Label(yg1b, text="检测动作后停留(秒):").pack(side=LEFT) ttk.Spinbox( yg1b, from_=0.0, to=120.0, increment=1.0, textvariable=vars_["yg_dwell_on_action_min_var"], width=6, ).pack(side=LEFT) ttk.Label(yg1b, text="~").pack(side=LEFT, padx=(6, 6)) ttk.Spinbox( yg1b, from_=0.0, to=120.0, increment=1.0, textvariable=vars_["yg_dwell_on_action_max_var"], width=6, ).pack(side=LEFT) ttk.Label(yg1b, text="(随机范围)").pack(side=LEFT, padx=(6, 0)) yg2 = ttk.Frame(yg_box) yg2.pack(fill=X, padx=10, pady=(0, 8)) ttk.Label(yg2, text="图标ROI大小(px):").pack(side=LEFT) ttk.Spinbox( yg2, from_=80, to=600, increment=10, textvariable=vars_["yg_icon_roi_size_var"], width=6 ).pack(side=LEFT) ttk.Label(yg2, text="匹配阈值:").pack(side=LEFT, padx=(10, 0)) ttk.Spinbox( yg2, from_=0.0, to=1.0, increment=0.01, textvariable=vars_["yg_icon_match_threshold_var"], width=6, ).pack(side=LEFT) yg_texts = ttk.Frame(yg_box) yg_texts.pack(fill=BOTH, expand=True, padx=10, pady=(0, 10)) ttk.Label(yg_texts, text="评论文案库(每行一条):").pack(anchor="w") yg_comment_texts = ScrolledText(yg_texts, height=4) yg_comment_texts.pack(fill=X, pady=(0, 6)) yg_kw = ttk.Frame(yg_texts) yg_kw.pack(fill=BOTH, expand=True) ttk.Label(yg_kw, text="爱心关键词(每行一条):").pack(anchor="w") yg_like_keywords_text = ScrolledText(yg_kw, height=3) yg_like_keywords_text.pack(fill=X, pady=(0, 6)) ttk.Label(yg_kw, text="收藏关键词(每行一条):").pack(anchor="w") yg_fav_keywords_text = ScrolledText(yg_kw, height=3) yg_fav_keywords_text.pack(fill=X) quiet_box = ttk.LabelFrame(yanghao_tab, text="定时禁抢(仅养号)") quiet_box.pack(fill=X, padx=10, pady=(0, 10)) quiet_r0 = ttk.Frame(quiet_box) quiet_r0.pack(fill=X, padx=10, pady=(10, 6)) ttk.Checkbutton( quiet_r0, text="启用定时禁抢", variable=vars_["fudai_quiet_hours_enabled_var"] ).pack(side=LEFT) quiet_r1 = ttk.Frame(quiet_box) quiet_r1.pack(fill=X, padx=10, pady=(0, 10)) ttk.Label(quiet_r1, text="开始小时:").pack(side=LEFT) ttk.Spinbox( quiet_r1, from_=0, to=23, textvariable=vars_["fudai_quiet_start_hour_var"], width=6 ).pack(side=LEFT) ttk.Label(quiet_r1, text="结束小时:").pack(side=LEFT, padx=(12, 0)) ttk.Spinbox( quiet_r1, from_=0, to=23, textvariable=vars_["fudai_quiet_end_hour_var"], width=6 ).pack(side=LEFT) # 标签页5:调试参数 return yanghao_tab, yg_comment_texts, yg_like_keywords_text, yg_fav_keywords_text