From 00821d0926a5cfe0b151a1b7048232d4e7f735c2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 18 Jun 2026 17:12:47 +0800 Subject: [PATCH] Refine dashboard overview readability --- gui/dashboard_app/app.py | 28 ++++++++-------- gui/dashboard_app/page_context.py | 2 ++ gui/dashboard_app/page_home.py | 43 ++++++++----------------- gui/dashboard_app/theme.py | 21 ++++++------ gui/dashboard_app/widgets.py | 53 ++++++++++++++++++++----------- 5 files changed, 74 insertions(+), 73 deletions(-) diff --git a/gui/dashboard_app/app.py b/gui/dashboard_app/app.py index 633f0e1..6f298d7 100644 --- a/gui/dashboard_app/app.py +++ b/gui/dashboard_app/app.py @@ -25,7 +25,7 @@ class DashboardApp: def __init__(self) -> None: self.root = tk.Tk() try: - self.root.tk.call("tk", "scaling", 1.0) + self.root.tk.call("tk", "scaling", 1.12) except Exception: pass self.root.title("抖音自动化助手 - 数据看板") @@ -71,24 +71,24 @@ class DashboardApp: mark = tk.Frame(brand, bg=theme.TEAL, width=28, height=28) mark.pack(side="left", padx=(0, 9)) mark.pack_propagate(False) - tk.Label(mark, text="抖", bg=theme.TEAL, fg="#ffffff", font=("Microsoft YaHei UI", 11, "bold")).pack(expand=True) + tk.Label(mark, text="抖", bg=theme.TEAL, fg="#ffffff", font=("Microsoft YaHei UI", 13, "bold")).pack(expand=True) title_box = tk.Frame(brand, bg=theme.SURFACE) title_box.pack(side="left") - tk.Label(title_box, text="抖音自动化助手", bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 14, "bold")).pack(anchor="w") + tk.Label(title_box, text="抖音自动化助手", bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 16, "bold")).pack(anchor="w") tk.Label(title_box, text="轻量数据看板入口", bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_SMALL).pack(anchor="w") tool_row = tk.Frame(top, bg=theme.SURFACE) tool_row.pack(fill="x", padx=14, pady=(0, 8)) ttk.Label(tool_row, text="设备:", background=theme.SURFACE, foreground=theme.MUTED).pack(side="left") self.device_combo = ttk.Combobox(tool_row, textvariable=self.device_var, values=[], width=28) self.device_combo.pack(side="left", padx=(4, 8)) - button(tool_row, "刷新设备", self.refresh_devices, width=104).pack(side="left", padx=3) - self.scan_button = button(tool_row, "扫描 WiFi", self.scan_wifi, width=106) + button(tool_row, "刷新设备", self.refresh_devices, width=126).pack(side="left", padx=3) + self.scan_button = button(tool_row, "扫描 WiFi", self.scan_wifi, width=128) self.scan_button.pack(side="left", padx=4) - button(tool_row, "WiFi ADB", self.open_wifi_adb, width=98).pack(side="left", padx=3) + button(tool_row, "WiFi ADB", self.open_wifi_adb, width=118).pack(side="left", padx=3) ttk.Label(tool_row, text="Y偏移:", background=theme.SURFACE, foreground=theme.MUTED).pack(side="left", padx=(8, 3)) ttk.Spinbox(tool_row, from_=-200, to=200, textvariable=self.y_var, width=6).pack(side="left") - button(tool_row, "保存配置", self.save_config, width=104).pack(side="right", padx=3) - button(tool_row, "截图+OCR", self.screenshot_ocr, kind="primary", width=110).pack(side="right", padx=3) + button(tool_row, "保存配置", self.save_config, width=126).pack(side="right", padx=3) + button(tool_row, "截图+OCR", self.screenshot_ocr, kind="primary", width=132).pack(side="right", padx=3) main = ttk.Frame(shell, style="Dashboard.TFrame") main.pack(fill="both", expand=True, padx=16, pady=(4, 7)) @@ -119,11 +119,11 @@ class DashboardApp: bottom = tk.Frame(shell, bg=theme.SURFACE, highlightbackground=theme.BORDER, highlightthickness=1) bottom.pack(fill="x", padx=16, pady=(3, 12)) inner_bottom = tk.Frame(bottom, bg=theme.SURFACE) - inner_bottom.pack(fill="x", padx=10, pady=7) - button(inner_bottom, "开始运行", self.start_run, kind="primary", width=86).pack(side="left", padx=(0, 7)) - button(inner_bottom, "停止", self.stop_run, width=70).pack(side="left", padx=3) - button(inner_bottom, "强制停止", self.force_stop_run, kind="danger", width=86).pack(side="left", padx=3) - button(inner_bottom, "发送返回键", self.send_back_key, width=96).pack(side="left", padx=7) + inner_bottom.pack(fill="x", padx=12, pady=9) + button(inner_bottom, "开始运行", self.start_run, kind="primary", width=132).pack(side="left", padx=(0, 8)) + button(inner_bottom, "停止", self.stop_run, width=96).pack(side="left", padx=4) + button(inner_bottom, "强制停止", self.force_stop_run, kind="danger", width=132).pack(side="left", padx=4) + button(inner_bottom, "发送返回键", self.send_back_key, width=146).pack(side="left", padx=8) self.status_pill = status_pill(inner_bottom, "就绪") self.status_pill.pack(side="right") @@ -329,7 +329,7 @@ class DashboardApp: self._ensure_text_widgets() clear(self.content) builder = PAGES.get(name, PAGES["数据看板"]) - builder(self.content, self.data, PageContext(self.config_vars, self.text_widgets, self._actions())) + builder(self.content, self.data, PageContext(self.config_vars, self.text_widgets, self._actions(), self.status_var)) try: self.content_scroll.canvas.yview_moveto(0) except Exception: diff --git a/gui/dashboard_app/page_context.py b/gui/dashboard_app/page_context.py index 3dbd937..3d0a837 100644 --- a/gui/dashboard_app/page_context.py +++ b/gui/dashboard_app/page_context.py @@ -12,10 +12,12 @@ class PageContext: vars_: dict[str, tk.Variable], texts: dict[str, tk.Text], actions: dict[str, Action], + status_var: tk.StringVar | None = None, ) -> None: self.vars = vars_ self.texts = texts self.actions = actions + self.status_var = status_var def var(self, name: str) -> tk.Variable | None: return self.vars.get(name) diff --git a/gui/dashboard_app/page_home.py b/gui/dashboard_app/page_home.py index 1245750..abf64d3 100644 --- a/gui/dashboard_app/page_home.py +++ b/gui/dashboard_app/page_home.py @@ -6,27 +6,25 @@ from . import theme from .data import DashboardData, fmt_ts from .page_context import PageContext from .page_helpers import reservation_rows -from .widgets import card, flow_grid, mini_table, section, stat_tile, table_panel, text_panel +from .widgets import flow_grid, section, stat_tile, table_panel, text_panel def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: - section(parent, "数据看板", "运行状态 / 截图 / 队列 / 记录") - metrics = flow_grid(parent, 3) + section(parent, "数据看板", "运行状态 / 队列 / 动作") + metrics = flow_grid(parent, 2) + status_text = ctx.status_var.get() if ctx.status_var is not None else "就绪" values = [ - ("运行日志", len(data.run_log), "最近记录", theme.TEAL, theme.TEAL_SOFT), - ("行为日志", len(data.action_log), "动作流", theme.BLUE, theme.BLUE_SOFT), - ("预约队列", len(data.reservations), "等待处理", theme.AMBER, theme.AMBER_SOFT), - ("高价值房间", len(data.high_value_rooms), "本地记录", theme.GREEN, theme.GREEN_SOFT), ("中奖截图", len(data.win_images), "pic/lottery", theme.RED, theme.RED_SOFT), - ("映射条目", len(data.mapping_rows), "room_pos", theme.TEAL_DARK, theme.TEAL_SOFT), + ("当前状态", status_text or "就绪", "运行状态", theme.TEAL, theme.TEAL_SOFT), ] for idx, item in enumerate(values): - stat_tile(metrics, *item[:3], color=item[3], soft=item[4]).grid(row=idx // 3, column=idx % 3, sticky="ew", padx=5, pady=5) + tile = stat_tile(metrics, *item[:3], color=item[3], soft=item[4], compact=True) + tile.grid(row=idx // 2, column=idx % 2, sticky="ew", padx=4, pady=4) body = tk.Frame(parent, bg=theme.BG) body.pack(fill="both", expand=True) - body.grid_columnconfigure(0, weight=1, minsize=520) - body.grid_columnconfigure(1, weight=0, minsize=320) + body.grid_columnconfigure(0, weight=3, minsize=520) + body.grid_columnconfigure(1, weight=2, minsize=360) left = tk.Frame(body, bg=theme.BG) right = tk.Frame(body, bg=theme.BG) @@ -37,26 +35,11 @@ def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: for row in rows: row["time"] = fmt_ts(row["time"]) table_panel(left, "预约队列", ( - ("idx", "#", 28), ("title", "直播间", 110), ("content", "内容", 180), - ("value", "价值", 52), ("status", "状态", 58), ("time", "时间", 96), - ), rows, height=8).pack(fill="both", expand=True, pady=(0, 12)) + ("idx", "#", 32), ("title", "直播间", 108), ("content", "内容", 168), + ("value", "价值", 54), ("status", "状态", 58), ("time", "时间", 92), + ), rows, height=18).pack(fill="both", expand=True) - high_rows = [] - for item in data.high_value_rooms[:8]: - high_rows.append(( - str(item.get("room_title") or item.get("title") or "-")[:18], - str(item.get("prize_value_yuan") or item.get("value") or "-"), - str(item.get("status") or "已记录"), - )) - mini_table(left, "高价值房间", high_rows, color=theme.GREEN).pack(fill="x", pady=(0, 12)) - text_panel(left, "运行日志", data.run_log[-80:], height=9).pack(fill="both", expand=True) - - snap = card(right, "当前截图") - snap.pack(fill="x", pady=(0, 12)) - snap_name = data.screenshot_path.name if data.screenshot_path else "暂无截图" - tk.Label(snap, text=snap_name, bg="#fbfcfa", fg=theme.TEXT, font=theme.FONT_UI, anchor="w").pack(fill="x", padx=12, pady=(4, 6)) - tk.Label(snap, text="完整预览请打开“截图预览”界面", bg=theme.TEAL_SOFT, fg=theme.TEAL_DARK, font=theme.FONT_SMALL, padx=8, pady=3).pack(anchor="w", padx=12, pady=(0, 12)) - text_panel(right, "实时动作", data.action_log[-80:], height=9).pack(fill="both", expand=True) + text_panel(right, "详细动作日志", data.action_log[-160:], height=24).pack(fill="both", expand=True) def build_statistics(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: diff --git a/gui/dashboard_app/theme.py b/gui/dashboard_app/theme.py index e7e0cd1..011046b 100644 --- a/gui/dashboard_app/theme.py +++ b/gui/dashboard_app/theme.py @@ -30,11 +30,12 @@ RADIUS_SM = 8 RADIUS_MD = 12 RADIUS_LG = 16 -FONT_UI = ("Microsoft YaHei UI", 9) -FONT_SMALL = ("Microsoft YaHei UI", 8) -FONT_TITLE = ("Microsoft YaHei UI", 14, "bold") -FONT_H2 = ("Microsoft YaHei UI", 10, "bold") -FONT_MONO = ("Consolas", 8) +FONT_UI = ("Microsoft YaHei UI", 12) +FONT_SMALL = ("Microsoft YaHei UI", 11) +FONT_READ = ("Microsoft YaHei UI", 13) +FONT_TITLE = ("Microsoft YaHei UI", 18, "bold") +FONT_H2 = ("Microsoft YaHei UI", 14, "bold") +FONT_MONO = ("Consolas", 13) def setup_styles(root) -> None: @@ -54,7 +55,7 @@ def setup_styles(root) -> None: 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", 17, "bold")) + style.configure("Value.TLabel", background=SURFACE, foreground=TEXT, font=("Microsoft YaHei UI", 22, "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, borderwidth=0) @@ -62,11 +63,11 @@ def setup_styles(root) -> None: 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("Dashboard.TNotebook.Tab", padding=(16, 9), font=FONT_SMALL) style.configure( "Treeview", - font=("Microsoft YaHei UI", 8), - rowheight=23, + font=("Microsoft YaHei UI", 13), + rowheight=38, background=SURFACE, fieldbackground=SURFACE, borderwidth=0, @@ -75,7 +76,7 @@ def setup_styles(root) -> None: style.map("Treeview", background=[("selected", TEAL_SOFT)], foreground=[("selected", TEXT)]) style.configure( "Treeview.Heading", - font=("Microsoft YaHei UI", 8, "bold"), + font=("Microsoft YaHei UI", 12, "bold"), background="#eef2eb", foreground=TEXT, relief="flat", diff --git a/gui/dashboard_app/widgets.py b/gui/dashboard_app/widgets.py index 360fbb7..681d685 100644 --- a/gui/dashboard_app/widgets.py +++ b/gui/dashboard_app/widgets.py @@ -127,8 +127,8 @@ class RoundedButton(tk.Canvas): "ghost": (theme.SURFACE, theme.TEXT, theme.TEAL_SOFT), } self.bg_color, self.fg_color, self.hover_color = colors.get(kind, colors["soft"]) - w = width or max(78, len(self.text) * 12 + 24) - super().__init__(parent, width=w, height=30, bg=_parent_bg(parent), highlightthickness=0, bd=0, cursor="hand2") + w = width or max(98, len(self.text) * 14 + 34) + super().__init__(parent, width=w, height=38, bg=_parent_bg(parent), highlightthickness=0, bd=0, cursor="hand2") self._draw(self.bg_color) self.bind("", self._click) self.bind("", lambda _e: self._draw(self.hover_color)) @@ -139,7 +139,7 @@ class RoundedButton(tk.Canvas): outline = theme.BORDER_DARK if self.kind == "primary" else theme.BORDER fg = self.fg_color if self._state != "disabled" else theme.SUBTLE rounded_rect(self, 1, 1, int(self["width"]) - 2, int(self["height"]) - 2, theme.RADIUS_SM, fill=fill, outline=outline) - self.create_text(int(self["width"]) // 2, int(self["height"]) // 2, text=self.text, fill=fg, font=("Microsoft YaHei UI", 8, "bold") if self.kind == "primary" else theme.FONT_SMALL) + self.create_text(int(self["width"]) // 2, int(self["height"]) // 2, text=self.text, fill=fg, font=("Microsoft YaHei UI", 12, "bold") if self.kind == "primary" else theme.FONT_UI) def _click(self, _event) -> None: if self.command and self._state != "disabled": @@ -166,7 +166,7 @@ class RoundedNavButton(tk.Canvas): self.text = _with_icon(text, NAV_ICONS.get(text)) self.command = command self.active = active - super().__init__(parent, height=27, bg=theme.SURFACE, highlightthickness=0, bd=0, cursor="hand2") + super().__init__(parent, height=34, bg=theme.SURFACE, highlightthickness=0, bd=0, cursor="hand2") self.bind("", lambda _e: self._draw()) self.bind("", lambda _e: self.command()) self.bind("", lambda _e: self._draw(hover=True)) @@ -181,10 +181,10 @@ class RoundedNavButton(tk.Canvas): width = max(1, self.winfo_width()) bg = theme.TEAL_SOFT if self.active else (theme.SURFACE_HOVER if hover else theme.SURFACE) fg = theme.TEAL_DARK if self.active else theme.TEXT - rounded_rect(self, 1, 2, width - 2, 25, theme.RADIUS_SM, fill=bg, outline=bg) + rounded_rect(self, 1, 2, width - 2, 32, theme.RADIUS_SM, fill=bg, outline=bg) if self.active: - rounded_rect(self, 3, 7, 7, 20, 4, fill=theme.TEAL, outline=theme.TEAL) - self.create_text(15 if self.active else 11, 14, text=self.text, anchor="w", fill=fg, font=("Microsoft YaHei UI", 8, "bold") if self.active else theme.FONT_UI) + rounded_rect(self, 3, 8, 8, 26, 4, fill=theme.TEAL, outline=theme.TEAL) + self.create_text(18 if self.active else 13, 17, text=self.text, anchor="w", fill=fg, font=("Microsoft YaHei UI", 11, "bold") if self.active else theme.FONT_UI) def clear(frame: tk.Misc) -> None: @@ -201,11 +201,11 @@ def nav_button(parent, text: str, command: Callable[[], None], *, active: bool = def pill(parent, text: str, *, fg: str = theme.TEAL, bg: str = theme.TEAL_SOFT) -> tk.Label: - return tk.Label(parent, text=text, bg=bg, fg=fg, font=("Microsoft YaHei UI", 8, "bold"), padx=10, pady=3) + return tk.Label(parent, text=text, bg=bg, fg=fg, font=("Microsoft YaHei UI", 10, "bold"), padx=10, pady=3) def status_pill(parent, text: str, *, color: str = theme.GREEN, bg: str = theme.GREEN_SOFT) -> tk.Label: - return tk.Label(parent, text=text, bg=bg, fg=color, font=("Microsoft YaHei UI", 8, "bold"), padx=12, pady=4) + return tk.Label(parent, text=text, bg=bg, fg=color, font=("Microsoft YaHei UI", 11, "bold"), padx=14, pady=5) def card(parent, title: str | None = None, *, padding: int = 14) -> tk.Frame: @@ -229,18 +229,20 @@ def metric(parent, title: str, value: object, hint: str = "", color: str = theme return box -def stat_tile(parent, title: str, value: object, hint: str, *, color: str, soft: str) -> tk.Frame: +def stat_tile(parent, title: str, value: object, hint: str, *, color: str, soft: str, compact: bool = False) -> tk.Frame: box = tk.Frame(parent, bg=theme.SURFACE, highlightbackground=theme.BORDER, highlightthickness=1) + if compact: + box.configure(height=72) accent = tk.Frame(box, bg=color, width=3) accent.pack(side="left", fill="y") inner = tk.Frame(box, bg=theme.SURFACE) inner.pack(side="left", fill="both", expand=True) head = tk.Frame(inner, bg=theme.SURFACE) - head.pack(fill="x", padx=13, pady=(9, 3)) + head.pack(fill="x", padx=13, pady=(8, 2)) tk.Label(head, text=title, bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_SMALL).pack(side="left") - tk.Label(head, text="●", bg=theme.SURFACE, fg=color, font=("Segoe UI", 11, "bold")).pack(side="right") - tk.Label(inner, text=str(value), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 16, "bold")).pack(anchor="w", padx=13) - tk.Label(inner, text=hint, bg=soft, fg=color, font=("Microsoft YaHei UI", 8, "bold"), padx=9, pady=2).pack(anchor="w", padx=13, pady=(4, 9)) + tk.Label(head, text="●", bg=theme.SURFACE, fg=color, font=("Segoe UI", 10, "bold")).pack(side="right") + tk.Label(inner, text=str(value), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 18, "bold")).pack(anchor="w", padx=13) + tk.Label(inner, text=hint, bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=10, pady=2).pack(anchor="w", padx=13, pady=(5, 9)) return box @@ -263,7 +265,20 @@ def flow_grid(parent, columns: int = 4) -> tk.Frame: 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=theme.SURFACE_ALT, fg=theme.TEXT, insertbackground=theme.TEAL, font=theme.FONT_MONO, padx=10, pady=9) + text = tk.Text( + box, + height=height, + wrap="none", + bd=0, + bg=theme.SURFACE_ALT, + fg=theme.TEXT, + insertbackground=theme.TEAL, + font=theme.FONT_MONO, + padx=14, + pady=12, + spacing1=3, + spacing3=4, + ) text.pack(fill="both", expand=True, padx=11, pady=(4, 11)) content = "\n".join(list(lines)[:260]) or "暂无数据" text.insert("1.0", content) @@ -290,14 +305,14 @@ def mini_table(parent, title: str, rows: Sequence[tuple[str, str, str]], *, colo body = tk.Frame(box, bg=theme.SURFACE) body.pack(fill="both", expand=True, padx=11, pady=(4, 11)) if not rows: - tk.Label(body, text="暂无数据", bg=theme.SURFACE, fg=theme.MUTED, pady=20).pack(fill="x") + tk.Label(body, text="暂无数据", bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_READ, pady=20).pack(fill="x") return box for idx, (a, b, c) in enumerate(rows[:8]): row = tk.Frame(body, bg=theme.SURFACE if idx % 2 == 0 else theme.SURFACE_ALT) row.pack(fill="x", pady=1) - tk.Label(row, text=a, bg=row["bg"], fg=theme.TEXT, font=theme.FONT_SMALL, anchor="w").pack(side="left", fill="x", expand=True, padx=8, pady=5) - tk.Label(row, text=b, bg=row["bg"], fg=color, font=("Microsoft YaHei UI", 9, "bold"), width=10).pack(side="left", padx=4) - tk.Label(row, text=c, bg=row["bg"], fg=theme.MUTED, font=theme.FONT_SMALL, width=12).pack(side="left", padx=4) + tk.Label(row, text=a, bg=row["bg"], fg=theme.TEXT, font=theme.FONT_READ, anchor="w").pack(side="left", fill="x", expand=True, padx=9, pady=7) + tk.Label(row, text=b, bg=row["bg"], fg=color, font=("Microsoft YaHei UI", 10, "bold"), width=10).pack(side="left", padx=5) + tk.Label(row, text=c, bg=row["bg"], fg=theme.MUTED, font=theme.FONT_READ, width=12).pack(side="left", padx=5) return box