refactor(gui): 抽 yanghao_tab UI 创建到 components/yanghao_tab (2456 → 2334)

This commit is contained in:
Your Name committed 2026-05-30 16:06:40 +08:00
1 parent bcb0e363d1
commit 3f04bb23c2
2 files changed
+196 -144

No files matched your search

+174
View File
@@ -0,0 +1,174 @@
"""养号设置 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
+22 -144
View File
@@ -89,6 +89,7 @@ from gui.components.config_io import (
)
from gui.components.debug_tab import setup_debug_tab
from gui.components.logging_tab import setup_logging_tab
from gui.components.yanghao_tab import setup_yanghao_tab
# 导入日志颜色配置模块
try:
@@ -1113,150 +1114,27 @@ def main():
).pack(side=LEFT)
# 养号设置标签(后续代码)
yanghao_tab = ttk.Frame(left_notebook)
left_notebook.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=yg_enabled_var
).pack(side=LEFT)
ttk.Checkbutton(
yg_switch,
text="启用养号动作(爱心/收藏/评论)",
variable=yg_actions_enabled_var,
).pack(side=LEFT, padx=(10, 0))
ttk.Checkbutton(
yg_switch,
text="只养号(仅执行推荐页养号,跳过抽奖/参与)",
variable=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=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=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=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=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=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=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=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=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=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=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=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=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=fudai_quiet_end_hour_var, width=6
).pack(side=LEFT)
# 标签页5:调试参数
_, yg_comment_texts, yg_like_keywords_text, yg_fav_keywords_text = setup_yanghao_tab(
left_notebook,
vars_={
"fudai_quiet_end_hour_var": fudai_quiet_end_hour_var,
"fudai_quiet_hours_enabled_var": fudai_quiet_hours_enabled_var,
"fudai_quiet_start_hour_var": fudai_quiet_start_hour_var,
"yg_actions_enabled_var": yg_actions_enabled_var,
"yg_comment_prob_var": yg_comment_prob_var,
"yg_dwell_on_action_max_var": yg_dwell_on_action_max_var,
"yg_dwell_on_action_min_var": yg_dwell_on_action_min_var,
"yg_enabled_var": yg_enabled_var,
"yg_fav_prob_var": yg_fav_prob_var,
"yg_icon_match_threshold_var": yg_icon_match_threshold_var,
"yg_icon_roi_size_var": yg_icon_roi_size_var,
"yg_like_prob_var": yg_like_prob_var,
"yg_only_var": yg_only_var,
"yg_recommend_duration_var": yg_recommend_duration_var,
"yg_recommend_interval_var": yg_recommend_interval_var,
"yg_step_screenshot_var": yg_step_screenshot_var,
},
)
setup_debug_tab(left_notebook, vars_={
"attend_button_red_ratio_threshold_var": attend_button_red_ratio_threshold_var,
"coupon_template_match_threshold_var": coupon_template_match_threshold_var,