style: polish dashboard app UI
This commit is contained in:
1 parent
cf2b71f831
commit
a7d6bc87b6
5 files changed
+134
-283
No files matched your search
+42
-26
@@ -19,14 +19,14 @@ from . import theme
|
||||
from .data import load_dashboard_data
|
||||
from .page_context import PageContext
|
||||
from .page_registry import PAGES
|
||||
from .widgets import ScrollFrame, button, clear, nav_button, rounded_surface, status_pill
|
||||
from .widgets import ScrollFrame, button, clear, field_shell, nav_button, rounded_surface, status_pill
|
||||
|
||||
|
||||
class DashboardApp:
|
||||
def __init__(self) -> None:
|
||||
self.root = tk.Tk()
|
||||
try:
|
||||
self.root.tk.call("tk", "scaling", 1.12)
|
||||
self.root.tk.call("tk", "scaling", 1.0)
|
||||
except Exception:
|
||||
pass
|
||||
self.root.title("抖音自动化助手 - 数据看板")
|
||||
@@ -66,40 +66,56 @@ class DashboardApp:
|
||||
shell = ttk.Frame(self.root, style="Dashboard.TFrame")
|
||||
shell.pack(fill="both", expand=True)
|
||||
|
||||
top = rounded_surface(shell, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
top.pack(fill="x", padx=18, pady=(14, 8))
|
||||
top = rounded_surface(shell, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_LG)
|
||||
top.pack(fill="x", padx=20, pady=(14, 8))
|
||||
brand = tk.Frame(top, bg=theme.SURFACE)
|
||||
brand.pack(fill="x", padx=18, pady=(12, 5))
|
||||
brand.pack(fill="x", padx=20, pady=(12, 5))
|
||||
mark = tk.Frame(brand, bg=theme.TEAL, width=34, height=34)
|
||||
mark.pack(side="left", padx=(0, 12))
|
||||
mark.pack_propagate(False)
|
||||
tk.Label(mark, text="抖", bg=theme.TEAL, fg="#ffffff", font=("Microsoft YaHei UI", 15, "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", 17, "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=18, pady=(0, 12))
|
||||
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, state="readonly")
|
||||
self.device_combo.pack(side="left", padx=(4, 8))
|
||||
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=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.Entry(tool_row, textvariable=self.y_var, width=7).pack(side="left")
|
||||
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)
|
||||
tool_row.pack(fill="x", padx=20, pady=(0, 12))
|
||||
tool_row.grid_columnconfigure(5, weight=1)
|
||||
ttk.Label(tool_row, text="设备:", background=theme.SURFACE, foreground=theme.MUTED).grid(row=0, column=0, sticky="w")
|
||||
self.device_combo = ttk.Combobox(tool_row, textvariable=self.device_var, values=[], width=36, state="readonly")
|
||||
self.device_combo.grid(row=0, column=1, sticky="w", padx=(6, 12), pady=(0, 8))
|
||||
button(tool_row, "刷新设备", self.refresh_devices, width=128).grid(row=0, column=2, sticky="e", padx=3, pady=(0, 8))
|
||||
self.scan_button = button(tool_row, "扫描 WiFi", self.scan_wifi, width=136)
|
||||
self.scan_button.grid(row=0, column=3, sticky="e", padx=3, pady=(0, 8))
|
||||
button(tool_row, "WiFi ADB", self.open_wifi_adb, width=124).grid(row=0, column=4, sticky="e", padx=3, pady=(0, 8))
|
||||
|
||||
y_shell = field_shell(tool_row, "Y偏移")
|
||||
y_shell.grid(row=1, column=0, columnspan=2, sticky="w", pady=(0, 2))
|
||||
y_entry = tk.Entry(
|
||||
y_shell,
|
||||
textvariable=self.y_var,
|
||||
width=12,
|
||||
bg=theme.SURFACE_ALT,
|
||||
fg=theme.TEXT,
|
||||
insertbackground=theme.TEAL,
|
||||
relief="flat",
|
||||
bd=0,
|
||||
font=theme.FONT_UI,
|
||||
)
|
||||
y_entry.pack(fill="x", padx=11, pady=(0, 9))
|
||||
actions = tk.Frame(tool_row, bg=theme.SURFACE)
|
||||
actions.grid(row=1, column=2, columnspan=3, sticky="w")
|
||||
button(actions, "保存配置", self.save_config, width=132).pack(side="left", padx=3)
|
||||
button(actions, "截图+OCR", self.screenshot_ocr, kind="primary", width=146).pack(side="left", padx=3)
|
||||
|
||||
main = ttk.Frame(shell, style="Dashboard.TFrame")
|
||||
main.pack(fill="both", expand=True, padx=18, pady=(6, 8))
|
||||
main.pack(fill="both", expand=True, padx=20, pady=(8, 8))
|
||||
main.grid_columnconfigure(1, weight=1)
|
||||
main.grid_rowconfigure(0, weight=1)
|
||||
|
||||
sidebar = rounded_surface(main, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
sidebar.grid(row=0, column=0, sticky="nsw", padx=(0, 16))
|
||||
sidebar.configure(width=204)
|
||||
sidebar = rounded_surface(main, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_LG)
|
||||
sidebar.grid(row=0, column=0, sticky="nsw", padx=(0, 18))
|
||||
sidebar.configure(width=218)
|
||||
sidebar.grid_propagate(False)
|
||||
sidebar.pack_propagate(False)
|
||||
nav_canvas = tk.Canvas(sidebar, bg=theme.SURFACE, highlightthickness=0, bd=0)
|
||||
@@ -134,10 +150,10 @@ class DashboardApp:
|
||||
("数据", ["运行日志", "行为日志", "实时状态", "截图预览", "统计信息", "预约队列", "高价值房间", "OCR结果", "中奖记录", "映射表"]),
|
||||
("连接", ["WiFi ADB"]),
|
||||
]:
|
||||
ttk.Label(nav_inner, text=group_title, background=theme.SURFACE, foreground=theme.MUTED, font=theme.FONT_SMALL).pack(anchor="w", padx=14, pady=(13, 5))
|
||||
ttk.Label(nav_inner, text=group_title, background=theme.SURFACE, foreground=theme.MUTED, font=("Microsoft YaHei UI", 10, "bold")).pack(anchor="w", padx=16, pady=(14, 6))
|
||||
for name in names:
|
||||
btn = nav_button(nav_inner, name, lambda n=name: self.show_page(n), active=name == self.current_page)
|
||||
btn.pack(fill="x", padx=10, pady=1)
|
||||
btn.pack(fill="x", padx=12, pady=2)
|
||||
self.nav_buttons[name] = btn
|
||||
_bind_nav_wheel(sidebar)
|
||||
|
||||
@@ -145,8 +161,8 @@ class DashboardApp:
|
||||
self.content_scroll.grid(row=0, column=1, sticky="nsew")
|
||||
self.content = self.content_scroll.inner
|
||||
|
||||
bottom = rounded_surface(shell, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
bottom.pack(fill="x", padx=18, pady=(4, 14))
|
||||
bottom = rounded_surface(shell, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_LG)
|
||||
bottom.pack(fill="x", padx=20, pady=(6, 16))
|
||||
inner_bottom = tk.Frame(bottom, bg=theme.SURFACE)
|
||||
inner_bottom.pack(fill="x", padx=14, pady=11)
|
||||
button(inner_bottom, "开始运行", self.start_run, kind="primary", width=132).pack(side="left", padx=(0, 8))
|
||||
|
||||
@@ -190,12 +190,13 @@ def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
||||
]
|
||||
for idx, item in enumerate(values):
|
||||
tile = stat_tile(metrics, *item[:3], color=item[3], soft=item[4], compact=True)
|
||||
tile.grid(row=idx // 3, column=idx % 3, sticky="ew", padx=4, pady=4)
|
||||
tile.grid(row=idx // 3, column=idx % 3, sticky="ew", padx=6, pady=5)
|
||||
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
body.pack(fill="both", expand=True)
|
||||
body.pack(fill="both", expand=True, pady=(4, 0))
|
||||
body.grid_columnconfigure(0, weight=3, minsize=540)
|
||||
body.grid_columnconfigure(1, weight=2, minsize=380)
|
||||
body.grid_rowconfigure(0, weight=1)
|
||||
|
||||
left = tk.Frame(body, bg=theme.BG)
|
||||
right = tk.Frame(body, bg=theme.BG)
|
||||
@@ -215,7 +216,7 @@ def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
||||
include_created=False,
|
||||
).pack(side="left")
|
||||
|
||||
preview_panel(right, data.current_screenshot_path, "实时截图").pack(fill="both", expand=True)
|
||||
preview_panel(right, data.current_screenshot_path, "实时截图", max_size=(430, 620)).pack(fill="both", expand=True)
|
||||
|
||||
|
||||
def _statistics_values(data: DashboardData, ctx: PageContext) -> tuple[dict[str, Any], str, str]:
|
||||
|
||||
+16
-194
@@ -47,56 +47,6 @@ def _last_log_time(stats: dict[str, Any]) -> str:
|
||||
return "-"
|
||||
|
||||
|
||||
def _group(parent: tk.Misc, title: str) -> tk.Frame:
|
||||
box = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
box.pack(fill="both", expand=True)
|
||||
head = tk.Frame(box, bg=theme.SURFACE)
|
||||
head.pack(fill="x", padx=16, pady=(14, 8))
|
||||
tk.Frame(head, bg=theme.TEAL, width=4, height=18).pack(side="left", padx=(0, 10))
|
||||
tk.Label(head, text=title, bg=theme.SURFACE, fg=theme.TEXT, font=theme.FONT_H2).pack(side="left")
|
||||
body = tk.Frame(box, bg=theme.SURFACE)
|
||||
body.pack(fill="both", expand=True, padx=16, pady=(0, 14))
|
||||
return body
|
||||
|
||||
|
||||
def _metric_row(parent: tk.Misc, label: str, value: object, hint: str = "", color: str = theme.TEAL) -> None:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
row.pack(fill="x", pady=4)
|
||||
tk.Label(row, text=label, bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_UI).pack(side="left")
|
||||
tk.Label(row, text=str(value), bg=theme.SURFACE, fg=color, font=("Microsoft YaHei UI", 15, "bold")).pack(side="right")
|
||||
if hint:
|
||||
tk.Label(parent, text=hint, bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_SMALL).pack(anchor="w", pady=(0, 4))
|
||||
|
||||
|
||||
def _kpi_tile(parent: tk.Misc, title: str, value: object, hint: str, color: str, soft: str) -> tk.Frame:
|
||||
box = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
box.configure(height=104)
|
||||
box.pack_propagate(False)
|
||||
accent = tk.Frame(box, bg=color, width=4)
|
||||
accent.pack(side="left", fill="y")
|
||||
inner = tk.Frame(box, bg=theme.SURFACE)
|
||||
inner.pack(side="left", fill="both", expand=True, padx=14, pady=10)
|
||||
head = tk.Frame(inner, bg=theme.SURFACE)
|
||||
head.pack(fill="x")
|
||||
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", 9, "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", pady=(4, 0))
|
||||
tk.Label(inner, text=hint, bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=9, pady=2).pack(anchor="w", pady=(5, 0))
|
||||
return box
|
||||
|
||||
|
||||
def _bar_row(parent: tk.Misc, label: str, value: int, total: int, color: str = theme.TEAL) -> None:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
row.pack(fill="x", pady=5)
|
||||
tk.Label(row, text=label, bg=theme.SURFACE, fg=theme.TEXT, font=theme.FONT_UI).pack(side="left")
|
||||
tk.Label(row, text=f"{value} {_fmt_rate(value, total)}", bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_SMALL).pack(side="right")
|
||||
track = tk.Frame(parent, bg=theme.BG_ALT, height=8)
|
||||
track.pack(fill="x", pady=(0, 4))
|
||||
pct = 0.0 if total <= 0 else min(1.0, max(0.0, value / total))
|
||||
fill = tk.Frame(track, bg=color, height=8)
|
||||
fill.place(relx=0, rely=0, relwidth=pct, relheight=1)
|
||||
|
||||
|
||||
class StatsDashboardView:
|
||||
def __init__(self, parent: tk.Misc) -> None:
|
||||
self.root = tk.Frame(parent, bg=theme.BG)
|
||||
@@ -112,35 +62,34 @@ class StatsDashboardView:
|
||||
|
||||
def _kpi_tile(self, parent: tk.Misc, key: str, title: str, color: str, soft: str) -> tk.Frame:
|
||||
box = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
box.configure(height=104)
|
||||
box.configure(height=112)
|
||||
box.pack_propagate(False)
|
||||
tk.Frame(box, bg=color, width=4).pack(side="left", fill="y")
|
||||
inner = tk.Frame(box, bg=theme.SURFACE)
|
||||
inner.pack(side="left", fill="both", expand=True, padx=14, pady=10)
|
||||
inner.pack(fill="both", expand=True, padx=16, pady=12)
|
||||
head = tk.Frame(inner, bg=theme.SURFACE)
|
||||
head.pack(fill="x")
|
||||
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", 9, "bold")).pack(side="right")
|
||||
tk.Label(inner, textvariable=self._var(f"{key}.value"), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 18, "bold")).pack(anchor="w", pady=(4, 0))
|
||||
tk.Label(inner, textvariable=self._var(f"{key}.hint"), bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=9, pady=2).pack(anchor="w", pady=(5, 0))
|
||||
tk.Label(inner, textvariable=self._var(f"{key}.value"), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 22, "bold")).pack(anchor="w", pady=(5, 0))
|
||||
tk.Label(inner, textvariable=self._var(f"{key}.hint"), bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=10, pady=3).pack(anchor="w", pady=(7, 0))
|
||||
return box
|
||||
|
||||
def _metric_row(self, parent: tk.Misc, key: str, label: str, color: str = theme.TEAL) -> None:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
row.pack(fill="x", pady=4)
|
||||
tk.Label(row, text=label, bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_UI).pack(side="left")
|
||||
tk.Label(row, textvariable=self._var(f"{key}.value"), bg=theme.SURFACE, fg=color, font=("Microsoft YaHei UI", 15, "bold")).pack(side="right")
|
||||
tk.Label(parent, textvariable=self._var(f"{key}.hint"), bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_SMALL).pack(anchor="w", pady=(0, 4))
|
||||
row = tk.Frame(parent, bg=theme.SURFACE_ALT)
|
||||
row.pack(fill="x", pady=5)
|
||||
tk.Label(row, text=label, bg=theme.SURFACE_ALT, fg=theme.MUTED, font=theme.FONT_UI, anchor="w").pack(side="left", fill="x", expand=True, padx=(10, 6), pady=(8, 2))
|
||||
tk.Label(row, textvariable=self._var(f"{key}.value"), bg=theme.SURFACE_ALT, fg=color, font=("Microsoft YaHei UI", 16, "bold")).pack(side="right", padx=10, pady=(8, 2))
|
||||
tk.Label(parent, textvariable=self._var(f"{key}.hint"), bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_SMALL).pack(anchor="w", pady=(0, 5), padx=2)
|
||||
|
||||
def _bar_row(self, parent: tk.Misc, key: str, label: str, color: str = theme.TEAL) -> None:
|
||||
row = tk.Frame(parent, bg=theme.SURFACE)
|
||||
row.pack(fill="x", pady=5)
|
||||
row.pack(fill="x", pady=(7, 3))
|
||||
tk.Label(row, text=label, bg=theme.SURFACE, fg=theme.TEXT, font=theme.FONT_UI).pack(side="left")
|
||||
value_var = self._var(f"{key}.value")
|
||||
tk.Label(row, textvariable=value_var, bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_SMALL).pack(side="right")
|
||||
track = tk.Frame(parent, bg=theme.BG_ALT, height=8)
|
||||
track = tk.Frame(parent, bg=theme.BG_ALT, height=10)
|
||||
track.pack(fill="x", pady=(0, 4))
|
||||
fill = tk.Frame(track, bg=color, height=8)
|
||||
fill = tk.Frame(track, bg=color, height=10)
|
||||
fill.place(relx=0, rely=0, relwidth=0, relheight=1)
|
||||
self.bars[key] = (value_var, fill)
|
||||
|
||||
@@ -148,11 +97,11 @@ class StatsDashboardView:
|
||||
box = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
box.pack(fill="both", expand=True)
|
||||
head = tk.Frame(box, bg=theme.SURFACE)
|
||||
head.pack(fill="x", padx=16, pady=(14, 8))
|
||||
head.pack(fill="x", padx=18, pady=(16, 8))
|
||||
tk.Frame(head, bg=theme.TEAL, width=4, height=18).pack(side="left", padx=(0, 10))
|
||||
tk.Label(head, text=title, bg=theme.SURFACE, fg=theme.TEXT, font=theme.FONT_H2).pack(side="left")
|
||||
body = tk.Frame(box, bg=theme.SURFACE)
|
||||
body.pack(fill="both", expand=True, padx=16, pady=(0, 14))
|
||||
body.pack(fill="both", expand=True, padx=18, pady=(0, 16))
|
||||
return body
|
||||
|
||||
def _build(self) -> None:
|
||||
@@ -168,7 +117,7 @@ class StatsDashboardView:
|
||||
("total_run", "总运行", theme.BLUE, theme.BLUE_SOFT),
|
||||
]
|
||||
for idx, (key, title, color, soft) in enumerate(kpis):
|
||||
self._kpi_tile(grid, key, title, color, soft).grid(row=idx // 4, column=idx % 4, sticky="ew", padx=4, pady=4)
|
||||
self._kpi_tile(grid, key, title, color, soft).grid(row=idx // 4, column=idx % 4, sticky="ew", padx=6, pady=5)
|
||||
|
||||
panels = tk.Frame(self.root, bg=theme.BG)
|
||||
panels.pack(fill="both", expand=True)
|
||||
@@ -180,7 +129,7 @@ class StatsDashboardView:
|
||||
slots = []
|
||||
for idx in range(6):
|
||||
slot = tk.Frame(panels, bg=theme.BG)
|
||||
slot.grid(row=idx // 2, column=idx % 2, sticky="nsew", padx=(0 if idx % 2 == 0 else 8, 8 if idx % 2 == 0 else 0), pady=6)
|
||||
slot.grid(row=idx // 2, column=idx % 2, sticky="nsew", padx=(0 if idx % 2 == 0 else 10, 10 if idx % 2 == 0 else 0), pady=7)
|
||||
slots.append(slot)
|
||||
|
||||
core = self._group(slots[0], "核心流程")
|
||||
@@ -309,130 +258,3 @@ class StatsDashboardView:
|
||||
self._set("last_countdown", last.get("countdown") or "-", "")
|
||||
self._set("last_value", last.get("prize_value_yuan") or "-", "元")
|
||||
self._set("last_people", f"{last.get('participants') or '-'} / {last.get('copies') or '-'}", "")
|
||||
|
||||
|
||||
def _build_top_cards(parent: tk.Misc, stats: dict[str, Any], current_run: str, total_run: str) -> None:
|
||||
uptime = int(stats.get("uptime_seconds") or 0)
|
||||
if uptime > 0:
|
||||
current_run = _fmt_duration(uptime)
|
||||
grid = flow_grid(parent, 4)
|
||||
values = [
|
||||
("运行状态", "运行中" if stats.get("running") else "未运行", f"日志 {_last_log_time(stats)}", theme.TEAL, theme.TEAL_SOFT),
|
||||
("本次运行", current_run, "当前轮次", theme.BLUE, theme.BLUE_SOFT),
|
||||
("参与成功", _counter(stats, "fudai_attend_ok_unique"), "去重口径", theme.GREEN, theme.GREEN_SOFT),
|
||||
("中奖次数", _counter(stats, "fudai_result_win"), "开奖结果", theme.RED, theme.RED_SOFT),
|
||||
("识别福袋", _counter(stats, "fudai_seen_unique"), "唯一口径", theme.TEAL, theme.TEAL_SOFT),
|
||||
("打开详情", _counter(stats, "fudai_open_detail_unique"), "详情页", theme.BLUE, theme.BLUE_SOFT),
|
||||
("切换直播间", _counter(stats, "switch_room"), "运行动作", theme.AMBER, theme.AMBER_SOFT),
|
||||
("总运行", total_run, "日志累计", theme.BLUE, theme.BLUE_SOFT),
|
||||
]
|
||||
for idx, item in enumerate(values):
|
||||
tile = _kpi_tile(grid, *item[:3], color=item[3], soft=item[4])
|
||||
tile.grid(row=idx // 4, column=idx % 4, sticky="ew", padx=4, pady=4)
|
||||
|
||||
|
||||
def _build_core_flow(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "核心流程")
|
||||
seen = _counter(stats, "fudai_seen_unique")
|
||||
open_detail = _counter(stats, "fudai_open_detail_unique")
|
||||
click = _counter(stats, "fudai_click_attend_unique")
|
||||
attend = _counter(stats, "fudai_attend_ok_unique")
|
||||
win = _counter(stats, "fudai_result_win")
|
||||
no_win = _counter(stats, "fudai_result_no_win")
|
||||
_bar_row(body, "识别福袋", seen, max(seen, 1), theme.TEAL)
|
||||
_bar_row(body, "打开详情", open_detail, max(seen, 1), theme.BLUE)
|
||||
_bar_row(body, "点击参与", click, max(open_detail, 1), theme.AMBER)
|
||||
_bar_row(body, "参与成功", attend, max(click, attend, 1), theme.GREEN)
|
||||
_metric_row(body, "中奖率", _fmt_rate(win, win + no_win), f"中奖 {win} / 未中 {no_win}", theme.RED)
|
||||
|
||||
|
||||
def _build_efficiency(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "效率与动作")
|
||||
uptime = int(stats.get("uptime_seconds") or 0)
|
||||
_metric_row(body, "识别效率", _per_hour(_counter(stats, "fudai_seen_unique"), uptime), "每小时识别福袋", theme.TEAL)
|
||||
_metric_row(body, "参与效率", _per_hour(_counter(stats, "fudai_attend_ok_unique"), uptime), "每小时成功参与", theme.GREEN)
|
||||
_metric_row(body, "切换频率", _per_hour(_counter(stats, "switch_room"), uptime), "每小时切换直播间", theme.AMBER)
|
||||
ocr_attempt = _counter(stats, "ocr_attempt")
|
||||
_metric_row(body, "OCR成功率", _fmt_rate(_counter(stats, "ocr_success"), ocr_attempt), f"尝试 {ocr_attempt}", theme.BLUE)
|
||||
|
||||
|
||||
def _build_skip(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "过滤与跳过")
|
||||
items = [
|
||||
("价值过低", "fudai_skip_value_low", theme.AMBER),
|
||||
("人数过少", "fudai_skip_participants_low", theme.BLUE),
|
||||
("人数过多", "fudai_skip_participants_high", theme.BLUE),
|
||||
("内容过滤", "fudai_skip_content", theme.TEAL),
|
||||
("倒计时太短", "fudai_skip_countdown_short", theme.RED),
|
||||
("倒计时太长", "fudai_skip_countdown_long", theme.AMBER),
|
||||
("需要看播", "fudai_skip_watch_required", theme.RED),
|
||||
]
|
||||
total = sum(_counter(stats, key) for _, key, _ in items)
|
||||
if total <= 0:
|
||||
tk.Label(body, text="暂无跳过记录", bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_READ).pack(anchor="w", pady=8)
|
||||
return
|
||||
for label, key, color in items:
|
||||
value = _counter(stats, key)
|
||||
if value > 0:
|
||||
_bar_row(body, label, value, total, color)
|
||||
|
||||
|
||||
def _build_reservation(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "预约与回访")
|
||||
recorded = _counter(stats, "reservation_recorded")
|
||||
back_success = _counter(stats, "reservation_back_success")
|
||||
verify_ok = _counter(stats, "reservation_back_verify_ok")
|
||||
verify_fail = _counter(stats, "reservation_back_verify_fail")
|
||||
_metric_row(body, "记录预约", recorded, "累计写入预约队列", theme.TEAL)
|
||||
_metric_row(body, "回退成功", back_success, f"成功率 {_fmt_rate(back_success, recorded)}", theme.GREEN)
|
||||
_metric_row(body, "回退校验", _fmt_rate(verify_ok, verify_ok + verify_fail), f"成功 {verify_ok} / 失败 {verify_fail}", theme.BLUE)
|
||||
_metric_row(body, "高价值预约", _counter(stats, "fudai_reserved_high_value"), "倒计时长但价值高", theme.AMBER)
|
||||
|
||||
|
||||
def _build_health(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "运行健康")
|
||||
total = _counter(stats, "error_total")
|
||||
detail_errors = _counter(stats, "error_read_detail") + _counter(stats, "fudai_open_error")
|
||||
vision_errors = _counter(stats, "error_ocr") + _counter(stats, "error_screenshot") + _counter(stats, "error_detection")
|
||||
_metric_row(body, "总错误数", total, "运行日志异常计数", theme.RED if total else theme.GREEN)
|
||||
_metric_row(body, "识别/截图异常", vision_errors, "OCR、截图、识别", theme.RED if vision_errors else theme.GREEN)
|
||||
_metric_row(body, "详情异常", detail_errors, "读详情或打开失败", theme.RED if detail_errors else theme.GREEN)
|
||||
_metric_row(body, "慢操作", _counter(stats, "slow_operation"), ">5秒操作", theme.AMBER)
|
||||
|
||||
|
||||
def _build_latest(parent: tk.Misc, stats: dict[str, Any]) -> None:
|
||||
body = _group(parent, "最近福袋")
|
||||
last = stats.get("fudai_last", {}) or {}
|
||||
if not (last.get("content") or last.get("countdown")):
|
||||
tk.Label(body, text="暂无最近福袋信息", bg=theme.SURFACE, fg=theme.SUBTLE, font=theme.FONT_READ).pack(anchor="w", pady=8)
|
||||
return
|
||||
_metric_row(body, "内容", last.get("content") or "-", color=theme.TEXT)
|
||||
_metric_row(body, "倒计时", last.get("countdown") or "-", color=theme.BLUE)
|
||||
_metric_row(body, "价值", f"{last.get('prize_value_yuan') or '-'}", "元", theme.AMBER)
|
||||
participants = last.get("participants")
|
||||
copies = last.get("copies")
|
||||
_metric_row(body, "人数/份数", f"{participants or '-'} / {copies or '-'}", color=theme.TEAL)
|
||||
|
||||
|
||||
def build_stats_dashboard(parent: tk.Misc, stats: dict[str, Any], current_run: str, total_run: str) -> tk.Frame:
|
||||
_build_top_cards(parent, stats, current_run, total_run)
|
||||
grid = tk.Frame(parent, bg=theme.BG)
|
||||
grid.pack(fill="both", expand=True)
|
||||
for col in range(2):
|
||||
grid.grid_columnconfigure(col, weight=1, uniform="stats")
|
||||
for row in range(3):
|
||||
grid.grid_rowconfigure(row, weight=1)
|
||||
|
||||
panels = [
|
||||
_build_core_flow,
|
||||
_build_efficiency,
|
||||
_build_skip,
|
||||
_build_reservation,
|
||||
_build_health,
|
||||
_build_latest,
|
||||
]
|
||||
for idx, builder in enumerate(panels):
|
||||
slot = tk.Frame(grid, bg=theme.BG)
|
||||
slot.grid(row=idx // 2, column=idx % 2, sticky="nsew", padx=(0 if idx % 2 == 0 else 8, 8 if idx % 2 == 0 else 0), pady=6)
|
||||
builder(slot, stats)
|
||||
return grid
|
||||
+25
-25
@@ -3,32 +3,32 @@ from __future__ import annotations
|
||||
from tkinter import ttk
|
||||
|
||||
|
||||
BG = "#f3f6f8"
|
||||
BG_ALT = "#e8eef2"
|
||||
BG = "#f6f8fb"
|
||||
BG_ALT = "#edf2f7"
|
||||
SURFACE = "#ffffff"
|
||||
SURFACE_ALT = "#f7fafc"
|
||||
SURFACE_HOVER = "#edf7f5"
|
||||
BORDER = "#d9e3e8"
|
||||
BORDER_DARK = "#b9c8d0"
|
||||
TEXT = "#10201f"
|
||||
MUTED = "#5d6f78"
|
||||
SUBTLE = "#94a4ad"
|
||||
SURFACE_ALT = "#f8fafc"
|
||||
SURFACE_HOVER = "#eef7f6"
|
||||
BORDER = "#dde7ee"
|
||||
BORDER_DARK = "#b8c7d3"
|
||||
TEXT = "#111827"
|
||||
MUTED = "#5f7285"
|
||||
SUBTLE = "#94a3b8"
|
||||
TEAL = "#0f9488"
|
||||
TEAL_DARK = "#087368"
|
||||
TEAL_SOFT = "#e6f7f3"
|
||||
AMBER = "#a76707"
|
||||
AMBER_SOFT = "#fff4dd"
|
||||
RED = "#c74454"
|
||||
RED_SOFT = "#fff0f2"
|
||||
TEAL_DARK = "#08756e"
|
||||
TEAL_SOFT = "#e5f7f4"
|
||||
AMBER = "#b26a00"
|
||||
AMBER_SOFT = "#fff4dc"
|
||||
RED = "#cf4057"
|
||||
RED_SOFT = "#fff0f3"
|
||||
GREEN = "#15805a"
|
||||
GREEN_SOFT = "#e5f5ee"
|
||||
BLUE = "#2e6fd8"
|
||||
GREEN_SOFT = "#e7f7ef"
|
||||
BLUE = "#2f6fda"
|
||||
BLUE_SOFT = "#eaf2ff"
|
||||
SHADOW = "#e7edf1"
|
||||
SHADOW = "#d9e2ea"
|
||||
|
||||
RADIUS_SM = 8
|
||||
RADIUS_MD = 12
|
||||
RADIUS_LG = 16
|
||||
RADIUS_SM = 12
|
||||
RADIUS_MD = 18
|
||||
RADIUS_LG = 24
|
||||
|
||||
FONT_UI = ("Microsoft YaHei UI", 12)
|
||||
FONT_SMALL = ("Microsoft YaHei UI", 11)
|
||||
@@ -51,11 +51,11 @@ def setup_styles(root) -> None:
|
||||
style.configure("Toolbar.TFrame", background=SURFACE)
|
||||
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("Card.TFrame", background=SURFACE, borderwidth=0, relief="flat")
|
||||
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", 22, "bold"))
|
||||
style.configure("Value.TLabel", background=SURFACE, foreground=TEXT, font=("Microsoft YaHei UI", 23, "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)
|
||||
@@ -67,7 +67,7 @@ def setup_styles(root) -> None:
|
||||
style.configure(
|
||||
"Treeview",
|
||||
font=("Microsoft YaHei UI", 13),
|
||||
rowheight=38,
|
||||
rowheight=40,
|
||||
background=SURFACE,
|
||||
fieldbackground=SURFACE,
|
||||
borderwidth=0,
|
||||
@@ -77,7 +77,7 @@ def setup_styles(root) -> None:
|
||||
style.configure(
|
||||
"Treeview.Heading",
|
||||
font=("Microsoft YaHei UI", 12, "bold"),
|
||||
background="#edf3f1",
|
||||
background="#eef4f7",
|
||||
foreground=TEXT,
|
||||
relief="flat",
|
||||
)
|
||||
|
||||
@@ -126,6 +126,17 @@ class RoundedSurface(tk.Frame):
|
||||
width = max(2, self.winfo_width())
|
||||
height = max(2, self.winfo_height())
|
||||
self._canvas.delete("all")
|
||||
if self._outline != self._fill:
|
||||
rounded_rect(
|
||||
self._canvas,
|
||||
3,
|
||||
4,
|
||||
width - 2,
|
||||
height - 1,
|
||||
self._radius,
|
||||
fill=theme.SHADOW,
|
||||
outline=theme.SHADOW,
|
||||
)
|
||||
rounded_rect(
|
||||
self._canvas,
|
||||
1,
|
||||
@@ -165,15 +176,15 @@ class RoundedButton(tk.Canvas):
|
||||
self.kind = kind
|
||||
self._state = "normal"
|
||||
colors = {
|
||||
"primary": (theme.TEAL, "#ffffff", theme.TEAL_DARK),
|
||||
"danger": (theme.RED_SOFT, theme.RED, "#ffe5e2"),
|
||||
"amber": (theme.AMBER_SOFT, "#8a5a00", "#ffe8b8"),
|
||||
"soft": (theme.SURFACE, theme.TEXT, theme.SURFACE_HOVER),
|
||||
"ghost": (theme.SURFACE, theme.TEXT, theme.TEAL_SOFT),
|
||||
"primary": (theme.TEAL, "#ffffff", theme.TEAL_DARK, theme.TEAL),
|
||||
"danger": (theme.RED_SOFT, theme.RED, "#ffe5e2", "#f2ccd1"),
|
||||
"amber": (theme.AMBER_SOFT, "#8a5a00", "#ffe8b8", "#f0d6a0"),
|
||||
"soft": (theme.SURFACE, theme.TEXT, theme.SURFACE_HOVER, theme.BORDER),
|
||||
"ghost": (theme.SURFACE, theme.TEXT, theme.TEAL_SOFT, theme.SURFACE),
|
||||
}
|
||||
self.bg_color, self.fg_color, self.hover_color = colors.get(kind, colors["soft"])
|
||||
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.bg_color, self.fg_color, self.hover_color, self.outline_color = colors.get(kind, colors["soft"])
|
||||
w = width or max(104, len(self.text) * 14 + 38)
|
||||
super().__init__(parent, width=w, height=40, bg=_parent_bg(parent), highlightthickness=0, bd=0, cursor="hand2")
|
||||
self._draw(self.bg_color)
|
||||
self.bind("<Button-1>", self._click)
|
||||
self.bind("<Enter>", lambda _e: self._draw(self.hover_color))
|
||||
@@ -181,7 +192,7 @@ class RoundedButton(tk.Canvas):
|
||||
|
||||
def _draw(self, fill: str) -> None:
|
||||
self.delete("all")
|
||||
outline = theme.TEAL if self.kind == "primary" else theme.BORDER
|
||||
outline = self.outline_color
|
||||
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", 12, "bold") if self.kind == "primary" else theme.FONT_UI)
|
||||
@@ -211,7 +222,7 @@ class RoundedNavButton(tk.Canvas):
|
||||
self.text = _with_icon(text, NAV_ICONS.get(text))
|
||||
self.command = command
|
||||
self.active = active
|
||||
super().__init__(parent, height=34, bg=theme.SURFACE, highlightthickness=0, bd=0, cursor="hand2")
|
||||
super().__init__(parent, height=38, bg=theme.SURFACE, highlightthickness=0, bd=0, cursor="hand2")
|
||||
self.bind("<Configure>", lambda _e: self._draw())
|
||||
self.bind("<Button-1>", lambda _e: self.command())
|
||||
self.bind("<Enter>", lambda _e: self._draw(hover=True))
|
||||
@@ -226,10 +237,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, 32, theme.RADIUS_SM, fill=bg, outline=bg)
|
||||
rounded_rect(self, 1, 3, width - 2, 35, theme.RADIUS_SM, fill=bg, outline=bg)
|
||||
if self.active:
|
||||
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)
|
||||
rounded_rect(self, 4, 10, 9, 28, 4, fill=theme.TEAL, outline=theme.TEAL)
|
||||
self.create_text(20 if self.active else 14, 19, 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:
|
||||
@@ -246,19 +257,19 @@ 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", 10, "bold"), padx=10, pady=3)
|
||||
return tk.Label(parent, text=text, bg=bg, fg=fg, font=("Microsoft YaHei UI", 10, "bold"), padx=11, pady=4)
|
||||
|
||||
|
||||
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", 11, "bold"), padx=14, pady=5)
|
||||
return tk.Label(parent, text=text, bg=bg, fg=color, font=("Microsoft YaHei UI", 11, "bold"), padx=15, pady=6)
|
||||
|
||||
|
||||
def card(parent, title: str | None = None, *, padding: int = 14) -> tk.Frame:
|
||||
frame = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
if title:
|
||||
head = tk.Frame(frame, bg=theme.SURFACE)
|
||||
head.pack(fill="x", padx=padding + 2, pady=(padding, 7))
|
||||
tk.Frame(head, bg=theme.TEAL, width=4, height=18).pack(side="left", padx=(0, 10))
|
||||
head.pack(fill="x", padx=padding + 4, pady=(padding + 2, 8))
|
||||
tk.Frame(head, bg=theme.TEAL, width=4, height=18).pack(side="left", padx=(0, 11))
|
||||
ttk.Label(head, text=title, style="H2.TLabel").pack(side="left")
|
||||
return frame
|
||||
|
||||
@@ -277,26 +288,25 @@ def metric(parent, title: str, value: object, hint: str = "", color: str = theme
|
||||
def stat_tile(parent, title: str, value: object, hint: str, *, color: str, soft: str, compact: bool = False) -> tk.Frame:
|
||||
box = rounded_surface(parent, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD)
|
||||
if compact:
|
||||
box.configure(height=72)
|
||||
accent = tk.Frame(box, bg=color, width=4)
|
||||
accent.pack(side="left", fill="y")
|
||||
box.configure(height=86)
|
||||
box.pack_propagate(False)
|
||||
inner = tk.Frame(box, bg=theme.SURFACE)
|
||||
inner.pack(side="left", fill="both", expand=True)
|
||||
inner.pack(fill="both", expand=True, padx=16, pady=12)
|
||||
head = tk.Frame(inner, bg=theme.SURFACE)
|
||||
head.pack(fill="x", padx=16, pady=(10, 2))
|
||||
head.pack(fill="x")
|
||||
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", 10, "bold")).pack(side="right")
|
||||
tk.Label(inner, text=str(value), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 19, "bold")).pack(anchor="w", padx=16)
|
||||
tk.Label(inner, text=hint, bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=11, pady=3).pack(anchor="w", padx=16, pady=(6, 10))
|
||||
tk.Label(inner, text=str(value), bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 21 if compact else 22, "bold")).pack(anchor="w", pady=(4, 0))
|
||||
tk.Label(inner, text=hint, bg=soft, fg=color, font=("Microsoft YaHei UI", 10, "bold"), padx=11, pady=3).pack(anchor="w", pady=(6, 0))
|
||||
return box
|
||||
|
||||
|
||||
def section(parent, title: str, subtitle: str = "") -> tk.Frame:
|
||||
row = tk.Frame(parent, bg=theme.BG)
|
||||
row.pack(fill="x", pady=(2, 10))
|
||||
row.pack(fill="x", pady=(2, 12))
|
||||
ttk.Label(row, text=title, style="Title.TLabel").pack(side="left")
|
||||
if subtitle:
|
||||
tk.Label(row, text=subtitle, bg=theme.TEAL_SOFT, fg=theme.TEAL_DARK, font=theme.FONT_SMALL, padx=12, pady=4).pack(side="left", padx=(12, 0))
|
||||
tk.Label(row, text=subtitle, bg=theme.TEAL_SOFT, fg=theme.TEAL_DARK, font=theme.FONT_SMALL, padx=12, pady=5).pack(side="left", padx=(12, 0))
|
||||
return row
|
||||
|
||||
|
||||
@@ -333,8 +343,8 @@ def text_panel(parent, title: str, lines: Iterable[str], height: int = 10) -> tk
|
||||
|
||||
def log_panel(parent, title: str, lines: Iterable[str], height: int = 24) -> tuple[tk.Frame, tk.Text]:
|
||||
box = card(parent, title)
|
||||
wrap = tk.Frame(box, bg=theme.SURFACE_ALT)
|
||||
wrap.pack(fill="both", expand=True, padx=11, pady=(4, 11))
|
||||
wrap = tk.Frame(box, bg=theme.SURFACE_ALT, highlightbackground=theme.BORDER, highlightthickness=1)
|
||||
wrap.pack(fill="both", expand=True, padx=13, pady=(4, 13))
|
||||
wrap.grid_rowconfigure(0, weight=1)
|
||||
wrap.grid_columnconfigure(0, weight=1)
|
||||
text = tk.Text(
|
||||
@@ -377,18 +387,20 @@ def log_panel(parent, title: str, lines: Iterable[str], height: int = 24) -> tup
|
||||
def table_panel(parent, title: str, columns: Sequence[tuple[str, str, int]], rows: Sequence[dict], height: int = 8) -> tk.Frame:
|
||||
box = card(parent, title)
|
||||
table_wrap = tk.Frame(box, bg=theme.SURFACE)
|
||||
table_wrap.pack(fill="both", expand=True, padx=14, pady=(4, 14))
|
||||
table_wrap.pack(fill="both", expand=True, padx=16, pady=(4, 16))
|
||||
table_wrap.grid_rowconfigure(0, weight=1)
|
||||
table_wrap.grid_columnconfigure(0, weight=1)
|
||||
tree = ttk.Treeview(table_wrap, columns=[c[0] for c in columns], show="headings", height=height)
|
||||
tree.tag_configure("odd", background=theme.SURFACE)
|
||||
tree.tag_configure("even", background=theme.SURFACE_ALT)
|
||||
ybar = ttk.Scrollbar(table_wrap, orient="vertical", command=tree.yview)
|
||||
xbar = ttk.Scrollbar(table_wrap, orient="horizontal", command=tree.xview)
|
||||
tree.configure(yscrollcommand=ybar.set, xscrollcommand=xbar.set)
|
||||
for key, label, width in columns:
|
||||
tree.heading(key, text=label)
|
||||
tree.column(key, width=width, minwidth=min(width, 90), anchor="w", stretch=False)
|
||||
for row in rows:
|
||||
tree.insert("", "end", values=[str(row.get(key, "-")) for key, _, _ in columns])
|
||||
for idx, row in enumerate(rows):
|
||||
tree.insert("", "end", values=[str(row.get(key, "-")) for key, _, _ in columns], tags=("even" if idx % 2 else "odd",))
|
||||
if not rows:
|
||||
tree.insert("", "end", values=["暂无数据" if idx == 0 else "" for idx, _c in enumerate(columns)])
|
||||
tree.grid(row=0, column=0, sticky="nsew")
|
||||
@@ -417,7 +429,7 @@ def mini_table(parent, title: str, rows: Sequence[tuple[str, str, str]], *, colo
|
||||
|
||||
def field_shell(parent, label: str) -> tk.Frame:
|
||||
row = rounded_surface(parent, fill=theme.SURFACE_ALT, outline=theme.BORDER, radius=theme.RADIUS_SM)
|
||||
tk.Label(row, text=label, bg=theme.SURFACE_ALT, fg=theme.MUTED, font=theme.FONT_SMALL).pack(anchor="w", padx=9, pady=(7, 1))
|
||||
tk.Label(row, text=label, bg=theme.SURFACE_ALT, fg=theme.MUTED, font=theme.FONT_SMALL).pack(anchor="w", padx=11, pady=(8, 2))
|
||||
return row
|
||||
|
||||
|
||||
@@ -493,8 +505,8 @@ def switch_row(parent, label: str, variable: tk.Variable | None = None, value: b
|
||||
bd=0,
|
||||
anchor="w",
|
||||
justify="left",
|
||||
font=theme.FONT_SMALL,
|
||||
).pack(fill="x", padx=9, pady=6)
|
||||
font=theme.FONT_UI,
|
||||
).pack(fill="x", padx=10, pady=8)
|
||||
return row
|
||||
|
||||
|
||||
@@ -513,7 +525,7 @@ def toolbar(parent, actions: Sequence[tuple[str, Callable[[], None] | None, str]
|
||||
def preview_panel(parent, image_path: Path | None, title: str = "截图预览", max_size: tuple[int, int] = (360, 560)) -> tk.Frame:
|
||||
box = card(parent, title)
|
||||
body = tk.Frame(box, bg=theme.SURFACE_ALT, highlightbackground=theme.BORDER, highlightthickness=1)
|
||||
body.pack(fill="both", expand=True, padx=14, pady=(4, 14))
|
||||
body.pack(fill="both", expand=True, padx=16, pady=(4, 16))
|
||||
if image_path and image_path.exists():
|
||||
try:
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
Reference in new issue
Block a user