Polish dashboard table styling
This commit is contained in:
1 parent
ab37165baf
commit
c2cbee9592
4 files changed
+66
-19
No files matched your search
@@ -201,8 +201,8 @@ RESERVATION_COLUMNS = (
|
||||
|
||||
|
||||
HOME_RESERVATION_COLUMNS = (
|
||||
("idx", "#", 32), ("pos", "位置", 54), ("title", "直播间", 120), ("content", "内容", 160),
|
||||
("value", "价值", 58), ("countdown", "倒计时", 76), ("status", "状态", 68), ("target_time", "开奖时间", 132),
|
||||
("idx", "#", 32), ("pos", "位置", 48), ("title", "直播间", 112), ("content", "内容", 214),
|
||||
("value", "价值", 60), ("status", "状态", 72),
|
||||
)
|
||||
|
||||
|
||||
@@ -233,10 +233,15 @@ def _replace_table_rows(tree: ttk.Treeview, columns: tuple[tuple[str, str, int],
|
||||
for item_id in tree.get_children(""):
|
||||
tree.delete(item_id)
|
||||
if rows:
|
||||
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",),
|
||||
)
|
||||
else:
|
||||
tree.insert("", "end", values=["暂无数据" if idx == 0 else "" for idx, _c in enumerate(columns)])
|
||||
tree.insert("", "end", values=["暂无数据" if idx == 0 else "" for idx, _c in enumerate(columns)], tags=("empty",))
|
||||
try:
|
||||
tree.yview_moveto(top_pos)
|
||||
except Exception:
|
||||
|
||||
@@ -194,8 +194,8 @@ def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
||||
|
||||
body = tk.Frame(parent, bg=theme.BG)
|
||||
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_columnconfigure(0, weight=4, minsize=620)
|
||||
body.grid_columnconfigure(1, weight=2, minsize=360)
|
||||
body.grid_rowconfigure(0, weight=1)
|
||||
|
||||
left = tk.Frame(body, bg=theme.BG)
|
||||
|
||||
@@ -66,20 +66,44 @@ def setup_styles(root) -> None:
|
||||
style.configure("Dashboard.TNotebook.Tab", padding=(16, 9), font=FONT_SMALL)
|
||||
style.configure(
|
||||
"Treeview",
|
||||
font=("Microsoft YaHei UI", 15),
|
||||
rowheight=48,
|
||||
font=("Microsoft YaHei UI", 14),
|
||||
rowheight=44,
|
||||
background=SURFACE,
|
||||
fieldbackground=SURFACE,
|
||||
borderwidth=0,
|
||||
relief="flat",
|
||||
)
|
||||
style.map("Treeview", background=[("selected", TEAL_SOFT)], foreground=[("selected", TEXT)])
|
||||
style.map("Treeview", background=[("selected", TEAL_DARK)], foreground=[("selected", "#ffffff")])
|
||||
style.configure(
|
||||
"Treeview.Heading",
|
||||
font=("Microsoft YaHei UI", 14, "bold"),
|
||||
background="#eef4f7",
|
||||
font=("Microsoft YaHei UI", 13, "bold"),
|
||||
background="#eaf1f4",
|
||||
foreground=TEXT,
|
||||
relief="flat",
|
||||
padding=(10, 10),
|
||||
)
|
||||
style.configure(
|
||||
"Dashboard.Treeview",
|
||||
font=("Microsoft YaHei UI", 14),
|
||||
rowheight=46,
|
||||
background=SURFACE,
|
||||
fieldbackground=SURFACE,
|
||||
foreground=TEXT,
|
||||
borderwidth=0,
|
||||
relief="flat",
|
||||
)
|
||||
style.map(
|
||||
"Dashboard.Treeview",
|
||||
background=[("selected", TEAL_DARK)],
|
||||
foreground=[("selected", "#ffffff")],
|
||||
)
|
||||
style.configure(
|
||||
"Dashboard.Treeview.Heading",
|
||||
font=("Microsoft YaHei UI", 13, "bold"),
|
||||
background="#eaf1f4",
|
||||
foreground=TEXT,
|
||||
relief="flat",
|
||||
padding=(10, 11),
|
||||
)
|
||||
style.configure(
|
||||
"TCombobox",
|
||||
|
||||
@@ -490,26 +490,44 @@ 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 = tk.Frame(box, bg=theme.SURFACE_ALT, highlightbackground=theme.BORDER, highlightthickness=1, bd=0)
|
||||
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 = ttk.Treeview(table_wrap, columns=[c[0] for c in columns], show="headings", height=height, style="Dashboard.Treeview")
|
||||
tree.tag_configure("odd", background=theme.SURFACE)
|
||||
tree.tag_configure("even", background=theme.SURFACE_ALT)
|
||||
tree.tag_configure("even", background="#f7fbfc")
|
||||
tree.tag_configure("empty", background=theme.SURFACE_ALT, foreground=theme.MUTED)
|
||||
ybar = SlimScrollbar(table_wrap, orient="vertical", command=lambda *args: tree.yview(*[a for a in args if a is not None]))
|
||||
xbar = SlimScrollbar(table_wrap, orient="horizontal", command=lambda *args: tree.xview(*[a for a in args if a is not None]))
|
||||
tree.configure(yscrollcommand=ybar.set, xscrollcommand=xbar.set)
|
||||
for key, label, width in columns:
|
||||
total_width = sum(width for _key, _label, width in columns)
|
||||
compact_table = total_width <= 640
|
||||
for idx, (key, label, width) in enumerate(columns):
|
||||
tree.heading(key, text=label)
|
||||
tree.column(key, width=width, minwidth=min(width, 90), anchor="w", stretch=False)
|
||||
anchor = "center" if width <= 90 or key in {"idx", "pos", "value", "status"} else "w"
|
||||
stretch = compact_table or len(columns) <= 5 or idx == len(columns) - 1
|
||||
min_width = min(width, 76) if width <= 90 else min(width, 120)
|
||||
tree.column(key, width=width, minwidth=min_width, anchor=anchor, stretch=stretch)
|
||||
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.insert("", "end", values=["暂无数据" if idx == 0 else "" for idx, _c in enumerate(columns)], tags=("empty",))
|
||||
tree.grid(row=0, column=0, sticky="nsew")
|
||||
ybar.grid(row=0, column=1, sticky="ns", padx=(4, 6), pady=8)
|
||||
xbar.grid(row=1, column=0, sticky="ew", padx=8, pady=(4, 6))
|
||||
xbar.grid(row=1, column=0, sticky="ew", padx=10, pady=(4, 7))
|
||||
|
||||
def _wheel(event):
|
||||
tree.yview_scroll(int(-1 * (event.delta / 120)), "units")
|
||||
return "break"
|
||||
|
||||
def _shift_wheel(event):
|
||||
tree.xview_scroll(int(-1 * (event.delta / 120)), "units")
|
||||
return "break"
|
||||
|
||||
tree.bind("<MouseWheel>", _wheel)
|
||||
tree.bind("<Shift-MouseWheel>", _shift_wheel)
|
||||
table_wrap.configure(width=max(1, min(total_width + 36, 980)))
|
||||
box.tree = tree # type: ignore[attr-defined]
|
||||
box.columns_spec = list(columns) # type: ignore[attr-defined]
|
||||
return box
|
||||
|
||||
Reference in new issue
Block a user