-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.py
More file actions
798 lines (672 loc) · 32.5 KB
/
widgets.py
File metadata and controls
798 lines (672 loc) · 32.5 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
"""Custom UI widgets for SillyLoresmith."""
import tkinter as tk
from tkinter import ttk, scrolledtext
from theme import Theme
class FlatEntry(tk.Entry):
"""Flat entry widget with placeholder support."""
def __init__(self, parent, placeholder="", **kw):
self._mask_char = kw.pop("show", "")
super().__init__(parent,
bg=Theme.BG_INPUT, fg=Theme.FG, insertbackground=Theme.ACCENT,
relief="flat", highlightthickness=1,
highlightbackground=Theme.BORDER, highlightcolor=Theme.ACCENT,
font=Theme.FONT, bd=0, **kw)
self.placeholder = placeholder
self._showing_placeholder = False
if placeholder:
self._show_placeholder()
self.bind("<FocusIn>", self._on_focus_in)
self.bind("<FocusOut>", self._on_focus_out)
def _show_placeholder(self):
if not self.get():
self._showing_placeholder = True
self.configure(fg=Theme.FG_DIM, show="")
self.insert(0, self.placeholder)
def _on_focus_in(self, e):
if self._showing_placeholder:
self.delete(0, tk.END)
self.configure(fg=Theme.FG, show=self._mask_char)
self._showing_placeholder = False
def _on_focus_out(self, e):
if not self.get():
self._show_placeholder()
elif self._mask_char:
self.configure(show=self._mask_char)
def get_value(self):
return "" if self._showing_placeholder else self.get()
def set_value(self, text):
self._showing_placeholder = False
self.delete(0, tk.END)
if text:
self.configure(fg=Theme.FG, show=self._mask_char)
self.insert(0, text)
else:
self._show_placeholder()
class FlatButton(tk.Canvas):
"""Modern flat button widget."""
def __init__(self, parent, text="", command=None, accent=False,
width=140, height=36, **kw):
try:
parent_bg = parent["bg"]
except Exception:
parent_bg = Theme.BG
super().__init__(parent, width=width, height=height,
bg=parent_bg, highlightthickness=0, bd=0, **kw)
self.command = command
self.accent = accent
self._disabled = False
self.bg_normal = Theme.ACCENT if accent else Theme.BG_CARD
self.bg_hover = Theme.ACCENT_DIM if accent else Theme.BG_HOVER
self.fg_color = Theme.BG if accent else Theme.FG
self._bg = self.bg_normal
self._text = text
self._draw()
self.bind("<Enter>", self._on_enter)
self.bind("<Leave>", self._on_leave)
self.bind("<ButtonPress-1>", self._on_click)
def _draw(self):
self.delete("all")
w, h = self.winfo_reqwidth(), self.winfo_reqheight()
r = 6
self._round_rect(2, 2, w-2, h-2, r, fill=self._bg,
outline=Theme.BORDER if not self.accent else "")
self.create_text(w//2, h//2, text=self._text, fill=self.fg_color,
font=Theme.FONT)
def _round_rect(self, x1, y1, x2, y2, r, **kw):
pts = [x1+r, y1, x2-r, y1, x2, y1, x2, y1+r, x2, y2-r, x2, y2,
x2-r, y2, x1+r, y2, x1, y2, x1, y2-r, x1, y1+r, x1, y1]
self.create_polygon(pts, smooth=True, **kw)
def _on_enter(self, e):
if not self._disabled:
self._bg = self.bg_hover
self._draw()
def _on_leave(self, e):
if not self._disabled:
self._bg = self.bg_normal
self._draw()
def _on_click(self, e):
if not self._disabled and self.command:
self.command()
def set_disabled(self, val):
self._disabled = val
self._bg = Theme.BORDER if val else self.bg_normal
self.fg_color = Theme.FG_DIM if val else (Theme.BG if self.accent else Theme.FG)
self._draw()
def set_text(self, text):
self._text = text
self._draw()
class OutlineButton(tk.Label):
"""Compact outline/pill button for utility actions. Much lighter than FlatButton."""
def __init__(self, parent, text="", command=None, accent=False,
padx=10, pady=3, **kw):
fg = Theme.ACCENT if accent else Theme.FG
super().__init__(parent, text=text, font=Theme.FONT_SM,
bg=Theme.BG_CARD, fg=fg, padx=padx, pady=pady,
cursor="hand2",
highlightbackground=Theme.BORDER if not accent else Theme.ACCENT,
highlightthickness=1, relief="flat", bd=0)
self.command = command
self._accent = accent
self._fg = fg
self._text = text
self.bind("<Enter>", self._on_enter)
self.bind("<Leave>", self._on_leave)
self.bind("<ButtonPress-1>", self._on_click)
def _on_enter(self, e):
self.configure(bg=Theme.ACCENT if self._accent else Theme.BG_HOVER,
fg=Theme.BG if self._accent else Theme.FG_BRIGHT)
def _on_leave(self, e):
self.configure(bg=Theme.BG_CARD, fg=self._fg)
def _on_click(self, e):
if self.command:
self.command()
def set_text(self, text):
self._text = text
self.configure(text=text)
class Card(tk.Frame):
def __init__(self, parent, **kw):
super().__init__(parent, bg=Theme.BG_CARD,
highlightbackground=Theme.BORDER,
highlightthickness=1, bd=0, **kw)
class CollapsibleSection(tk.Frame):
def __init__(self, parent, title, initially_open=True, **kw):
super().__init__(parent, bg=Theme.BG_CARD, **kw)
self._open = initially_open
self.header = tk.Frame(self, bg=Theme.BG_HOVER, cursor="hand2")
self.header.pack(fill="x")
self.arrow_var = tk.StringVar(value="▼" if initially_open else "▶")
self.arrow = tk.Label(self.header, textvariable=self.arrow_var,
font=Theme.FONT_SM, bg=Theme.BG_HOVER, fg=Theme.FG_DIM)
self.arrow.pack(side="left", padx=(8, 4), pady=6)
self.title_label = tk.Label(self.header, text=title,
font=("Segoe UI", 10, "bold"),
bg=Theme.BG_HOVER, fg=Theme.ACCENT)
self.title_label.pack(side="left", pady=6)
self.header.bind("<Button-1>", self.toggle)
self.arrow.bind("<Button-1>", self.toggle)
self.title_label.bind("<Button-1>", self.toggle)
self.content = tk.Frame(self, bg=Theme.BG_CARD)
if initially_open:
self.content.pack(fill="both", expand=True, padx=8, pady=(0, 8))
def toggle(self, e=None):
self._open = not self._open
if self._open:
self.arrow_var.set("▼")
self.content.pack(fill="both", expand=True, padx=8, pady=(0, 8))
else:
self.arrow_var.set("▶")
self.content.pack_forget()
class StatusLogPanel(tk.Frame):
def __init__(self, parent, status_log, **kw):
super().__init__(parent, bg=Theme.BG_CARD, **kw)
self.status_log = status_log
header = tk.Frame(self, bg=Theme.BG_CARD)
header.pack(fill="x", padx=8, pady=(8, 4))
tk.Label(header, text="📋 Status Log", font=Theme.FONT_SM,
bg=Theme.BG_CARD, fg=Theme.FG_DIM).pack(side="left")
clear_btn = tk.Label(header, text="Clear", font=Theme.FONT_XS,
bg=Theme.BG_CARD, fg=Theme.ACCENT, cursor="hand2")
clear_btn.pack(side="right")
clear_btn.bind("<Button-1>", lambda e: self._clear())
log_frame = tk.Frame(self, bg=Theme.BG_INPUT, bd=0, highlightthickness=0)
log_frame.pack(fill="both", expand=True, padx=8, pady=(0, 8))
self.log_text = tk.Text(
log_frame, wrap="word", font=Theme.FONT_MONO, height=6,
bg=Theme.BG_INPUT, fg=Theme.FG, state="disabled",
relief="flat", bd=0, highlightthickness=0)
log_scroll = ttk.Scrollbar(log_frame, orient="vertical",
command=self.log_text.yview,
style="Vertical.TScrollbar")
self.log_text.configure(yscrollcommand=log_scroll.set)
self.log_text.pack(side="left", fill="both", expand=True)
log_scroll.pack(side="right", fill="y")
self.log_text.tag_configure("info", foreground=Theme.FG)
self.log_text.tag_configure("warn", foreground=Theme.WARNING)
self.log_text.tag_configure("error", foreground=Theme.ERROR)
self.log_text.tag_configure("success", foreground=Theme.SUCCESS)
status_log.add_listener(self._on_log_entry)
def _on_log_entry(self, entry):
self.log_text.configure(state="normal")
line = f"[{entry['timestamp']}] {entry['message']}\n"
self.log_text.insert(tk.END, line, entry['level'])
self.log_text.see(tk.END)
self.log_text.configure(state="disabled")
def _clear(self):
self.status_log.clear()
self.log_text.configure(state="normal")
self.log_text.delete("1.0", tk.END)
self.log_text.configure(state="disabled")
class ThemedProgressBar(tk.Canvas):
"""Progress bar that matches the theme accent color."""
def __init__(self, parent, width=300, height=24, **kw):
try:
parent_bg = parent["bg"]
except Exception:
parent_bg = Theme.BG
super().__init__(parent, width=width, height=height,
bg=parent_bg, highlightthickness=0, bd=0, **kw)
self._progress = 0.0
self._text = ""
self._width = width
self._height = height
self._draw()
def _draw(self):
self.delete("all")
w, h = self._width, self._height
r = h // 2
self._round_rect(0, 0, w, h, r, fill=Theme.BG_INPUT, outline=Theme.BORDER)
if self._progress > 0:
fill_w = max(h, int(w * self._progress))
self._round_rect(0, 0, fill_w, h, r, fill=Theme.ACCENT, outline="")
display_text = self._text or f"{int(self._progress * 100)}%"
self.create_text(w // 2, h // 2, text=display_text,
fill=Theme.FG_BRIGHT, font=Theme.FONT_SM)
def _round_rect(self, x1, y1, x2, y2, r, **kw):
pts = [x1+r, y1, x2-r, y1, x2, y1, x2, y1+r, x2, y2-r, x2, y2,
x2-r, y2, x1+r, y2, x1, y2, x1, y2-r, x1, y1+r, x1, y1]
self.create_polygon(pts, smooth=True, **kw)
def set_progress(self, value, text=""):
self._progress = max(0.0, min(1.0, value))
self._text = text
self._draw()
def reset(self):
self._progress = 0.0
self._text = ""
self._draw()
class FilterSearchBar(tk.Frame):
"""Search bar with filter icon dropdown for field/sort options."""
def __init__(self, parent, on_change=None, show_sort=True,
filter_options=None, sort_options=None, **kw):
super().__init__(parent, bg=Theme.BG_CARD, **kw)
self.on_change = on_change
self._filter_options = filter_options or ["All", "Name", "Content"]
self._sort_options = sort_options or [
"Alphabetical A-Z", "Alphabetical Z-A",
"Token Health: High→Low", "Token Health: Low→High"
]
self._show_sort = show_sort
self.filter_btn = tk.Label(self, text="⚙", font=("Segoe UI", 12),
bg=Theme.BG_INPUT, fg=Theme.FG_DIM,
cursor="hand2", padx=6, pady=2,
highlightbackground=Theme.BORDER, highlightthickness=1)
self.filter_btn.pack(side="left")
self.filter_btn.bind("<Button-1>", self._show_filter_menu)
self.search_entry = FlatEntry(self, placeholder="🔍 Search...", width=20)
self.search_entry.pack(side="left", fill="x", expand=True, padx=(2, 0))
self.search_entry.bind("<KeyRelease>", lambda e: self._fire_change())
self.filter_var = tk.StringVar(value="All")
self.sort_var = tk.StringVar(value="Alphabetical A-Z")
def _show_filter_menu(self, event=None):
menu = tk.Menu(self, tearoff=0, bg=Theme.BG_CARD, fg=Theme.FG,
activebackground=Theme.ACCENT, activeforeground=Theme.BG,
font=Theme.FONT_SM, relief="flat", bd=1)
menu.add_command(label="── Filter By ──", state="disabled")
for opt in self._filter_options:
check = " ✓" if self.filter_var.get() == opt else " "
menu.add_command(label=f"{check} {opt}",
command=lambda o=opt: self._set_filter(o))
if self._show_sort:
menu.add_separator()
menu.add_command(label="── Sort By ──", state="disabled")
for opt in self._sort_options:
check = " ✓" if self.sort_var.get() == opt else " "
menu.add_command(label=f"{check} {opt}",
command=lambda o=opt: self._set_sort(o))
x = self.filter_btn.winfo_rootx()
y = self.filter_btn.winfo_rooty() + self.filter_btn.winfo_height()
menu.post(x, y)
def _set_filter(self, value):
self.filter_var.set(value)
self._fire_change()
def _set_sort(self, value):
self.sort_var.set(value)
self._fire_change()
def _fire_change(self):
if self.on_change:
self.on_change()
def get_search(self):
return self.search_entry.get_value()
def get_filter(self):
return self.filter_var.get()
def get_sort(self):
return self.sort_var.get()
class TutorialOverlay:
"""Interactive tutorial with Quick and Advanced modes.
Quick mode: Brief overview cards centered on screen.
Advanced mode: Step-by-step walkthrough that switches tabs,
points arrows at UI elements, and guides in depth.
"""
def __init__(self, root, steps=None, on_switch_tab=None, advanced_steps=None, on_finish=None):
self.root = root
self.steps = steps or []
self.advanced_steps = advanced_steps or []
self.current_step = 0
self.popup = None
self.overlay = None
self.arrow_canvas = None
self.on_switch_tab = on_switch_tab # callback: switch_tab(tab_id)
self.on_finish = on_finish # callback: called when tutorial ends
self._mode = None
def start(self):
"""Show mode selection dialog."""
self._show_mode_choice()
def _show_mode_choice(self):
"""Show Quick vs Advanced tutorial choice."""
if self.popup:
self.popup.destroy()
self.popup = tk.Toplevel(self.root)
self.popup.overrideredirect(True)
self.popup.configure(bg=Theme.BG_CARD)
self.popup.attributes("-topmost", True)
w, h = 500, 370
root_x = self.root.winfo_rootx()
root_y = self.root.winfo_rooty()
root_w = self.root.winfo_width()
root_h = self.root.winfo_height()
x = root_x + (root_w - w) // 2
y = root_y + (root_h - h) // 2
self.popup.geometry(f"{w}x{h}+{x}+{y}")
border = tk.Frame(self.popup, bg=Theme.ACCENT, padx=2, pady=2)
border.pack(fill="both", expand=True)
inner = tk.Frame(border, bg=Theme.BG_CARD)
inner.pack(fill="both", expand=True)
tk.Label(inner, text="📚 Welcome to SillyLoresmith!",
font=("Segoe UI", 14, "bold"), bg=Theme.BG_CARD, fg=Theme.FG_BRIGHT
).pack(pady=(20, 4))
tk.Label(inner, text="How would you like to learn the ropes?",
font=Theme.FONT, bg=Theme.BG_CARD, fg=Theme.FG_DIM
).pack(pady=(0, 16))
# Quick mode card
quick_frame = tk.Frame(inner, bg=Theme.BG_INPUT, padx=12, pady=10,
highlightbackground=Theme.BORDER, highlightthickness=1)
quick_frame.pack(fill="x", padx=24, pady=(0, 8))
quick_frame.configure(cursor="hand2")
tk.Label(quick_frame, text="⚡ Quick Tour", font=("Segoe UI", 11, "bold"),
bg=Theme.BG_INPUT, fg=Theme.ACCENT).pack(anchor="w")
tk.Label(quick_frame, text="Brief overview of each feature - about 1 minute.",
font=Theme.FONT_SM, bg=Theme.BG_INPUT, fg=Theme.FG_DIM, wraplength=380).pack(anchor="w")
for widget in [quick_frame] + quick_frame.winfo_children():
widget.bind("<Button-1>", lambda e: self._start_mode("quick"))
widget.bind("<Enter>", lambda e: quick_frame.configure(highlightbackground=Theme.ACCENT))
widget.bind("<Leave>", lambda e: quick_frame.configure(highlightbackground=Theme.BORDER))
# Advanced mode card
adv_frame = tk.Frame(inner, bg=Theme.BG_INPUT, padx=12, pady=10,
highlightbackground=Theme.BORDER, highlightthickness=1)
adv_frame.pack(fill="x", padx=24, pady=(0, 8))
adv_frame.configure(cursor="hand2")
tk.Label(adv_frame, text="🎓 In-Depth Walkthrough", font=("Segoe UI", 11, "bold"),
bg=Theme.BG_INPUT, fg=Theme.ACCENT).pack(anchor="w")
tk.Label(adv_frame, text="Step-by-step guided tour with tab switching - about 5 minutes.",
font=Theme.FONT_SM, bg=Theme.BG_INPUT, fg=Theme.FG_DIM, wraplength=380).pack(anchor="w")
for widget in [adv_frame] + adv_frame.winfo_children():
widget.bind("<Button-1>", lambda e: self._start_mode("advanced"))
widget.bind("<Enter>", lambda e: adv_frame.configure(highlightbackground=Theme.ACCENT))
widget.bind("<Leave>", lambda e: adv_frame.configure(highlightbackground=Theme.BORDER))
# Skip
skip_lbl = tk.Label(inner, text="Skip tutorial", font=Theme.FONT_SM,
bg=Theme.BG_CARD, fg=Theme.FG_DIM, cursor="hand2")
skip_lbl.pack(pady=(8, 12))
skip_lbl.bind("<Button-1>", lambda e: self._finish())
skip_lbl.bind("<Enter>", lambda e: skip_lbl.configure(fg=Theme.ACCENT))
skip_lbl.bind("<Leave>", lambda e: skip_lbl.configure(fg=Theme.FG_DIM))
def _start_mode(self, mode):
"""Begin the selected tutorial mode."""
self._mode = mode
self.current_step = 0
if mode == "quick":
self._active_steps = self.steps
else:
self._active_steps = self.advanced_steps if self.advanced_steps else self.steps
self._show_step()
def _show_step(self):
if self.current_step >= len(self._active_steps):
self._finish()
return
step = self._active_steps[self.current_step]
# Switch tab if specified
tab_id = step.get("tab")
if tab_id and self.on_switch_tab:
try:
self.on_switch_tab(tab_id)
self.root.update_idletasks()
except Exception:
pass
if self.popup:
self.popup.destroy()
if self.arrow_canvas:
self.arrow_canvas.destroy()
self.arrow_canvas = None
self.popup = tk.Toplevel(self.root)
self.popup.overrideredirect(True)
self.popup.configure(bg=Theme.BG_CARD)
self.popup.attributes("-topmost", True)
w = 480 # fixed width, height auto-calculated
# Build card content FIRST, then position
border = tk.Frame(self.popup, bg=Theme.ACCENT, padx=2, pady=2)
border.pack(fill="both", expand=True)
inner = tk.Frame(border, bg=Theme.BG_CARD)
inner.pack(fill="both", expand=True)
# Category + step indicator
header = tk.Frame(inner, bg=Theme.BG_CARD)
header.pack(fill="x", padx=16, pady=(12, 0))
category = step.get("category", "")
if category:
tk.Label(header, text=category, font=Theme.FONT_XS,
bg=Theme.BG_CARD, fg=Theme.ACCENT).pack(side="left")
total = len(self._active_steps)
current = self.current_step + 1
mode_tag = "⚡ Quick" if self._mode == "quick" else "🎓 Advanced"
tk.Label(header, text=f"{mode_tag} • {current}/{total}", font=Theme.FONT_XS,
bg=Theme.BG_CARD, fg=Theme.FG_DIM).pack(side="right")
# Title
tk.Label(inner, text=step.get("title", ""), font=("Segoe UI", 12, "bold"),
bg=Theme.BG_CARD, fg=Theme.FG_BRIGHT).pack(anchor="w", padx=16, pady=(6, 4))
# Description
tk.Label(inner, text=step.get("description", ""), font=Theme.FONT,
bg=Theme.BG_CARD, fg=Theme.FG, wraplength=420,
justify="left").pack(anchor="w", padx=16, pady=(0, 4), fill="x")
# Tip text
tip = step.get("tip", "")
if tip:
tip_frame = tk.Frame(inner, bg=Theme.BG_HOVER)
tip_frame.pack(fill="x", padx=16, pady=(2, 0))
tk.Label(tip_frame, text=f"💡 {tip}", font=Theme.FONT_XS,
bg=Theme.BG_HOVER, fg=Theme.WARNING, wraplength=400,
justify="left").pack(padx=8, pady=4)
# Navigation
nav = tk.Frame(inner, bg=Theme.BG_CARD)
nav.pack(fill="x", padx=16, pady=(8, 12), side="bottom")
# Progress dots
dots_frame = tk.Frame(nav, bg=Theme.BG_CARD)
dots_frame.pack(side="left")
max_dots = min(total, 20) # Show max 20 dots
for i in range(max_dots):
color = Theme.ACCENT if i == self.current_step else Theme.BORDER
tk.Canvas(dots_frame, width=8, height=8, bg=Theme.BG_CARD,
highlightthickness=0).pack(side="left", padx=1)
c = dots_frame.winfo_children()[-1]
c.create_oval(1, 1, 7, 7, fill=color, outline="")
# Buttons
if self.current_step < len(self._active_steps) - 1:
next_btn = FlatButton(nav, text="Next →", width=80, height=28,
accent=True, command=self._next)
next_btn.pack(side="right", padx=(4, 0))
else:
done_btn = FlatButton(nav, text="Done! ✓", width=90, height=28,
accent=True, command=self._finish)
done_btn.pack(side="right", padx=(4, 0))
if self.current_step > 0:
back_btn = FlatButton(nav, text="← Back", width=80, height=28,
command=self._prev)
back_btn.pack(side="right", padx=(0, 4))
skip_btn = FlatButton(nav, text="Skip All", width=72, height=28,
command=self._finish)
skip_btn.pack(side="right")
# Auto-calculate height after content is built
self.popup.update_idletasks()
h = self.popup.winfo_reqheight()
h = max(h + 20, 220) # add padding + minimum height
# Now position the popup
root_x = self.root.winfo_rootx()
root_y = self.root.winfo_rooty()
root_w = self.root.winfo_width()
root_h = self.root.winfo_height()
target = step.get("target")
arrow_dir = step.get("arrow_dir", "none")
if target and hasattr(target, 'winfo_rootx'):
try:
target.update_idletasks()
tx = target.winfo_rootx()
ty = target.winfo_rooty()
tw = target.winfo_width()
th = target.winfo_height()
if arrow_dir == "up":
px = tx + tw // 2 - w // 2
py = ty + th + 20
elif arrow_dir == "down":
px = tx + tw // 2 - w // 2
py = ty - h - 20
elif arrow_dir == "left":
px = tx + tw + 20
py = ty + th // 2 - h // 2
elif arrow_dir == "right":
px = tx - w - 20
py = ty + th // 2 - h // 2
else:
px = tx + tw // 2 - w // 2
py = ty + th + 15
px = max(root_x + 10, min(px, root_x + root_w - w - 10))
py = max(root_y + 10, min(py, root_y + root_h - h - 10))
self.popup.geometry(f"{w}x{h}+{px}+{py}")
self._draw_arrow(px, py, w, h, tx, ty, tw, th, arrow_dir)
except Exception:
x = root_x + (root_w - w) // 2
y = root_y + (root_h - h) // 2
self.popup.geometry(f"{w}x{h}+{x}+{y}")
else:
x = root_x + (root_w - w) // 2
y = root_y + (root_h - h) // 2
self.popup.geometry(f"{w}x{h}+{x}+{y}")
def _draw_arrow(self, px, py, pw, ph, tx, ty, tw, th, arrow_dir):
"""Draw an arrow on a transparent canvas pointing from popup to target."""
try:
self.arrow_canvas = tk.Toplevel(self.root)
self.arrow_canvas.overrideredirect(True)
self.arrow_canvas.attributes("-topmost", True)
# Compute arrow start (popup edge) and end (target center)
target_cx = tx + tw // 2
target_cy = ty + th // 2
if arrow_dir == "up":
# Arrow points up from popup top to target bottom
ax1, ay1 = px + pw // 2, py # popup top center
ax2, ay2 = target_cx, ty + th # target bottom center
elif arrow_dir == "down":
ax1, ay1 = px + pw // 2, py + ph
ax2, ay2 = target_cx, ty
elif arrow_dir == "left":
ax1, ay1 = px, py + ph // 2
ax2, ay2 = tx + tw, target_cy
elif arrow_dir == "right":
ax1, ay1 = px + pw, py + ph // 2
ax2, ay2 = tx, target_cy
else:
self.arrow_canvas.destroy()
self.arrow_canvas = None
return
# Canvas bounds
cx = min(ax1, ax2) - 10
cy = min(ay1, ay2) - 10
cw = abs(ax2 - ax1) + 20
ch = abs(ay2 - ay1) + 20
self.arrow_canvas.geometry(f"{cw}x{ch}+{cx}+{cy}")
# Use a transparent bg trick - match BG color
canvas = tk.Canvas(self.arrow_canvas, width=cw, height=ch,
bg=Theme.BG, highlightthickness=0)
canvas.pack()
# Try to make transparent (Windows)
try:
self.arrow_canvas.attributes("-transparentcolor", Theme.BG)
except Exception:
pass
# Draw arrow line
lx1, ly1 = ax1 - cx, ay1 - cy
lx2, ly2 = ax2 - cx, ay2 - cy
canvas.create_line(lx1, ly1, lx2, ly2,
fill=Theme.ACCENT, width=3, arrow="last",
arrowshape=(12, 14, 5))
except Exception:
if self.arrow_canvas:
self.arrow_canvas.destroy()
self.arrow_canvas = None
def _next(self):
self.current_step += 1
self._show_step()
def _prev(self):
self.current_step = max(0, self.current_step - 1)
self._show_step()
def _finish(self):
if self.popup:
self.popup.destroy()
self.popup = None
if self.arrow_canvas:
self.arrow_canvas.destroy()
self.arrow_canvas = None
if self.on_finish:
try:
self.on_finish()
except Exception:
pass
def style_combobox(cb, root):
style = ttk.Style()
style.theme_use("clam")
style.configure("Dark.TCombobox",
fieldbackground=Theme.BG_INPUT, background=Theme.BG_INPUT,
foreground=Theme.FG, arrowcolor=Theme.ACCENT,
bordercolor=Theme.BORDER)
style.map("Dark.TCombobox",
fieldbackground=[("readonly", Theme.BG_INPUT)],
foreground=[("readonly", Theme.FG)])
cb.configure(style="Dark.TCombobox")
root.option_add("*TCombobox*Listbox.background", Theme.BG_INPUT)
root.option_add("*TCombobox*Listbox.foreground", Theme.FG)
def setup_scrollbar_style():
style = ttk.Style()
style.theme_use("clam")
style.configure("Vertical.TScrollbar",
background=Theme.BG_HOVER, troughcolor=Theme.BG_INPUT,
bordercolor=Theme.BG_INPUT, arrowcolor=Theme.FG_DIM,
relief="flat", borderwidth=0, width=10)
style.map("Vertical.TScrollbar",
background=[("active", Theme.ACCENT_DIM), ("pressed", Theme.ACCENT)])
style.configure("Horizontal.TScrollbar",
background=Theme.BG_HOVER, troughcolor=Theme.BG_INPUT,
bordercolor=Theme.BG_INPUT, arrowcolor=Theme.FG_DIM,
relief="flat", borderwidth=0, width=10)
style.map("Horizontal.TScrollbar",
background=[("active", Theme.ACCENT_DIM), ("pressed", Theme.ACCENT)])
style.configure("Dark.Vertical.TScrollbar",
background=Theme.BG_HOVER, troughcolor=Theme.BG_INPUT,
bordercolor=Theme.BG_INPUT, arrowcolor=Theme.FG_DIM,
borderwidth=0, width=10)
style.map("Dark.Vertical.TScrollbar",
background=[("active", Theme.ACCENT_DIM), ("pressed", Theme.ACCENT)])
style.configure("Dark.Treeview",
background=Theme.BG_INPUT, foreground=Theme.FG,
fieldbackground=Theme.BG_INPUT, bordercolor=Theme.BORDER)
style.map("Dark.Treeview",
background=[("selected", Theme.ACCENT)], foreground=[("selected", Theme.BG)])
style.configure("Treeview",
background=Theme.BG_INPUT, foreground=Theme.FG,
fieldbackground=Theme.BG_INPUT, borderwidth=0, relief="flat")
style.map("Treeview",
background=[("selected", Theme.ACCENT)], foreground=[("selected", Theme.BG)])
style.configure("Treeview.Heading",
background=Theme.BG_CARD, foreground=Theme.FG_DIM, borderwidth=0, relief="flat")
style.map("Treeview.Heading", background=[("active", Theme.BG_HOVER)])
style.configure("TCombobox",
fieldbackground=Theme.BG_INPUT, background=Theme.BG_HOVER,
foreground=Theme.FG, arrowcolor=Theme.FG_DIM, bordercolor=Theme.BORDER)
style.map("TCombobox",
fieldbackground=[("readonly", Theme.BG_INPUT)],
foreground=[("readonly", Theme.FG)],
background=[("active", Theme.ACCENT_DIM)])
class DarkScrolledText(tk.Frame):
def __init__(self, parent, wrap="word", font=None, bg=None, fg=None,
insertbackground=None, height=15, state=None, **kw):
super().__init__(parent, bg=bg or Theme.BG_INPUT, bd=0, highlightthickness=0)
self.text = tk.Text(self, wrap=wrap, font=font or Theme.FONT,
bg=bg or Theme.BG_INPUT, fg=fg or Theme.FG,
insertbackground=insertbackground or Theme.ACCENT,
height=height, relief="flat", bd=0,
highlightthickness=0, undo=True, **kw)
self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.text.yview,
style="Vertical.TScrollbar")
self.text.configure(yscrollcommand=self.scrollbar.set)
self.text.pack(side="left", fill="both", expand=True)
self.scrollbar.pack(side="right", fill="y")
if state:
self.text.configure(state=state)
def insert(self, *args, **kw): return self.text.insert(*args, **kw)
def delete(self, *args, **kw): return self.text.delete(*args, **kw)
def get(self, *args, **kw): return self.text.get(*args, **kw)
def configure(self, **kw):
text_keys = {"state", "wrap", "font", "bg", "fg", "insertbackground", "height"}
text_kw = {k: v for k, v in kw.items() if k in text_keys}
frame_kw = {k: v for k, v in kw.items() if k not in text_keys}
if text_kw: self.text.configure(**text_kw)
if frame_kw: super().configure(**frame_kw)
config = configure
def bind(self, *args, **kw): return self.text.bind(*args, **kw)
def tag_configure(self, *args, **kw): return self.text.tag_configure(*args, **kw)
def tag_add(self, *args, **kw): return self.text.tag_add(*args, **kw)
def see(self, *args, **kw): return self.text.see(*args, **kw)
def index(self, *args, **kw): return self.text.index(*args, **kw)
def center_window(win, parent, w, h):
win.update_idletasks()
parent_x = parent.winfo_x()
parent_y = parent.winfo_y()
parent_w = parent.winfo_width()
parent_h = parent.winfo_height()
x = parent_x + (parent_w - w) // 2
y = parent_y + (parent_h - h) // 2
win.geometry(f"{w}x{h}+{x}+{y}")