style: unify dashboard scrollbars

This commit is contained in:
Your Name committed 2026-06-27 23:40:25 +08:00
1 parent 39996405d5
commit 7234bf0cac
4 files changed
+62 -37

No files matched your search

+1
View File
@@ -15,6 +15,7 @@
## [Unreleased]
## [V3.3.6] — 2026-06-27
## [V3.3.5] — 2026-06-27
## [V3.3.4] — 2026-06-26
### Added
+1 -1
View File
@@ -10,7 +10,7 @@
from typing import Optional
APP_NAME = "douyin_guaji"
APP_VERSION = "V3.3.5"
APP_VERSION = "V3.3.6"
APP_BUILD_DATE = "2026-06-27"
# 兼容旧代码与测试:提供 VERSION / RELEASE_DATE 别名
+59 -35
View File
@@ -244,10 +244,18 @@ class RoundedNavButton(tk.Canvas):
class SlimScrollbar(tk.Canvas):
def __init__(self, parent, *, command: Callable[[str, int | float, str | None], None] | None = None) -> None:
def __init__(
self,
parent,
*,
command: Callable[[str, int | float, str | None], None] | None = None,
orient: str = "vertical",
) -> None:
self.orient = "horizontal" if str(orient).startswith("h") else "vertical"
super().__init__(
parent,
width=14,
width=14 if self.orient == "vertical" else 1,
height=14 if self.orient == "horizontal" else 1,
bg=theme.SURFACE,
highlightthickness=0,
bd=0,
@@ -267,43 +275,59 @@ class SlimScrollbar(tk.Canvas):
self.last = max(self.first, min(1.0, float(last)))
self._draw()
def _track_length(self) -> int:
size = self.winfo_width() if self.orient == "horizontal" else self.winfo_height()
return max(1, int(size))
def _thumb_bounds(self) -> tuple[int, int, int]:
height = max(1, self.winfo_height())
track_top = 10
track_bottom = max(track_top + 1, height - 10)
track_h = track_bottom - track_top
thumb_h = max(42, int(track_h * max(0.08, self.last - self.first)))
travel = max(1, track_h - thumb_h)
y1 = track_top + int(travel * self.first)
return y1, min(track_bottom, y1 + thumb_h), travel
length = self._track_length()
track_start = 10
track_end = max(track_start + 1, length - 10)
track_len = track_end - track_start
min_thumb = 46 if self.orient == "horizontal" else 42
thumb_len = max(min_thumb, int(track_len * max(0.08, self.last - self.first)))
travel = max(1, track_len - thumb_len)
start = track_start + int(travel * self.first)
return start, min(track_end, start + thumb_len), travel
def _draw(self) -> None:
self.delete("all")
height = max(1, self.winfo_height())
self.create_line(7, 10, 7, height - 10, fill=theme.BG_ALT, width=8, capstyle="round")
length = self._track_length()
if self.orient == "horizontal":
self.create_line(10, 7, length - 10, 7, fill=theme.BG_ALT, width=8, capstyle="round")
else:
self.create_line(7, 10, 7, length - 10, fill=theme.BG_ALT, width=8, capstyle="round")
if self.last - self.first >= 0.995:
self.create_line(7, 10, 7, height - 10, fill=theme.BORDER, width=4, capstyle="round")
if self.orient == "horizontal":
self.create_line(10, 7, length - 10, 7, fill=theme.TEAL_SOFT, width=8, capstyle="round")
self.create_line(10, 7, length - 10, 7, fill=theme.BORDER_DARK, width=3, capstyle="round")
else:
self.create_line(7, 10, 7, length - 10, fill=theme.TEAL_SOFT, width=8, capstyle="round")
self.create_line(7, 10, 7, length - 10, fill=theme.BORDER_DARK, width=3, capstyle="round")
return
y1, y2, _travel = self._thumb_bounds()
self.create_line(7, y1, 7, y2, fill=theme.TEAL, width=8, capstyle="round")
self.create_line(7, y1 + 5, 7, y2 - 5, fill=theme.TEAL_DARK, width=3, capstyle="round")
start, end, _travel = self._thumb_bounds()
if self.orient == "horizontal":
self.create_line(start, 7, end, 7, fill=theme.TEAL, width=8, capstyle="round")
self.create_line(start + 5, 7, end - 5, 7, fill=theme.TEAL_DARK, width=3, capstyle="round")
else:
self.create_line(7, start, 7, end, fill=theme.TEAL, width=8, capstyle="round")
self.create_line(7, start + 5, 7, end - 5, fill=theme.TEAL_DARK, width=3, capstyle="round")
def _moveto_from_y(self, y: int) -> None:
def _moveto_from_position(self, pos: int) -> None:
if not self.command:
return
y1, y2, travel = self._thumb_bounds()
thumb_h = max(1, y2 - y1)
track_top = 10
target = (y - track_top - thumb_h / 2) / max(1, travel)
start, end, travel = self._thumb_bounds()
thumb_len = max(1, end - start)
target = (pos - 10 - thumb_len / 2) / max(1, travel)
self.command("moveto", max(0.0, min(1.0, target)), None)
def _jump(self, event) -> None:
self._drag_y = int(event.y)
self._moveto_from_y(int(event.y))
self._drag_y = int(event.x if self.orient == "horizontal" else event.y)
self._moveto_from_position(self._drag_y)
def _drag(self, event) -> None:
self._drag_y = int(event.y)
self._moveto_from_y(int(event.y))
self._drag_y = int(event.x if self.orient == "horizontal" else event.y)
self._moveto_from_position(self._drag_y)
def clear(frame: tk.Misc) -> None:
@@ -424,12 +448,12 @@ def log_panel(parent, title: str, lines: Iterable[str], height: int = 24) -> tup
spacing1=3,
spacing3=4,
)
yscroll = ttk.Scrollbar(wrap, orient="vertical", command=text.yview)
xscroll = ttk.Scrollbar(wrap, orient="horizontal", command=text.xview)
yscroll = SlimScrollbar(wrap, orient="vertical", command=lambda *args: text.yview(*[a for a in args if a is not None]))
xscroll = SlimScrollbar(wrap, orient="horizontal", command=lambda *args: text.xview(*[a for a in args if a is not None]))
text.configure(yscrollcommand=yscroll.set, xscrollcommand=xscroll.set)
text.grid(row=0, column=0, sticky="nsew")
yscroll.grid(row=0, column=1, sticky="ns")
xscroll.grid(row=1, column=0, sticky="ew")
yscroll.grid(row=0, column=1, sticky="ns", padx=(4, 6), pady=8)
xscroll.grid(row=1, column=0, sticky="ew", padx=8, pady=(4, 6))
content = "\n".join(list(lines)[-1000:]) or "暂无数据"
text.insert("1.0", content)
text.configure(state="disabled")
@@ -456,8 +480,8 @@ def table_panel(parent, title: str, columns: Sequence[tuple[str, str, int]], row
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)
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:
tree.heading(key, text=label)
@@ -467,8 +491,8 @@ def table_panel(parent, title: str, columns: Sequence[tuple[str, str, int]], row
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")
ybar.grid(row=0, column=1, sticky="ns")
xbar.grid(row=1, column=0, sticky="ew")
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))
box.tree = tree # type: ignore[attr-defined]
box.columns_spec = list(columns) # type: ignore[attr-defined]
return box
@@ -611,12 +635,12 @@ class ScrollFrame(ttk.Frame):
def __init__(self, parent):
super().__init__(parent, style="Dashboard.TFrame")
self.canvas = tk.Canvas(self, bg=theme.BG, highlightthickness=0, bd=0)
self.scroll = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.scroll = SlimScrollbar(self, orient="vertical", command=lambda *args: self.canvas.yview(*[a for a in args if a is not None]))
self.inner = tk.Frame(self.canvas, bg=theme.BG)
self.window_id = self.canvas.create_window((0, 0), window=self.inner, anchor="nw")
self.canvas.configure(yscrollcommand=self.scroll.set)
self.canvas.pack(side="left", fill="both", expand=True)
self.scroll.pack(side="right", fill="y")
self.scroll.pack(side="right", fill="y", padx=(6, 0), pady=6)
self.inner.bind("<Configure>", lambda _e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))
self.canvas.bind("<Configure>", lambda e: self.canvas.itemconfigure(self.window_id, width=e.width))
self.canvas.bind_all("<MouseWheel>", self._wheel)
+1 -1
View File
@@ -3,7 +3,7 @@
# 这里的 version 由 tools/dev/bump_version.py 与 version.py 同步维护。
# 注意:为兼容 PEP 440,这里去掉 "V" 前缀,仅保留数字部分(如 V3.3.3 → 3.3.3)。
name = "douyin_guaji"
version = "3.3.5"
version = "3.3.6"
description = "基于 ADB + OCR + 像素检测 + 模板匹配的抖音直播间福袋自动挂机工具"
readme = "README.md"
requires-python = ">=3.10"