109 lines
6.2 KiB
Python
109 lines
6.2 KiB
Python
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
|
|
from . import theme
|
|
from .data import DashboardData, fmt_ts
|
|
from .page_context import PageContext
|
|
from .page_helpers import reservation_rows
|
|
from .widgets import flow_grid, preview_panel, section, stat_tile, table_panel, text_panel, toolbar
|
|
|
|
|
|
def build_run_log(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "运行日志", "筛选 / 搜索 / 刷新")
|
|
toolbar(parent, [("刷新", ctx.action("refresh"), "soft"), "上一个", "下一个", "清除"])
|
|
text_panel(parent, "最近运行日志", data.run_log, height=24).pack(fill="both", expand=True)
|
|
|
|
|
|
def build_preview(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "截图预览", "选择图片 / 打开pic目录 / 刷新预览")
|
|
toolbar(parent, [("刷新预览", ctx.action("refresh"), "soft"), ("截图+OCR", ctx.action("screenshot_ocr"), "primary"), "打开pic目录"])
|
|
preview_panel(parent, data.screenshot_path, "当前截图").pack(fill="both", expand=True)
|
|
|
|
|
|
def build_reservation_queue(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "预约队列", "预约队列总览与等待状态")
|
|
toolbar(parent, [("刷新", ctx.action("refresh"), "soft")])
|
|
rows = reservation_rows(data)
|
|
for row in rows:
|
|
row["time"] = fmt_ts(row["time"])
|
|
table_panel(parent, "预约队列", (
|
|
("idx", "#", 40), ("title", "直播间", 190), ("content", "内容", 250),
|
|
("value", "价值", 80), ("status", "状态", 90), ("time", "时间", 170),
|
|
), rows, height=18).pack(fill="both", expand=True)
|
|
|
|
|
|
def build_high_value(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "高价值房间", "持久化高价值记录")
|
|
toolbar(parent, [("刷新", ctx.action("refresh"), "soft")])
|
|
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: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "行为日志", "关键字筛选 / 搜索 / 刷新")
|
|
toolbar(parent, [("刷新", ctx.action("refresh"), "soft"), "上一个", "下一个", "清除"])
|
|
text_panel(parent, "最近行为日志", data.action_log, height=24).pack(fill="both", expand=True)
|
|
|
|
|
|
def build_realtime(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "实时状态", "显示动作流 / 显示截图 / 自动滚动 / 查看大图")
|
|
toolbar(parent, ["显示动作流", "显示截图", "自动滚动", "查看大图"])
|
|
body = tk.Frame(parent, bg=theme.BG)
|
|
body.pack(fill="both", expand=True)
|
|
text_panel(body, "动作流", data.action_log[-120:], height=16).pack(fill="both", expand=True, pady=(0, 12))
|
|
preview_panel(body, data.screenshot_path, "实时截图").pack(fill="both", expand=True)
|
|
|
|
|
|
def build_ocr(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "OCR结果", "点击 截图+OCR 后更新")
|
|
toolbar(parent, [("截图+OCR", ctx.action("screenshot_ocr"), "primary"), ("刷新", ctx.action("refresh"), "soft")])
|
|
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: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "中奖记录", "中奖截图列表与预览")
|
|
toolbar(parent, [("刷新列表", ctx.action("refresh"), "soft"), "打开目录", "保存误识别", "加载误识别"])
|
|
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: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "映射表", "显示原始标题 / 刷新映射表 / 搜索 / 复制条目")
|
|
toolbar(parent, [("自动刷新(5s)", None, "soft"), ("刷新映射表", ctx.action("refresh"), "soft"), "显示原始标题", "清除", "复制条目"])
|
|
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: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "WiFi ADB", "扫描 WiFi / USB 授权提示 / 连接状态")
|
|
toolbar(parent, [("扫描WiFi", ctx.action("scan_wifi"), "primary"), ("WiFi ADB", ctx.action("wifi_adb"), "soft"), ("刷新设备", ctx.action("refresh_devices"), "soft")])
|
|
metrics = flow_grid(parent, 4)
|
|
for idx, item in enumerate([
|
|
("USB设备", "待检测", "首次启用", theme.TEAL, theme.TEAL_SOFT),
|
|
("扫描状态", "未扫描", "局域网", theme.BLUE, theme.BLUE_SOFT),
|
|
("默认端口", "5555", "ADB TCP", theme.AMBER, theme.AMBER_SOFT),
|
|
("当前设备", "设备选择器", "顶部下拉", theme.GREEN, theme.GREEN_SOFT),
|
|
]):
|
|
stat_tile(metrics, *item[:3], color=item[3], soft=item[4]).grid(row=0, column=idx, sticky="ew", padx=5)
|