Add dashboard desktop UI entry
This commit is contained in:
1 parent
b61f766ea6
commit
e977f6054d
7 files changed
+841
No files matched your search
@@ -0,0 +1,6 @@
|
||||
"""Dashboard-style desktop GUI entry.
|
||||
|
||||
This package is intentionally separate from ``gui.gui_app`` so the classic
|
||||
desktop UI remains available while the dashboard UI can evolve independently.
|
||||
"""
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
from douyin.core.version import print_version_banner
|
||||
from gui.components.config_vars import build_config_vars
|
||||
from gui.components.run_params_builder import get_params as build_run_params
|
||||
from gui.gui_core import Runner, read_config, write_config
|
||||
|
||||
from . import theme
|
||||
from .data import load_dashboard_data
|
||||
from .pages import PAGES
|
||||
from .widgets import ScrollFrame, clear
|
||||
|
||||
|
||||
class DashboardApp:
|
||||
def __init__(self) -> None:
|
||||
self.root = tk.Tk()
|
||||
self.root.title("抖音福袋挂机 - 数据看板")
|
||||
self.root.geometry("1480x940")
|
||||
self.root.minsize(1180, 760)
|
||||
theme.setup_styles(self.root)
|
||||
self.data = load_dashboard_data()
|
||||
self.runner = Runner(self._on_runner_line)
|
||||
self.config_vars = build_config_vars(self.data.cfg)
|
||||
self.current_page = "数据看板"
|
||||
self.status_var = tk.StringVar(value="就绪")
|
||||
self.device_var = tk.StringVar(value="自动选择设备")
|
||||
self.y_var = tk.StringVar(value=str(self.data.cfg.get("y_pianyi", 0) if isinstance(self.data.cfg, dict) else 0))
|
||||
self._build_shell()
|
||||
self.show_page(self.current_page)
|
||||
|
||||
def _build_shell(self) -> None:
|
||||
root = self.root
|
||||
shell = ttk.Frame(root, style="Dashboard.TFrame")
|
||||
shell.pack(fill="both", expand=True)
|
||||
|
||||
top = ttk.Frame(shell, style="Dashboard.TFrame")
|
||||
top.pack(fill="x", padx=18, pady=(14, 8))
|
||||
ttk.Label(top, text="抖音福袋挂机", style="Title.TLabel").pack(side="left", padx=(0, 16))
|
||||
ttk.Label(top, text="设备:", background=theme.BG, foreground=theme.MUTED).pack(side="left")
|
||||
ttk.Combobox(top, textvariable=self.device_var, values=["自动选择设备"], width=28).pack(side="left", padx=(4, 8))
|
||||
for text, command in [
|
||||
("刷新设备", self.refresh_data),
|
||||
("扫描WiFi", self._noop),
|
||||
("WiFi ADB", lambda: self.show_page("WiFi ADB")),
|
||||
]:
|
||||
ttk.Button(top, text=text, style="Soft.TButton", command=command).pack(side="left", padx=4)
|
||||
ttk.Label(top, text="Y偏移:", background=theme.BG, foreground=theme.MUTED).pack(side="left", padx=(10, 3))
|
||||
ttk.Spinbox(top, from_=-200, to=200, textvariable=self.y_var, width=6).pack(side="left")
|
||||
ttk.Button(top, text="保存配置", style="Soft.TButton", command=self._noop).pack(side="right", padx=4)
|
||||
ttk.Button(top, text="截图+OCR", style="Primary.TButton", command=self.refresh_data).pack(side="right", padx=4)
|
||||
|
||||
main = ttk.Frame(shell, style="Dashboard.TFrame")
|
||||
main.pack(fill="both", expand=True, padx=18, pady=8)
|
||||
main.grid_columnconfigure(1, weight=1)
|
||||
main.grid_rowconfigure(0, weight=1)
|
||||
|
||||
sidebar = ttk.Frame(main, style="Surface.TFrame")
|
||||
sidebar.grid(row=0, column=0, sticky="nsw", padx=(0, 14))
|
||||
for group_title, names in [
|
||||
("总览", ["数据看板"]),
|
||||
("配置", ["运行设置", "筛选设置", "高价值预约", "养号设置", "调试参数", "授权", "日志配置", "关键词"]),
|
||||
("数据", ["运行日志", "截图预览", "统计信息", "预约队列", "高价值房间", "行为日志", "实时状态", "OCR结果", "中奖记录", "映射表"]),
|
||||
("连接", ["WiFi ADB"]),
|
||||
]:
|
||||
ttk.Label(sidebar, text=group_title, background=theme.SURFACE, foreground=theme.MUTED, font=theme.FONT_SMALL).pack(anchor="w", padx=14, pady=(14, 5))
|
||||
for name in names:
|
||||
ttk.Button(sidebar, text=name, style="Sidebar.TButton", command=lambda n=name: self.show_page(n)).pack(fill="x", padx=10, pady=2)
|
||||
|
||||
self.content_scroll = ScrollFrame(main)
|
||||
self.content_scroll.grid(row=0, column=1, sticky="nsew")
|
||||
self.content = self.content_scroll.inner
|
||||
|
||||
bottom = ttk.Frame(shell, style="Dashboard.TFrame")
|
||||
bottom.pack(fill="x", padx=18, pady=(4, 14))
|
||||
ttk.Button(bottom, text="开始运行", style="Primary.TButton", command=self.start_run).pack(side="left", padx=(0, 8))
|
||||
ttk.Button(bottom, text="停止", style="Soft.TButton", command=self.stop_run).pack(side="left", padx=4)
|
||||
ttk.Button(bottom, text="强制停止", style="Danger.TButton", command=self.force_stop_run).pack(side="left", padx=4)
|
||||
ttk.Button(bottom, text="发送返回键", style="Soft.TButton", command=self.send_back_key).pack(side="left", padx=8)
|
||||
ttk.Label(bottom, textvariable=self.status_var, background=theme.BG, foreground=theme.GREEN).pack(side="right")
|
||||
|
||||
def _noop(self) -> None:
|
||||
self.status_var.set("新版看板入口:当前操作保留为独立预览")
|
||||
|
||||
def _on_runner_line(self, line: str) -> None:
|
||||
try:
|
||||
self.status_var.set((line or "").strip()[:120] or "就绪")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _params(self):
|
||||
try:
|
||||
self.config_vars = build_config_vars(read_config())
|
||||
except Exception:
|
||||
pass
|
||||
self.config_vars["device_var"] = self.device_var
|
||||
self.config_vars["y_var"].set(int(self.y_var.get() or 0))
|
||||
return build_run_params(self.config_vars)
|
||||
|
||||
def start_run(self) -> None:
|
||||
if self.runner.is_running():
|
||||
self.status_var.set("已在运行中")
|
||||
return
|
||||
try:
|
||||
cfg = read_config()
|
||||
cfg["y_pianyi"] = int(self.y_var.get() or 0)
|
||||
write_config(cfg)
|
||||
self.runner.start(self._params())
|
||||
self.status_var.set("运行中")
|
||||
self.refresh_data()
|
||||
except Exception as exc:
|
||||
self.status_var.set(f"启动失败:{exc}")
|
||||
|
||||
def stop_run(self) -> None:
|
||||
self.runner.stop()
|
||||
self.status_var.set("已停止")
|
||||
|
||||
def force_stop_run(self) -> None:
|
||||
self.runner.force_stop()
|
||||
self.status_var.set("已停止(强制)")
|
||||
|
||||
def send_back_key(self) -> None:
|
||||
dev = self.device_var.get().strip()
|
||||
ok = self.runner.send_back_key("" if dev == "自动选择设备" else dev)
|
||||
self.status_var.set("返回键已发送" if ok else "发送返回键失败")
|
||||
|
||||
def refresh_data(self) -> None:
|
||||
self.data = load_dashboard_data()
|
||||
self.status_var.set("已刷新")
|
||||
self.show_page(self.current_page)
|
||||
|
||||
def show_page(self, name: str) -> None:
|
||||
self.current_page = name
|
||||
clear(self.content)
|
||||
builder = PAGES.get(name, PAGES["数据看板"])
|
||||
builder(self.content, self.data)
|
||||
try:
|
||||
self.content_scroll.canvas.yview_moveto(0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def run(self) -> None:
|
||||
self.root.mainloop()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
try:
|
||||
print_version_banner("gui_dashboard_app")
|
||||
except Exception:
|
||||
pass
|
||||
DashboardApp().run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,129 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
@dataclass
|
||||
class DashboardData:
|
||||
cfg: dict[str, Any]
|
||||
run_log: list[str]
|
||||
action_log: list[str]
|
||||
reservations: list[dict[str, Any]]
|
||||
high_value_rooms: list[dict[str, Any]]
|
||||
mapping_rows: list[dict[str, Any]]
|
||||
win_images: list[Path]
|
||||
screenshot_path: Path | None
|
||||
ocr_files: list[Path]
|
||||
|
||||
|
||||
def _read_json(path: str | Path, default: Any) -> Any:
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def _tail(path: str | Path, limit: int = 220) -> list[str]:
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
||||
lines = f.readlines()[-limit:]
|
||||
return [line.rstrip("\n") for line in lines if line.strip()]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def _list_images(path: str | Path, limit: int = 40) -> list[Path]:
|
||||
root = Path(path)
|
||||
if not root.exists():
|
||||
return []
|
||||
items = [
|
||||
p for p in root.iterdir()
|
||||
if p.is_file() and p.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"}
|
||||
]
|
||||
items.sort(key=lambda p: p.stat().st_mtime if p.exists() else 0, reverse=True)
|
||||
return items[:limit]
|
||||
|
||||
|
||||
def _normalize_rows(raw: Any, keys: tuple[str, ...]) -> list[dict[str, Any]]:
|
||||
if isinstance(raw, dict):
|
||||
for key in keys:
|
||||
value = raw.get(key)
|
||||
if isinstance(value, list):
|
||||
return [x for x in value if isinstance(x, dict)]
|
||||
return [raw] if raw else []
|
||||
if isinstance(raw, list):
|
||||
return [x for x in raw if isinstance(x, dict)]
|
||||
return []
|
||||
|
||||
|
||||
def _mapping_rows() -> list[dict[str, Any]]:
|
||||
raw = _read_json(Path(path_config.get_project_root()) / "douyin" / "core" / "state" / "room_pos_map.json", {})
|
||||
rows: list[dict[str, Any]] = []
|
||||
if isinstance(raw, dict):
|
||||
source = raw.get("items") if isinstance(raw.get("items"), list) else raw
|
||||
if isinstance(source, dict):
|
||||
iterable = source.items()
|
||||
else:
|
||||
iterable = enumerate(source if isinstance(source, list) else [])
|
||||
for key, value in iterable:
|
||||
if str(key).startswith("_"):
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
rows.append({
|
||||
"pos": value.get("pos") or value.get("room_pos") or key,
|
||||
"title": value.get("title") or value.get("room_title") or value.get("raw_title") or "-",
|
||||
"status": value.get("status") or value.get("state") or "已记录",
|
||||
"updated": value.get("updated_at") or value.get("ts") or value.get("time") or "-",
|
||||
})
|
||||
else:
|
||||
rows.append({"pos": key, "title": str(value), "status": "已记录", "updated": "-"})
|
||||
return rows[:80]
|
||||
|
||||
|
||||
def load_dashboard_data() -> DashboardData:
|
||||
cfg_path = path_config.get_config_path()
|
||||
cfg = _read_json(cfg_path, {})
|
||||
reservations_raw = _read_json(path_config.get_reservations_path(), {})
|
||||
high_raw = _read_json(path_config.get_high_value_rooms_path(), {})
|
||||
pic_dir = Path(path_config.get_pic_dir())
|
||||
screenshot = Path(path_config.get_screenshot_path())
|
||||
return DashboardData(
|
||||
cfg=cfg if isinstance(cfg, dict) else {},
|
||||
run_log=_tail(path_config.get_log_file_path(), 240) or _tail(path_config.get_simple_log_path(), 240),
|
||||
action_log=_tail(path_config.get_actions_log_path(), 240),
|
||||
reservations=_normalize_rows(reservations_raw, ("reservations", "items", "queue")),
|
||||
high_value_rooms=_normalize_rows(high_raw, ("rooms", "items", "records")),
|
||||
mapping_rows=_mapping_rows(),
|
||||
win_images=_list_images(pic_dir / "lottery_prize_captures", 60),
|
||||
screenshot_path=screenshot if screenshot.exists() else None,
|
||||
ocr_files=sorted((pic_dir / "ocr").glob("*"), key=lambda p: p.stat().st_mtime if p.exists() else 0, reverse=True)[:20]
|
||||
if (pic_dir / "ocr").exists() else [],
|
||||
)
|
||||
|
||||
|
||||
def cfg_get(cfg: dict[str, Any], *keys: str, default: Any = "-") -> Any:
|
||||
cur: Any = cfg
|
||||
for key in keys:
|
||||
if not isinstance(cur, dict) or key not in cur:
|
||||
return default
|
||||
cur = cur[key]
|
||||
return cur
|
||||
|
||||
|
||||
def fmt_ts(value: Any) -> str:
|
||||
try:
|
||||
ts = float(value)
|
||||
if ts <= 0:
|
||||
return "-"
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
|
||||
except Exception:
|
||||
return str(value or "-")
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from pathlib import Path
|
||||
from tkinter import ttk
|
||||
|
||||
from . import theme
|
||||
from .data import DashboardData, cfg_get, fmt_ts
|
||||
from .widgets import card, field, flow_grid, metric, preview_panel, section, switch_row, table_panel, text_panel
|
||||
|
||||
|
||||
def _pack_fields(parent, items: list[tuple[str, object]], columns: int = 2) -> None:
|
||||
grid = tk.Frame(parent, bg=theme.SURFACE)
|
||||
grid.pack(fill="x", padx=14, pady=(4, 14))
|
||||
for col in range(columns):
|
||||
grid.grid_columnconfigure(col, weight=1, uniform="field")
|
||||
for idx, (label, value) in enumerate(items):
|
||||
cell = field(grid, label, value)
|
||||
cell.grid(row=idx // columns, column=idx % columns, sticky="ew", padx=8, pady=5)
|
||||
|
||||
|
||||
def _sample_reservation_rows(data: DashboardData) -> list[dict]:
|
||||
rows = []
|
||||
for idx, item in enumerate(data.reservations[:18], 1):
|
||||
rows.append({
|
||||
"idx": idx,
|
||||
"title": item.get("room_title") or item.get("title") or item.get("live_title") or "-",
|
||||
"content": item.get("content") or item.get("prize_content") or item.get("gift") or "-",
|
||||
"value": item.get("prize_value_yuan") or item.get("value") or "-",
|
||||
"status": item.get("status") or item.get("state") or "等待中",
|
||||
"time": fmt_ts(item.get("target_ts") or item.get("created_ts") or item.get("updated_ts")),
|
||||
})
|
||||
return rows
|
||||
|
||||
|
||||
def build_home(parent, data: DashboardData) -> None:
|
||||
section(parent, "数据看板", "现有统计 / 实时状态 / 队列 / 截图集中视图")
|
||||
metrics = flow_grid(parent, 6)
|
||||
values = [
|
||||
("运行日志", len(data.run_log), "最近记录", theme.TEAL),
|
||||
("行为日志", len(data.action_log), "最近行为", theme.BLUE),
|
||||
("预约队列", len(data.reservations), "等待处理", theme.AMBER),
|
||||
("高价值房间", len(data.high_value_rooms), "本地记录", theme.GREEN),
|
||||
("中奖截图", len(data.win_images), "pic/lottery", theme.RED),
|
||||
("映射条目", len(data.mapping_rows), "room_pos", theme.TEAL_DARK),
|
||||
]
|
||||
for idx, item in enumerate(values):
|
||||
metric(metrics, *item).grid(row=0, column=idx, sticky="ew", padx=5)
|
||||
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
body.pack(fill="both", expand=True)
|
||||
body.grid_columnconfigure(0, weight=7)
|
||||
body.grid_columnconfigure(1, weight=4)
|
||||
body.grid_rowconfigure(0, weight=1)
|
||||
left = tk.Frame(body, bg=theme.BG)
|
||||
right = tk.Frame(body, bg=theme.BG)
|
||||
left.grid(row=0, column=0, sticky="nsew", padx=(0, 8))
|
||||
right.grid(row=0, column=1, sticky="nsew", padx=(8, 0))
|
||||
table_panel(left, "预约队列", (
|
||||
("idx", "#", 40), ("title", "直播间", 180), ("content", "内容", 220),
|
||||
("value", "价值", 80), ("status", "状态", 90), ("time", "时间", 150),
|
||||
), _sample_reservation_rows(data), height=8).pack(fill="both", expand=True, pady=(0, 12))
|
||||
text_panel(left, "运行日志", data.run_log[-80:], height=11).pack(fill="both", expand=True)
|
||||
preview_panel(right, data.screenshot_path).pack(fill="both", expand=True, pady=(0, 12))
|
||||
text_panel(right, "实时动作", data.action_log[-80:], height=9).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_run_settings(parent, data: DashboardData) -> None:
|
||||
section(parent, "运行设置", "运行时长、切换、滑动回退与直播间进入策略")
|
||||
box = card(parent, "核心运行参数")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("允许切换直播间", cfg_get(data.cfg, "needswitch")),
|
||||
("无限循环模式", cfg_get(data.cfg, "infinite_loop_enabled")),
|
||||
("运行时长(分钟)", cfg_get(data.cfg, "wait_minutes")),
|
||||
("倒计时大于不参与", cfg_get(data.cfg, "skip_if_countdown_gt_seconds")),
|
||||
("倒计时小于不参与", cfg_get(data.cfg, "skip_if_countdown_lt_seconds")),
|
||||
("滑动次数限制", cfg_get(data.cfg, "reset_after_swipes_enabled")),
|
||||
("次数", cfg_get(data.cfg, "reset_after_swipes")),
|
||||
("回退方式", cfg_get(data.cfg, "reset_after_swipes_action")),
|
||||
("进入坐标模式", cfg_get(data.cfg, "reenter_live_entry_mode")),
|
||||
("连续无福袋退出阈值", cfg_get(data.cfg, "fudai_exit_after_misses")),
|
||||
])
|
||||
|
||||
|
||||
def build_filter_settings(parent, data: DashboardData) -> None:
|
||||
section(parent, "筛选设置", "价值、人数、倒计时与粉丝团策略")
|
||||
box = card(parent, "筛选规则")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("最低价值(元)", cfg_get(data.cfg, "min_prize_value_yuan")),
|
||||
("参与人数最小", cfg_get(data.cfg, "min_participants")),
|
||||
("参与人数最大", cfg_get(data.cfg, "max_participants")),
|
||||
("倒计时小于不参与", cfg_get(data.cfg, "skip_if_countdown_lt_seconds")),
|
||||
("粉丝团失败策略", cfg_get(data.cfg, "fansclub_fail_action")),
|
||||
("粉丝团点击延迟(s)", cfg_get(data.cfg, "fansclub_click_delay")),
|
||||
("自动加入等待(s)", cfg_get(data.cfg, "fansclub_auto_join_wait_seconds")),
|
||||
("手动加入等待(s)", cfg_get(data.cfg, "fansclub_manual_wait_seconds")),
|
||||
])
|
||||
|
||||
|
||||
def build_reservation_settings(parent, data: DashboardData) -> None:
|
||||
section(parent, "高价值预约", "高价值记录、回访与回退校验")
|
||||
box = card(parent, "预约策略")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("启用高价值预约", cfg_get(data.cfg, "high_value_fudai_enabled")),
|
||||
("价值阈值(元)", cfg_get(data.cfg, "high_value_fudai_threshold_yuan")),
|
||||
("提前参与(秒)", cfg_get(data.cfg, "high_value_fudai_join_ahead_seconds")),
|
||||
("最多回退次数", cfg_get(data.cfg, "high_value_fudai_max_swipe_back")),
|
||||
("最多记录数量", cfg_get(data.cfg, "high_value_fudai_max_reservations")),
|
||||
("完成后策略", cfg_get(data.cfg, "high_value_fudai_after_action")),
|
||||
("启用高价值房间回访", cfg_get(data.cfg, "high_value_room_revisit_enabled")),
|
||||
("重访最小间隔(秒)", cfg_get(data.cfg, "high_value_room_revisit_min_interval_seconds")),
|
||||
("每次运行最大次数", cfg_get(data.cfg, "high_value_room_revisit_max_per_run")),
|
||||
("最低奖品价值(元)", cfg_get(data.cfg, "high_value_room_revisit_min_prize_value")),
|
||||
("最大年龄(天)", cfg_get(data.cfg, "high_value_room_revisit_max_age_days")),
|
||||
("开奖前轮询(秒)", cfg_get(data.cfg, "high_value_fudai_poll_before_seconds")),
|
||||
("回退滑延迟(秒)", cfg_get(data.cfg, "reservation_back_swipe_delay")),
|
||||
("校验等待时间(秒)", cfg_get(data.cfg, "reservation_back_verify_wait_seconds")),
|
||||
])
|
||||
|
||||
|
||||
def build_yanghao_settings(parent, data: DashboardData) -> None:
|
||||
section(parent, "养号设置", "推荐流停留、互动概率与关键词")
|
||||
metrics = flow_grid(parent, 4)
|
||||
for idx, item in enumerate([
|
||||
("养号启用", cfg_get(data.cfg, "yanghao_enabled"), "开关", theme.TEAL),
|
||||
("推荐停留", cfg_get(data.cfg, "yanghao_recommend_duration_seconds"), "秒", theme.BLUE),
|
||||
("点赞概率", cfg_get(data.cfg, "yanghao_like_prob"), "0-1", theme.AMBER),
|
||||
("收藏概率", cfg_get(data.cfg, "yanghao_fav_prob"), "0-1", theme.GREEN),
|
||||
]):
|
||||
metric(metrics, *item).grid(row=0, column=idx, sticky="ew", padx=5)
|
||||
box = card(parent, "互动参数")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("启用互动动作", cfg_get(data.cfg, "yanghao_enable_actions")),
|
||||
("只养号模式", cfg_get(data.cfg, "yanghao_only")),
|
||||
("评论概率", cfg_get(data.cfg, "yanghao_comment_prob")),
|
||||
("动作停留最小(s)", cfg_get(data.cfg, "yanghao_dwell_on_action_min_seconds")),
|
||||
("动作停留最大(s)", cfg_get(data.cfg, "yanghao_dwell_on_action_max_seconds")),
|
||||
("图标匹配阈值", cfg_get(data.cfg, "yanghao_icon_match_threshold")),
|
||||
])
|
||||
|
||||
|
||||
def build_debug_settings(parent, data: DashboardData) -> None:
|
||||
section(parent, "调试参数", "识别阈值、模板匹配、像素检测与截图调试")
|
||||
metrics = flow_grid(parent, 4)
|
||||
for idx, item in enumerate([
|
||||
("调试截图", cfg_get(data.cfg, "debug_captures", "enabled"), "enabled", theme.TEAL),
|
||||
("保留天数", cfg_get(data.cfg, "debug_captures", "keep_days"), "debug", theme.BLUE),
|
||||
("最大文件", cfg_get(data.cfg, "debug_captures", "max_files"), "cleanup", theme.AMBER),
|
||||
("OCR模式", cfg_get(data.cfg, "fudai_detail_ui_mode"), "detail", theme.GREEN),
|
||||
]):
|
||||
metric(metrics, *item).grid(row=0, column=idx, sticky="ew", padx=5)
|
||||
box = card(parent, "识别与点击参数")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("找福袋最大尝试", cfg_get(data.cfg, "fudai_find_max_attempts")),
|
||||
("找福袋重试间隔", cfg_get(data.cfg, "fudai_icon_retry_delay_seconds")),
|
||||
("最大等待时间", cfg_get(data.cfg, "fudai_icon_max_wait_seconds")),
|
||||
("点击后等待", cfg_get(data.cfg, "fudai_click_wait_seconds")),
|
||||
("模板匹配阈值", cfg_get(data.cfg, "fudai_template_match_threshold")),
|
||||
("详情模板阈值", cfg_get(data.cfg, "fudai_detail_template_threshold")),
|
||||
("开奖页红色阈值", cfg_get(data.cfg, "lucky_draw_red_ratio_threshold")),
|
||||
("滑动速度(ms)", cfg_get(data.cfg, "swipe_duration_ms")),
|
||||
])
|
||||
|
||||
|
||||
def build_license(parent, data: DashboardData) -> None:
|
||||
section(parent, "授权", "卡密授权、本机机器码与授权文件")
|
||||
box = card(parent, "卡密授权")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("授权状态", "本地检测"),
|
||||
("本机机器码", ""),
|
||||
("授权文件", "license.dat"),
|
||||
("输入卡密", ""),
|
||||
], columns=1)
|
||||
ttk.Button(box, text="安装卡密", style="Primary.TButton").pack(side="left", padx=22, pady=(0, 18))
|
||||
ttk.Button(box, text="刷新状态", style="Soft.TButton").pack(side="left", padx=6, pady=(0, 18))
|
||||
|
||||
|
||||
def build_logging(parent, data: DashboardData) -> None:
|
||||
section(parent, "日志配置", "日志格式、保留策略、实时状态刷新")
|
||||
box = card(parent, "日志与界面")
|
||||
box.pack(fill="x")
|
||||
_pack_fields(box, [
|
||||
("日志格式模式", cfg_get(data.cfg, "logging", "log_format_mode")),
|
||||
("统一日志路径", cfg_get(data.cfg, "log_unified_path")),
|
||||
("保留天数", cfg_get(data.cfg, "logging", "keep_days")),
|
||||
("总量上限(GB)", cfg_get(data.cfg, "logging", "max_total_size_gb")),
|
||||
("压缩阈值(天)", cfg_get(data.cfg, "logging", "compress_after_days")),
|
||||
("警告阈值(MB)", cfg_get(data.cfg, "logging", "monitor_warning_mb")),
|
||||
("严重阈值(MB)", cfg_get(data.cfg, "logging", "monitor_critical_mb")),
|
||||
("界面主题", cfg_get(data.cfg, "gui", "theme")),
|
||||
("实时刷新(ms)", cfg_get(data.cfg, "gui", "realtime_status", "refresh_interval_ms")),
|
||||
("实时状态条数", cfg_get(data.cfg, "gui", "realtime_status", "tail_items")),
|
||||
])
|
||||
|
||||
|
||||
def build_keywords(parent, data: DashboardData) -> None:
|
||||
section(parent, "关键词", "白名单与黑名单")
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
body.pack(fill="both", expand=True)
|
||||
for idx, title in enumerate(("想要 contains_want(白名单,空=不限制)", "不想要 contains_not_want(黑名单)")):
|
||||
box = card(body, title)
|
||||
box.grid(row=0, column=idx, sticky="nsew", padx=(0, 8) if idx == 0 else (8, 0))
|
||||
text = tk.Text(box, height=18, bd=0, bg="#fbfcfa", font=theme.FONT_UI)
|
||||
text.pack(fill="both", expand=True, padx=12, pady=(4, 12))
|
||||
body.grid_columnconfigure(0, weight=1)
|
||||
body.grid_columnconfigure(1, weight=1)
|
||||
body.grid_rowconfigure(0, weight=1)
|
||||
|
||||
|
||||
def build_run_log(parent, data: DashboardData) -> None:
|
||||
section(parent, "运行日志", "筛选 / 搜索 / 刷新")
|
||||
text_panel(parent, "最近运行日志", data.run_log, height=24).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_preview(parent, data: DashboardData) -> None:
|
||||
section(parent, "截图预览", "选择图片 / 打开pic目录 / 刷新预览")
|
||||
preview_panel(parent, data.screenshot_path, "当前截图").pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_statistics(parent, data: DashboardData) -> None:
|
||||
section(parent, "统计信息", "本地运行统计看板")
|
||||
build_home(parent, data)
|
||||
|
||||
|
||||
def build_reservation_queue(parent, data: DashboardData) -> None:
|
||||
section(parent, "预约队列", "预约队列总览与等待状态")
|
||||
table_panel(parent, "预约队列", (
|
||||
("idx", "#", 40), ("title", "直播间", 190), ("content", "内容", 250),
|
||||
("value", "价值", 80), ("status", "状态", 90), ("time", "时间", 170),
|
||||
), _sample_reservation_rows(data), height=18).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_high_value(parent, data: DashboardData) -> None:
|
||||
section(parent, "高价值房间", "持久化高价值记录")
|
||||
rows = []
|
||||
for idx, item in enumerate(data.high_value_rooms[:50], 1):
|
||||
rows.append({
|
||||
"idx": idx,
|
||||
"title": item.get("room_title") or item.get("title") or "-",
|
||||
"content": item.get("content") or item.get("prize_content") or "-",
|
||||
"value": item.get("prize_value_yuan") or item.get("value") or "-",
|
||||
"status": item.get("status") or "已记录",
|
||||
})
|
||||
table_panel(parent, "高价值房间", (
|
||||
("idx", "#", 40), ("title", "直播间", 220), ("content", "内容", 280),
|
||||
("value", "价值", 90), ("status", "状态", 100),
|
||||
), rows, height=20).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_actions_log(parent, data: DashboardData) -> None:
|
||||
section(parent, "行为日志", "关键字筛选 / 搜索 / 刷新")
|
||||
text_panel(parent, "最近行为日志", data.action_log, height=24).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_realtime(parent, data: DashboardData) -> None:
|
||||
section(parent, "实时状态", "显示动作流 / 显示截图 / 自动滚动 / 查看大图")
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
body.pack(fill="both", expand=True)
|
||||
body.grid_columnconfigure(0, weight=5)
|
||||
body.grid_columnconfigure(1, weight=3)
|
||||
text_panel(body, "动作流", data.action_log[-120:], height=24).grid(row=0, column=0, sticky="nsew", padx=(0, 8))
|
||||
preview_panel(body, data.screenshot_path, "实时截图").grid(row=0, column=1, sticky="nsew", padx=(8, 0))
|
||||
|
||||
|
||||
def build_ocr(parent, data: DashboardData) -> None:
|
||||
section(parent, "OCR结果", "点击 截图+OCR 后更新")
|
||||
lines = []
|
||||
for p in data.ocr_files[:8]:
|
||||
lines.append(f"{p.name} {fmt_ts(p.stat().st_mtime)}")
|
||||
text_panel(parent, "OCR结果", lines or ['暂无OCR结果,请先点击"截图+OCR"按钮'], height=24).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_wins(parent, data: DashboardData) -> None:
|
||||
section(parent, "中奖记录", "中奖截图列表与预览")
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
body.pack(fill="both", expand=True)
|
||||
body.grid_columnconfigure(0, weight=4)
|
||||
body.grid_columnconfigure(1, weight=5)
|
||||
rows = [
|
||||
{"idx": i + 1, "file": p.name, "time": fmt_ts(p.stat().st_mtime)}
|
||||
for i, p in enumerate(data.win_images[:40])
|
||||
]
|
||||
table_panel(body, "中奖截图", (("idx", "#", 40), ("file", "文件", 260), ("time", "时间", 160)), rows, height=18).grid(row=0, column=0, sticky="nsew", padx=(0, 8))
|
||||
preview_panel(body, data.win_images[0] if data.win_images else None, "中奖预览").grid(row=0, column=1, sticky="nsew", padx=(8, 0))
|
||||
|
||||
|
||||
def build_mapping(parent, data: DashboardData) -> None:
|
||||
section(parent, "映射表", "显示原始标题 / 刷新映射表 / 搜索 / 复制条目")
|
||||
table_panel(parent, "运行时映射表", (
|
||||
("pos", "位置", 80), ("title", "标题", 360), ("status", "状态", 100), ("updated", "更新时间", 180),
|
||||
), data.mapping_rows, height=22).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def build_wifi_adb(parent, data: DashboardData) -> None:
|
||||
section(parent, "WiFi ADB", "扫描 WiFi / USB 授权提示 / 连接状态")
|
||||
metrics = flow_grid(parent, 4)
|
||||
for idx, item in enumerate([
|
||||
("USB设备", "待检测", "首次启用", theme.TEAL),
|
||||
("扫描状态", "未扫描", "局域网", theme.BLUE),
|
||||
("默认端口", "5555", "ADB TCP", theme.AMBER),
|
||||
("当前设备", "自动选择", "设备选择器", theme.GREEN),
|
||||
]):
|
||||
metric(metrics, *item).grid(row=0, column=idx, sticky="ew", padx=5)
|
||||
|
||||
rows = [
|
||||
{"device": "待扫描设备", "ip": "192.168.1.x", "port": "5555", "state": "未连接"},
|
||||
]
|
||||
table_panel(parent, "WiFi 设备列表", (
|
||||
("device", "设备ID", 220), ("ip", "IP地址", 180), ("port", "端口", 90), ("state", "状态", 120),
|
||||
), rows, height=8).pack(fill="x", pady=(0, 12))
|
||||
|
||||
box = card(parent, "连接操作")
|
||||
box.pack(fill="x")
|
||||
row = tk.Frame(box, bg=theme.SURFACE)
|
||||
row.pack(fill="x", padx=14, pady=14)
|
||||
ttk.Button(row, text="扫描WiFi", style="Primary.TButton").pack(side="left", padx=(0, 8))
|
||||
ttk.Button(row, text="刷新", style="Soft.TButton").pack(side="left", padx=4)
|
||||
ttk.Button(row, text="连接", style="Soft.TButton").pack(side="left", padx=4)
|
||||
ttk.Button(row, text="取消", style="Soft.TButton").pack(side="left", padx=4)
|
||||
ttk.Label(row, text="请确保设备已通过 USB 授权,并已开启无线调试/ADB TCP。", style="Small.TLabel").pack(side="left", padx=14)
|
||||
|
||||
|
||||
PAGES = {
|
||||
"数据看板": build_home,
|
||||
"运行设置": build_run_settings,
|
||||
"筛选设置": build_filter_settings,
|
||||
"高价值预约": build_reservation_settings,
|
||||
"养号设置": build_yanghao_settings,
|
||||
"调试参数": build_debug_settings,
|
||||
"授权": build_license,
|
||||
"日志配置": build_logging,
|
||||
"关键词": build_keywords,
|
||||
"运行日志": build_run_log,
|
||||
"截图预览": build_preview,
|
||||
"统计信息": build_statistics,
|
||||
"预约队列": build_reservation_queue,
|
||||
"高价值房间": build_high_value,
|
||||
"行为日志": build_actions_log,
|
||||
"实时状态": build_realtime,
|
||||
"OCR结果": build_ocr,
|
||||
"中奖记录": build_wins,
|
||||
"映射表": build_mapping,
|
||||
"WiFi ADB": build_wifi_adb,
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from tkinter import ttk
|
||||
|
||||
|
||||
BG = "#f6f7f4"
|
||||
SURFACE = "#ffffff"
|
||||
SURFACE_ALT = "#f1f5f2"
|
||||
BORDER = "#dfe7e2"
|
||||
TEXT = "#1f2a2a"
|
||||
MUTED = "#6d7a7a"
|
||||
TEAL = "#009688"
|
||||
TEAL_DARK = "#00796b"
|
||||
AMBER = "#f59e0b"
|
||||
RED = "#ef4444"
|
||||
GREEN = "#16a34a"
|
||||
BLUE = "#3b82f6"
|
||||
|
||||
FONT_UI = ("Microsoft YaHei UI", 10)
|
||||
FONT_SMALL = ("Microsoft YaHei UI", 9)
|
||||
FONT_TITLE = ("Microsoft YaHei UI", 15, "bold")
|
||||
FONT_H2 = ("Microsoft YaHei UI", 12, "bold")
|
||||
FONT_MONO = ("Consolas", 10)
|
||||
|
||||
|
||||
def setup_styles(root) -> None:
|
||||
root.configure(bg=BG)
|
||||
style = ttk.Style(root)
|
||||
try:
|
||||
style.theme_use("clam")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
style.configure(".", font=FONT_UI)
|
||||
style.configure("Dashboard.TFrame", background=BG)
|
||||
style.configure("Surface.TFrame", background=SURFACE)
|
||||
style.configure("Alt.TFrame", background=SURFACE_ALT)
|
||||
style.configure("Card.TFrame", background=SURFACE, borderwidth=1, relief="solid")
|
||||
style.configure("Muted.TLabel", background=SURFACE, foreground=MUTED, font=FONT_SMALL)
|
||||
style.configure("Title.TLabel", background=BG, foreground=TEXT, font=FONT_TITLE)
|
||||
style.configure("H2.TLabel", background=SURFACE, foreground=TEXT, font=FONT_H2)
|
||||
style.configure("Value.TLabel", background=SURFACE, foreground=TEXT, font=("Microsoft YaHei UI", 18, "bold"))
|
||||
style.configure("Small.TLabel", background=SURFACE, foreground=MUTED, font=FONT_SMALL)
|
||||
style.configure("Sidebar.TButton", padding=(12, 8), anchor="w")
|
||||
style.configure("Primary.TButton", padding=(14, 8), foreground="#ffffff", background=TEAL)
|
||||
style.map("Primary.TButton", background=[("active", TEAL_DARK)])
|
||||
style.configure("Danger.TButton", padding=(14, 8), foreground=RED)
|
||||
style.configure("Soft.TButton", padding=(12, 7))
|
||||
style.configure("Dashboard.TNotebook", background=BG, borderwidth=0)
|
||||
style.configure("Dashboard.TNotebook.Tab", padding=(14, 8), font=FONT_SMALL)
|
||||
style.configure("Treeview", font=FONT_SMALL, rowheight=28, background=SURFACE, fieldbackground=SURFACE)
|
||||
style.configure("Treeview.Heading", font=("Microsoft YaHei UI", 9, "bold"))
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import tkinter as tk
|
||||
from pathlib import Path
|
||||
from tkinter import ttk
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
from . import theme
|
||||
|
||||
|
||||
def clear(frame: tk.Misc) -> None:
|
||||
for child in frame.winfo_children():
|
||||
child.destroy()
|
||||
|
||||
|
||||
def card(parent, title: str | None = None, *, padding: int = 14) -> tk.Frame:
|
||||
frame = tk.Frame(parent, bg=theme.SURFACE, highlightbackground=theme.BORDER, highlightthickness=1)
|
||||
if title:
|
||||
ttk.Label(frame, text=title, style="H2.TLabel").pack(anchor="w", padx=padding, pady=(padding, 6))
|
||||
return frame
|
||||
|
||||
|
||||
def metric(parent, title: str, value: object, hint: str = "", color: str = theme.TEAL) -> tk.Frame:
|
||||
box = card(parent)
|
||||
top = tk.Frame(box, bg=theme.SURFACE)
|
||||
top.pack(fill="x", padx=14, pady=(12, 4))
|
||||
tk.Label(top, text="●", fg=color, bg=theme.SURFACE, font=("Segoe UI", 11, "bold")).pack(side="left")
|
||||
ttk.Label(top, text=title, style="Small.TLabel").pack(side="left", padx=(6, 0))
|
||||
ttk.Label(box, text=str(value), style="Value.TLabel").pack(anchor="w", padx=14)
|
||||
ttk.Label(box, text=hint, style="Small.TLabel").pack(anchor="w", padx=14, pady=(0, 12))
|
||||
return box
|
||||
|
||||
|
||||
def section(parent, title: str, subtitle: str = "") -> tk.Frame:
|
||||
row = tk.Frame(parent, bg=theme.BG)
|
||||
row.pack(fill="x", pady=(0, 10))
|
||||
ttk.Label(row, text=title, style="Title.TLabel").pack(side="left")
|
||||
if subtitle:
|
||||
ttk.Label(row, text=subtitle, background=theme.BG, foreground=theme.MUTED, font=theme.FONT_SMALL).pack(side="left", padx=(10, 0))
|
||||
return row
|
||||
|
||||
|
||||
def flow_grid(parent, columns: int = 4) -> tk.Frame:
|
||||
grid = tk.Frame(parent, bg=theme.BG)
|
||||
grid.pack(fill="x", pady=(0, 14))
|
||||
for idx in range(columns):
|
||||
grid.grid_columnconfigure(idx, weight=1, uniform="metric")
|
||||
return grid
|
||||
|
||||
|
||||
def text_panel(parent, title: str, lines: Iterable[str], height: int = 10) -> tk.Frame:
|
||||
box = card(parent, title)
|
||||
text = tk.Text(box, height=height, wrap="none", bd=0, bg="#fbfcfa", fg=theme.TEXT, insertbackground=theme.TEAL, font=theme.FONT_MONO)
|
||||
text.pack(fill="both", expand=True, padx=12, pady=(4, 12))
|
||||
content = "\n".join(list(lines)[:260]) or "暂无数据"
|
||||
text.insert("1.0", content)
|
||||
text.configure(state="disabled")
|
||||
return box
|
||||
|
||||
|
||||
def table_panel(parent, title: str, columns: Sequence[tuple[str, str, int]], rows: Sequence[dict], height: int = 8) -> tk.Frame:
|
||||
box = card(parent, title)
|
||||
tree = ttk.Treeview(box, columns=[c[0] for c in columns], show="headings", height=height)
|
||||
for key, label, width in columns:
|
||||
tree.heading(key, text=label)
|
||||
tree.column(key, width=width, anchor="w")
|
||||
for row in rows:
|
||||
tree.insert("", "end", values=[str(row.get(key, "-")) for key, _, _ in columns])
|
||||
tree.pack(fill="both", expand=True, padx=12, pady=(4, 12))
|
||||
return box
|
||||
|
||||
|
||||
def field(parent, label: str, value: object, *, wide: bool = False) -> tk.Frame:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
ttk.Label(row, text=label, style="Small.TLabel", width=18).pack(side="left")
|
||||
ent = ttk.Entry(row)
|
||||
ent.insert(0, str(value))
|
||||
ent.pack(side="left", fill="x", expand=True)
|
||||
if not wide:
|
||||
ent.configure(width=18)
|
||||
return row
|
||||
|
||||
|
||||
def switch_row(parent, label: str, value: bool) -> tk.Frame:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
var = tk.BooleanVar(value=bool(value))
|
||||
ttk.Checkbutton(row, text=label, variable=var).pack(side="left")
|
||||
return row
|
||||
|
||||
|
||||
def preview_panel(parent, image_path: Path | None, title: str = "截图预览") -> tk.Frame:
|
||||
box = card(parent, title)
|
||||
body = tk.Frame(box, bg="#fbfcfa", highlightbackground=theme.BORDER, highlightthickness=1)
|
||||
body.pack(fill="both", expand=True, padx=12, pady=(4, 12))
|
||||
if image_path and image_path.exists():
|
||||
try:
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
img = Image.open(image_path).convert("RGB")
|
||||
img.thumbnail((320, 520))
|
||||
photo = ImageTk.PhotoImage(img)
|
||||
label = tk.Label(body, image=photo, bg="#fbfcfa")
|
||||
label.image = photo
|
||||
label.pack(expand=True, pady=10)
|
||||
ttk.Label(body, text=os.path.basename(str(image_path)), background="#fbfcfa", foreground=theme.MUTED).pack(pady=(0, 8))
|
||||
return box
|
||||
except Exception:
|
||||
pass
|
||||
tk.Label(body, text="暂无截图\n点击“截图+OCR”后刷新", bg="#fbfcfa", fg=theme.MUTED, font=("Microsoft YaHei UI", 14)).pack(expand=True)
|
||||
return box
|
||||
|
||||
|
||||
class ScrollFrame(ttk.Frame):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent, style="Dashboard.TFrame")
|
||||
self.canvas = tk.Canvas(self, bg=theme.BG, highlightthickness=0, bd=0)
|
||||
self.scroll = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
|
||||
self.inner = tk.Frame(self.canvas, bg=theme.BG)
|
||||
self.window_id = self.canvas.create_window((0, 0), window=self.inner, anchor="nw")
|
||||
self.canvas.configure(yscrollcommand=self.scroll.set)
|
||||
self.canvas.pack(side="left", fill="both", expand=True)
|
||||
self.scroll.pack(side="right", fill="y")
|
||||
self.inner.bind("<Configure>", lambda _e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))
|
||||
self.canvas.bind("<Configure>", lambda e: self.canvas.itemconfigure(self.window_id, width=e.width))
|
||||
self.canvas.bind_all("<MouseWheel>", self._wheel)
|
||||
|
||||
def _wheel(self, event) -> None:
|
||||
try:
|
||||
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from douyin.updater.bootstrap import run_startup_update_check_early
|
||||
|
||||
|
||||
run_startup_update_check_early(app_name="gui_dashboard_app")
|
||||
|
||||
from gui.dashboard_app.app import main # noqa: E402
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in new issue
Block a user