158 lines
6.7 KiB
Python
158 lines
6.7 KiB
Python
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()
|