-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyles.py
More file actions
184 lines (164 loc) · 7.13 KB
/
Copy pathstyles.py
File metadata and controls
184 lines (164 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import tkinter as tk
from tkinter import ttk
import tkinter.font as tkfont
C = {
"bg": "#f1f5f9",
"card": "#ffffff",
"input_bg": "#ffffff",
"disabled_bg": "#e2e8f0",
"log_bg": "#0f172a",
"log_fg": "#22c55e",
"log_insert": "#22c55e",
"text": "#0f172a",
"text_secondary": "#475569",
"text_muted": "#94a3b8",
"primary": "#2563eb",
"primary_hover": "#1d4ed8",
"success": "#16a34a",
"success_hover": "#15803d",
"danger": "#dc2626",
"danger_hover": "#b91c1c",
"warning": "#ca8a04",
"warning_hover": "#a16207",
"border": "#e2e8f0",
"input_border": "#cbd5e1",
"indicator_idle": "#cbd5e1",
"indicator_running": "#eab308",
"indicator_success": "#22c55e",
"indicator_error": "#ef4444",
"badge_api_bg": "#16a34a",
"badge_na_bg": "#dc2626",
"group_id_fg": "#2563eb",
"result_fg": "#2563eb",
"record_bg": "#ffffff",
"record_fg": "#0f172a",
"popup_bg": "#0f172a",
"popup_fg": "#22c55e",
"popup_insert": "#ffffff",
"token_idle": "#94a3b8",
"token_idle_fg": "#64748b",
"token_success": "#22c55e",
"token_success_fg": "#16a34a",
"token_error": "#ef4444",
"token_error_fg": "#dc2626",
}
FONT_DEFS = {
"default": ("Segoe UI", 10),
"heading": ("Segoe UI", 11, "bold"),
"small_heading": ("Segoe UI", 10, "bold"),
"small": ("Segoe UI", 8),
"badge": ("Segoe UI", 8, "bold"),
"mono": ("Consolas", 10),
"mono_small": ("Consolas", 9),
}
FONT_SCALE = 1.0
F = {}
_FONTS = {}
def _build_fonts():
global F
for name, spec in FONT_DEFS.items():
family, size = spec[0], spec[1]
weight = spec[2] if len(spec) > 2 else "normal"
new_size = max(int(size * FONT_SCALE), 1)
if name not in _FONTS:
_FONTS[name] = tkfont.Font(family=family, size=new_size, weight=weight)
else:
_FONTS[name].configure(family=family, size=new_size, weight=weight)
F[name] = _FONTS[name]
def set_font_scale(scale):
global FONT_SCALE
FONT_SCALE = max(0.5, min(scale, 3.0))
_build_fonts()
config_ttk_styles()
class PixelToggle(tk.Canvas):
"""Pixel-style sliding toggle: pink coin (off) -> green coin (on)."""
W, H = 45, 24
OFF = "#ff007f"
ON = "#00ffaa"
TRACK = "#d8dce2"
TRACK_ON = "#b5e8d5"
EDGE = "#9aa3b0"
EDGE_ON = "#5fb98b"
def __init__(self, parent, variable=None, command=None, **kw):
super().__init__(parent, width=self.W, height=self.H,
highlightthickness=0, bd=0, bg=kw.pop("bg", C["bg"]))
self._var = variable or tk.BooleanVar(value=False)
self._command = command
self._coin = self.H - 6
self.bind("<Button-1>", self._toggle)
if self._var is not None:
self._var.trace_add("write", lambda *_: self._draw())
self._draw()
def _toggle(self, _event=None):
self._var.set(not self._var.get())
if self._command:
self._command()
def _draw(self):
self.delete("all")
on = bool(self._var.get())
y0 = (self.H - self._coin) / 2
x0 = self.W - self._coin - 5 if on else 5
track = self.TRACK_ON if on else self.TRACK
edge = self.EDGE_ON if on else self.EDGE
coin = self.ON if on else self.OFF
r = 8
self.create_polygon(
1 + r, 1, self.W - 1 - r, 1,
self.W - 1, 1 + r, self.W - 1, self.H - 1 - r,
self.W - 1 - r, self.H - 1, 1 + r, self.H - 1,
1, self.H - 1 - r, 1, 1 + r,
fill=track, outline=edge, width=2, smooth=True)
self.create_oval(x0, y0, x0 + self._coin, y0 + self._coin,
fill=coin, outline=edge, width=2)
c = self._coin / 2
self.create_oval(x0 + c - 2.5, y0 + c - 3.5, x0 + c + 2.5, y0 + c + 0.5,
fill=edge, outline="")
self.create_oval(x0 + c - 2.5, y0 + c + 1.5, x0 + c + 2.5, y0 + c + 5.5,
fill=edge, outline="")
def config_ttk_styles():
_build_fonts()
style = ttk.Style()
try:
style.theme_use("clam")
except tk.TclError:
available = style.theme_names()
for preferred in ("clam", "alt", "default"):
if preferred in available:
style.theme_use(preferred)
break
style.configure(".", font=F["default"], background=C["bg"])
style.configure("TFrame", background=C["bg"])
style.configure("TLabelframe", background=C["bg"], bordercolor=C["border"], relief="solid")
style.configure("TLabelframe.Label", background=C["bg"], foreground=C["text"], font=F["heading"])
style.configure("TLabel", background=C["bg"], foreground=C["text"])
style.configure("Result.TLabel", background=C["bg"], foreground=C["result_fg"], font=F["small_heading"])
style.configure("GroupId.TLabel", background=C["bg"], foreground=C["group_id_fg"], font=F["small"])
style.configure("Token.TLabel", background=C["bg"], foreground=C["text_muted"], font=F["small"])
style.configure("Api.TLabel", foreground="white", background=C["badge_api_bg"], font=F["badge"], anchor="center")
style.configure("Na.TLabel", foreground="white", background=C["badge_na_bg"], font=F["badge"], anchor="center")
style.configure("TEntry", fieldbackground=C["input_bg"], foreground=C["text"], bordercolor=C["input_border"])
style.map("TEntry", bordercolor=[("focus", C["primary"])])
style.configure("TCheckbutton", background=C["bg"], foreground=C["text"])
style.map("TCheckbutton", background=[("active", C["bg"])])
style.configure("TSpinbox", fieldbackground=C["input_bg"], foreground=C["text"], bordercolor=C["input_border"])
tree_size = F["default"].cget("size")
style.configure("Treeview", rowheight=max(tree_size + 14, 24),
font=F["default"], background=C["input_bg"], foreground=C["text"],
fieldbackground=C["input_bg"])
style.configure("Treeview.Heading", font=F["small_heading"])
style.configure("Primary.TButton", background=C["primary"], foreground="white", bordercolor=C["primary"], padding=(12, 4))
style.map("Primary.TButton",
background=[("active", C["primary_hover"]), ("pressed", C["primary_hover"]), ("disabled", C["border"])],
foreground=[("disabled", "#ffffff")])
style.configure("Success.TButton", background=C["success"], foreground="white", bordercolor=C["success"], padding=(12, 4))
style.map("Success.TButton",
background=[("active", C["success_hover"]), ("pressed", C["success_hover"]), ("disabled", C["border"])],
foreground=[("disabled", "#ffffff")])
style.configure("Danger.TButton", background=C["danger"], foreground="white", bordercolor=C["danger"], padding=(12, 4))
style.map("Danger.TButton",
background=[("active", C["danger_hover"]), ("pressed", C["danger_hover"]), ("disabled", C["border"])],
foreground=[("disabled", "#ffffff")])
style.configure("Outline.TButton", background=C["card"], foreground=C["text"], bordercolor=C["border"], padding=(8, 4))
style.map("Outline.TButton",
background=[("active", C["bg"]), ("pressed", C["bg"])])
return style