-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathui_elements.py
More file actions
2741 lines (2347 loc) · 92 KB
/
ui_elements.py
File metadata and controls
2741 lines (2347 loc) · 92 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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import tkinter as tk
from tkinter import ttk, scrolledtext, filedialog, messagebox
import tkinter.font as tkfont
import sys
import os
from typing import Optional, Callable, Dict, Any, Union, TYPE_CHECKING
if TYPE_CHECKING:
from tkinter import _ButtonCommand
else:
_ButtonCommand = Any
# =============================================================================
# PREMIUM UI DESIGN SYSTEM - MODERN & SCALABLE
# =============================================================================
# --- Enhanced Color Palette ---
class Colors:
# Premium Brand Colors - Modern gradient-friendly palette
PRIMARY = "#6366F1" # Indigo - Premium, professional
PRIMARY_HOVER = "#4F46E5" # Darker indigo for hover
PRIMARY_ACTIVE = "#4338CA" # Even darker for active state
PRIMARY_LIGHT = "#A5B4FC" # Light indigo for accents
PRIMARY_GHOST = "#E0E7FF" # Light indigo instead of transparent
# Semantic Colors
SUCCESS = "#10B981" # Emerald green
SUCCESS_HOVER = "#059669" # Darker emerald
SUCCESS_LIGHT = "#A7F3D0" # Light emerald
WARNING = "#F59E0B" # Amber
WARNING_HOVER = "#D97706" # Darker amber
WARNING_LIGHT = "#FDE68A" # Light amber
ERROR = "#EF4444" # Red
ERROR_HOVER = "#DC2626" # Darker red
ERROR_LIGHT = "#FECACA" # Light red
INFO = "#3B82F6" # Blue
INFO_HOVER = "#2563EB" # Darker blue
INFO_LIGHT = "#BFDBFE" # Light blue
# Premium Background System
BG_PRIMARY = "#FAFBFC" # Primary background - slightly off-white
BG_SECONDARY = "#F7F9FB" # Secondary background
BG_TERTIARY = "#F1F4F7" # Tertiary background
BG_CARD = "#FFFFFF" # Card backgrounds
BG_ELEVATED = "#FFFFFF" # Elevated surfaces
# Glass/Blur Effects (simulated with lighter colors)
GLASS_PRIMARY = "#F8F9FA" # Light gray instead of transparent white
GLASS_SECONDARY = "#F1F3F4" # Slightly darker gray
# Premium Surface Colors
SURFACE_DEFAULT = "#FFFFFF"
SURFACE_HOVER = "#F8FAFC"
SURFACE_ACTIVE = "#F1F5F9"
SURFACE_DISABLED = "#F8FAFC"
# Professional Text Hierarchy
TEXT_PRIMARY = "#1E293B" # Very dark slate
TEXT_SECONDARY = "#475569" # Medium slate
TEXT_TERTIARY = "#64748B" # Light slate
TEXT_MUTED = "#94A3B8" # Very light slate
TEXT_INVERSE = "#FFFFFF" # White text
TEXT_ACCENT = "#6366F1" # Brand color text
# Sophisticated Border System
BORDER_SUBTLE = "#F1F5F9" # Very light borders
BORDER_DEFAULT = "#E2E8F0" # Default borders
BORDER_STRONG = "#CBD5E1" # Strong borders
BORDER_ACCENT = "#6366F1" # Accent borders
# Professional Shadow System (using gray colors since tkinter doesn't support alpha)
SHADOW_SM = "#F1F5F9" # Very light gray
SHADOW_MD = "#E2E8F0" # Light gray
SHADOW_LG = "#CBD5E1" # Medium gray
SHADOW_XL = "#94A3B8" # Darker gray
# Gradient Colors for Premium Effects
GRADIENT_PRIMARY = ["#6366F1", "#8B5CF6"] # Indigo to purple
GRADIENT_SUCCESS = ["#10B981", "#059669"] # Emerald gradient
GRADIENT_SUNSET = ["#F59E0B", "#EF4444"] # Warm gradient
GRADIENT_OCEAN = ["#06B6D4", "#3B82F6"] # Cool gradient
# --- Professional Typography System ---
class Typography:
# Premium Font Stack
PRIMARY_FONT = "Inter" # Primary UI font
HEADING_FONT = "SF Pro Display" # For headings (fallback to primary)
MONO_FONT = "SF Mono" # Monospace font
# Comprehensive Size Scale
XXS = 9 # Tiny text
XS = 10 # Extra small
SM = 11 # Small
BASE = 12 # Base size
MD = 13 # Medium
LG = 14 # Large
XL = 16 # Extra large
XXL = 18 # Double extra large
XXXL = 20 # Triple extra large
H4 = 22 # Heading 4
H3 = 24 # Heading 3
H2 = 28 # Heading 2
H1 = 32 # Heading 1
DISPLAY = 36 # Display text
# Professional Font Weights (tkinter-compatible)
THIN = "normal"
EXTRALIGHT = "normal"
LIGHT = "normal"
NORMAL = "normal"
MEDIUM = "normal"
SEMIBOLD = "bold"
BOLD = "bold"
EXTRABOLD = "bold"
BLACK = "bold"
# --- Advanced Spacing System ---
class Spacing:
# Micro spacing
XXS = 2
XS = 4
SM = 6
# Standard spacing
MD = 8
LG = 12
XL = 16
XXL = 20
XXXL = 24
# Large spacing
GIANT = 32
HUGE = 40
MASSIVE = 48
# Component-specific spacing
BUTTON_PADDING_X = 16
BUTTON_PADDING_Y = 8
CARD_PADDING = 20
SECTION_MARGIN = 24
# --- Animation & Effects System ---
class Effects:
# Timing functions
FAST = 150 # Quick interactions
NORMAL = 250 # Standard transitions
SLOW = 350 # Deliberate animations
# Easing curves (for future CSS-like transitions)
EASE_IN = "ease-in"
EASE_OUT = "ease-out"
EASE_IN_OUT = "ease-in-out"
# Shadow definitions
SHADOW_NONE = "none"
SHADOW_SM = "0 1px 2px rgba(0, 0, 0, 0.05)"
SHADOW_MD = "0 4px 6px rgba(0, 0, 0, 0.1)"
SHADOW_LG = "0 10px 15px rgba(0, 0, 0, 0.1)"
SHADOW_XL = "0 20px 25px rgba(0, 0, 0, 0.15)"
# Border radius for modern rounded corners
RADIUS_NONE = 0
RADIUS_SM = 3
RADIUS_MD = 6
RADIUS_LG = 8
RADIUS_XL = 12
RADIUS_FULL = 9999
# --- Icon System (Unicode/Text-based for cross-platform compatibility) ---
class Icons:
# Navigation
ARROW_LEFT = "←"
ARROW_RIGHT = "→"
ARROW_UP = "↑"
ARROW_DOWN = "↓"
# Actions
PLAY = "▶"
PAUSE = "⏸"
STOP = "⏹"
REFRESH = "↻"
DOWNLOAD = "⬇"
UPLOAD = "⬆"
SYNC = "⟲"
# Status
SUCCESS = "✓"
ERROR = "✗"
WARNING = "⚠"
INFO = "ℹ"
# Files & Folders
FOLDER = "📁"
FILE = "📄"
GEAR = "⚙"
KEY = "🔑"
LINK = "🔗"
# Security & Tools
SECURITY = "🔒"
COPY = "📋"
# Interface
MENU = "☰"
CLOSE = "✕"
MINIMIZE = "−"
MAXIMIZE = "□"
# =============================================================================
# ADVANCED UI COMPONENT SYSTEM
# =============================================================================
# Global font configuration
FONT_FAMILY_PRIMARY = "TkDefaultFont"
FONT_FAMILY_MONO = "TkFixedFont"
def get_premium_font_family():
"""Gets the best available font for a premium look."""
try:
available_fonts = tkfont.families()
# Premium font preferences by platform
if sys.platform == "win32":
preferred = ["Segoe UI Variable", "Segoe UI", "Calibri"]
elif sys.platform == "darwin": # macOS
preferred = ["SF Pro Display", "Helvetica Neue", "Lucida Grande"]
else: # Linux
preferred = ["Inter", "Roboto", "Noto Sans", "Ubuntu", "Cantarell", "DejaVu Sans"]
for font in preferred:
if font in available_fonts:
return font
return "TkDefaultFont"
except Exception:
return "TkDefaultFont"
def get_premium_mono_font():
"""Gets the best available monospace font."""
try:
available_fonts = tkfont.families()
if sys.platform == "win32":
preferred = ["Consolas", "Courier New"]
elif sys.platform == "darwin":
preferred = ["SF Mono", "Menlo", "Monaco"]
else:
preferred = ["JetBrains Mono", "Fira Code", "Ubuntu Mono", "DejaVu Sans Mono"]
for font in preferred:
if font in available_fonts:
return font
return "TkFixedFont"
except Exception:
return "TkFixedFont"
def init_font_config():
"""Initializes premium font configuration."""
global FONT_FAMILY_PRIMARY, FONT_FAMILY_MONO
FONT_FAMILY_PRIMARY = get_premium_font_family()
FONT_FAMILY_MONO = get_premium_mono_font()
# =============================================================================
# PREMIUM COMPONENT LIBRARY
# =============================================================================
class PremiumButton:
"""Enhanced button component with hover effects and styling options."""
@staticmethod
def create_primary(parent, text: str, command: Optional[Callable[[], Any]] = None, icon: Optional[str] = None, size: str = "md"):
"""Creates a primary button with premium styling."""
btn_frame = tk.Frame(parent, bg=Colors.BG_PRIMARY)
# Size configurations
sizes = {
"sm": {"font_size": Typography.SM, "pad_x": 12, "pad_y": 6, "min_width": 60},
"md": {"font_size": Typography.MD, "pad_x": 16, "pad_y": 8, "min_width": 80},
"lg": {"font_size": Typography.LG, "pad_x": 20, "pad_y": 10, "min_width": 100}
}
size_config = sizes.get(size, sizes["md"])
# Create button text with optional icon
button_text = f"{icon} {text}" if icon else text
btn = tk.Button(
btn_frame,
text=button_text,
command=command if command is not None else lambda: None,
font=(FONT_FAMILY_PRIMARY, size_config["font_size"], Typography.MEDIUM),
bg=Colors.PRIMARY,
fg=Colors.TEXT_INVERSE,
activebackground=Colors.PRIMARY_HOVER,
activeforeground=Colors.TEXT_INVERSE,
relief=tk.FLAT,
borderwidth=0,
cursor="hand2",
padx=size_config["pad_x"],
pady=size_config["pad_y"],
width=10, # Set minimum width in characters
height=2 # Set minimum height in text lines
)
# Add hover effects
def on_enter(e):
btn.config(bg=Colors.PRIMARY_HOVER)
def on_leave(e):
btn.config(bg=Colors.PRIMARY)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
btn.pack(fill=tk.BOTH, expand=True)
# Use a custom attribute container to avoid Pylance warnings
setattr(btn_frame, '_button', btn)
return btn_frame
@staticmethod
def create_secondary(parent, text: str, command: Optional[Callable[[], Any]] = None, icon: Optional[str] = None, size: str = "md"):
"""Creates a secondary button with outline styling."""
btn_frame = tk.Frame(parent, bg=Colors.BG_PRIMARY)
sizes = {
"sm": {"font_size": Typography.SM, "pad_x": 12, "pad_y": 6, "min_width": 60},
"md": {"font_size": Typography.MD, "pad_x": 16, "pad_y": 8, "min_width": 80},
"lg": {"font_size": Typography.LG, "pad_x": 20, "pad_y": 10, "min_width": 100}
}
size_config = sizes.get(size, sizes["md"])
button_text = f"{icon} {text}" if icon else text
btn = tk.Button(
btn_frame,
text=button_text,
command=command if command is not None else lambda: None,
font=(FONT_FAMILY_PRIMARY, size_config["font_size"], Typography.MEDIUM),
bg=Colors.BG_CARD,
fg=Colors.TEXT_ACCENT,
activebackground=Colors.SURFACE_HOVER,
activeforeground=Colors.PRIMARY_HOVER,
relief=tk.SOLID,
borderwidth=1,
cursor="hand2",
padx=size_config["pad_x"],
pady=size_config["pad_y"],
width=10, # Set minimum width in characters
height=2 # Set minimum height in text lines
)
def on_enter(e):
btn.config(bg=Colors.SURFACE_HOVER, fg=Colors.PRIMARY_HOVER, relief=tk.SOLID)
def on_leave(e):
btn.config(bg=Colors.BG_CARD, fg=Colors.TEXT_ACCENT, relief=tk.SOLID)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
btn.pack(fill=tk.BOTH, expand=True)
# Use a custom attribute container to avoid Pylance warnings
setattr(btn_frame, '_button', btn)
return btn_frame
@staticmethod
def create_success(parent, text: str, command: Optional[Callable[[], Any]] = None, icon: Optional[str] = None, size: str = "md"):
"""Creates a success button with success styling."""
btn_frame = tk.Frame(parent, bg=Colors.BG_PRIMARY)
sizes = {
"sm": {"font_size": Typography.SM, "pad_x": 12, "pad_y": 6},
"md": {"font_size": Typography.MD, "pad_x": 16, "pad_y": 8},
"lg": {"font_size": Typography.LG, "pad_x": 20, "pad_y": 10}
}
size_config = sizes.get(size, sizes["md"])
button_text = f"{icon} {text}" if icon else text
btn = tk.Button(
btn_frame,
text=button_text,
command=command if command is not None else lambda: None,
font=(FONT_FAMILY_PRIMARY, size_config["font_size"], Typography.MEDIUM),
bg=Colors.SUCCESS,
fg=Colors.TEXT_INVERSE,
activebackground=Colors.SUCCESS_HOVER,
activeforeground=Colors.TEXT_INVERSE,
relief=tk.FLAT,
borderwidth=0,
cursor="hand2",
padx=size_config["pad_x"],
pady=size_config["pad_y"]
)
def on_enter(e):
btn.config(bg=Colors.SUCCESS_HOVER)
def on_leave(e):
btn.config(bg=Colors.SUCCESS)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
btn.pack(fill=tk.BOTH, expand=True)
setattr(btn_frame, '_button', btn)
return btn_frame
@staticmethod
def create_danger(parent, text: str, command: Optional[Callable[[], Any]] = None, icon: Optional[str] = None, size: str = "md"):
"""Creates a danger button with error styling."""
btn_frame = tk.Frame(parent, bg=Colors.BG_PRIMARY)
sizes = {
"sm": {"font_size": Typography.SM, "pad_x": 12, "pad_y": 6},
"md": {"font_size": Typography.MD, "pad_x": 16, "pad_y": 8},
"lg": {"font_size": Typography.LG, "pad_x": 20, "pad_y": 10}
}
size_config = sizes.get(size, sizes["md"])
button_text = f"{icon} {text}" if icon else text
btn = tk.Button(
btn_frame,
text=button_text,
command=command if command is not None else lambda: None,
font=(FONT_FAMILY_PRIMARY, size_config["font_size"], Typography.MEDIUM),
bg=Colors.ERROR,
fg=Colors.TEXT_INVERSE,
activebackground=Colors.ERROR_HOVER,
activeforeground=Colors.TEXT_INVERSE,
relief=tk.FLAT,
borderwidth=0,
cursor="hand2",
padx=size_config["pad_x"],
pady=size_config["pad_y"]
)
def on_enter(e):
btn.config(bg=Colors.ERROR_HOVER)
def on_leave(e):
btn.config(bg=Colors.ERROR)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
btn.pack(fill=tk.BOTH, expand=True)
setattr(btn_frame, '_button', btn)
return btn_frame
@staticmethod
def create_warning(parent, text: str, command: Optional[Callable[[], Any]] = None, icon: Optional[str] = None, size: str = "md"):
"""Creates a warning button with warning styling."""
btn_frame = tk.Frame(parent, bg=Colors.BG_PRIMARY)
sizes = {
"sm": {"font_size": Typography.SM, "pad_x": 12, "pad_y": 6},
"md": {"font_size": Typography.MD, "pad_x": 16, "pad_y": 8},
"lg": {"font_size": Typography.LG, "pad_x": 20, "pad_y": 10}
}
size_config = sizes.get(size, sizes["md"])
button_text = f"{icon} {text}" if icon else text
btn = tk.Button(
btn_frame,
text=button_text,
command=command if command is not None else lambda: None,
font=(FONT_FAMILY_PRIMARY, size_config["font_size"], Typography.MEDIUM),
bg=Colors.WARNING,
fg=Colors.TEXT_INVERSE,
activebackground=Colors.WARNING_HOVER,
activeforeground=Colors.TEXT_INVERSE,
relief=tk.FLAT,
borderwidth=0,
cursor="hand2",
padx=size_config["pad_x"],
pady=size_config["pad_y"]
)
def on_enter(e):
btn.config(bg=Colors.WARNING_HOVER)
def on_leave(e):
btn.config(bg=Colors.WARNING)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
btn.pack(fill=tk.BOTH, expand=True)
setattr(btn_frame, '_button', btn)
return btn_frame
class PremiumCard:
"""Card component with elevated styling and shadows."""
@staticmethod
def create(parent, title=None, padding=Spacing.CARD_PADDING):
"""Creates a premium card container."""
# Outer frame for shadow effect (simulation)
shadow_frame = tk.Frame(parent, bg=Colors.SHADOW_MD, height=2)
shadow_frame.pack(fill=tk.X, padx=(2, 0), pady=(2, 0))
# Main card frame
card_frame = tk.Frame(
parent,
bg=Colors.BG_CARD,
relief=tk.FLAT,
borderwidth=1
)
card_frame.pack(fill=tk.BOTH, expand=True, padx=(0, 2), pady=(0, 2))
# Inner content frame with padding
content_frame = tk.Frame(card_frame, bg=Colors.BG_CARD)
content_frame.pack(fill=tk.BOTH, expand=True, padx=padding, pady=padding)
# Optional title
if title:
title_label = tk.Label(
content_frame,
text=title,
font=(FONT_FAMILY_PRIMARY, Typography.LG, Typography.SEMIBOLD),
bg=Colors.BG_CARD,
fg=Colors.TEXT_PRIMARY
)
title_label.pack(anchor=tk.W, pady=(0, Spacing.MD))
return content_frame
class PremiumDialog:
"""Enhanced dialog system with modern styling."""
@staticmethod
def create_base(parent, title, width=400, height=300, resizable=True):
"""Creates a base dialog with premium styling."""
dialog = tk.Toplevel(parent)
dialog.title(title)
dialog.transient(parent)
dialog.grab_set()
dialog.resizable(resizable, resizable) # Allow resizing by default
dialog.configure(bg=Colors.BG_PRIMARY)
# Set minimum size to prevent content from being cut off
dialog.minsize(min(width, 350), min(height, 200))
# Center the dialog
dialog.update_idletasks()
x = (dialog.winfo_screenwidth() // 2) - (width // 2)
y = (dialog.winfo_screenheight() // 2) - (height // 2)
dialog.geometry(f"{width}x{height}+{x}+{y}")
# Ensure dialog appears on top and gets focus (Windows Z-order fix)
dialog.update()
dialog.lift()
dialog.focus_force()
dialog.attributes('-topmost', True) # Temporarily make topmost
dialog.after(100, lambda: dialog.attributes('-topmost', False)) # Remove topmost after showing
# Main container with padding
main_frame = tk.Frame(dialog, bg=Colors.BG_PRIMARY)
main_frame.pack(fill=tk.BOTH, expand=True, padx=Spacing.XL, pady=Spacing.XL)
return dialog, main_frame
# --- Premium Styling System ---
def setup_premium_styles():
"""Configures advanced TTK styles for premium appearance."""
style = ttk.Style()
# Select the best available theme
available_themes = style.theme_names()
preferred_themes = ['vista', 'clam', 'alt', 'default']
selected_theme = None
for theme in preferred_themes:
if theme in available_themes:
selected_theme = theme
break
if selected_theme:
try:
style.theme_use(selected_theme)
except tk.TclError:
style.theme_use('default')
# Premium Frame Styling
style.configure(
"Premium.TFrame",
background=Colors.BG_CARD,
relief="flat",
borderwidth=0
)
style.configure(
"Card.TFrame",
background=Colors.BG_CARD,
relief="solid",
borderwidth=1,
lightcolor=Colors.BORDER_SUBTLE,
darkcolor=Colors.BORDER_SUBTLE
)
# Premium Label Styling
style.configure(
"Premium.TLabel",
font=(FONT_FAMILY_PRIMARY, Typography.BASE, Typography.NORMAL),
background=Colors.BG_CARD,
foreground=Colors.TEXT_PRIMARY
)
style.configure(
"Heading.TLabel",
font=(FONT_FAMILY_PRIMARY, Typography.XL, Typography.SEMIBOLD),
background=Colors.BG_CARD,
foreground=Colors.TEXT_PRIMARY
)
style.configure(
"Title.TLabel",
font=(FONT_FAMILY_PRIMARY, Typography.XXL, Typography.BOLD),
background=Colors.BG_CARD,
foreground=Colors.TEXT_PRIMARY
)
style.configure(
"Subtitle.TLabel",
font=(FONT_FAMILY_PRIMARY, Typography.LG, Typography.MEDIUM),
background=Colors.BG_CARD,
foreground=Colors.TEXT_SECONDARY
)
style.configure(
"Caption.TLabel",
font=(FONT_FAMILY_PRIMARY, Typography.SM, Typography.NORMAL),
background=Colors.BG_CARD,
foreground=Colors.TEXT_MUTED
)
# Premium Button Styling
style.configure(
"Premium.TButton",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.MEDIUM),
padding=(Spacing.BUTTON_PADDING_X, Spacing.BUTTON_PADDING_Y),
background=Colors.PRIMARY,
foreground=Colors.TEXT_INVERSE,
borderwidth=0,
focuscolor="none"
)
style.map(
"Premium.TButton",
background=[
("active", Colors.PRIMARY_HOVER),
("pressed", Colors.PRIMARY_ACTIVE)
],
foreground=[
("active", Colors.TEXT_INVERSE),
("pressed", Colors.TEXT_INVERSE)
]
)
# Success Button
style.configure(
"Success.TButton",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.MEDIUM),
padding=(Spacing.BUTTON_PADDING_X, Spacing.BUTTON_PADDING_Y),
background=Colors.SUCCESS,
foreground=Colors.TEXT_INVERSE,
borderwidth=0,
focuscolor="none"
)
style.map(
"Success.TButton",
background=[("active", Colors.SUCCESS_HOVER)]
)
# Secondary/Outline Button
style.configure(
"Secondary.TButton",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.MEDIUM),
padding=(Spacing.BUTTON_PADDING_X, Spacing.BUTTON_PADDING_Y),
background=Colors.BG_CARD,
foreground=Colors.TEXT_ACCENT,
borderwidth=1,
relief="solid",
focuscolor="none"
)
style.map(
"Secondary.TButton",
background=[
("active", Colors.SURFACE_HOVER),
("pressed", Colors.SURFACE_ACTIVE)
]
)
# Danger Button
style.configure(
"Danger.TButton",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.MEDIUM),
padding=(Spacing.BUTTON_PADDING_X, Spacing.BUTTON_PADDING_Y),
background=Colors.ERROR,
foreground=Colors.TEXT_INVERSE,
borderwidth=0,
focuscolor="none"
)
style.map(
"Danger.TButton",
background=[("active", Colors.ERROR_HOVER)]
)
# Premium LabelFrame
style.configure(
"Premium.TLabelframe",
background=Colors.BG_CARD,
borderwidth=1,
relief="solid",
lightcolor=Colors.BORDER_DEFAULT,
darkcolor=Colors.BORDER_DEFAULT
)
style.configure(
"Premium.TLabelframe.Label",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.SEMIBOLD),
background=Colors.BG_CARD,
foreground=Colors.TEXT_PRIMARY
)
# Premium Progressbar
style.configure(
"Premium.Horizontal.TProgressbar",
background=Colors.PRIMARY,
troughcolor=Colors.BG_TERTIARY,
borderwidth=0,
lightcolor=Colors.PRIMARY,
darkcolor=Colors.PRIMARY
)
# =============================================================================
# ENHANCED WINDOW CREATION FUNCTIONS
# =============================================================================
def create_premium_main_window():
"""Creates the main application window with premium styling."""
root = tk.Tk()
root.title("Ogresync")
root.geometry("800x600")
root.configure(bg=Colors.BG_PRIMARY)
root.minsize(600, 400)
# Set window icon with enhanced fallback support
try:
# Check if we're running from PyInstaller bundle
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# Try different icon files in order of preference
icon_files = ["new_logo_1.ico", "ogrelix_logo.ico", "new_logo_1.png", "logo.png"]
icon_path = None
for icon_file in icon_files:
test_path = os.path.join(sys._MEIPASS, "assets", icon_file) # type: ignore
if os.path.exists(test_path):
icon_path = test_path
break
else:
# Development mode - check local assets folder
icon_files = ["new_logo_1.ico", "ogrelix_logo.ico", "new_logo_1.png", "logo.png"]
icon_path = None
for icon_file in icon_files:
test_path = os.path.join("assets", icon_file)
if os.path.exists(test_path):
icon_path = test_path
break
if icon_path:
if icon_path.endswith('.ico'):
# Use iconbitmap for .ico files (works better on Windows)
root.iconbitmap(icon_path)
else:
# Use iconphoto for .png files
img = tk.PhotoImage(file=icon_path)
root.iconphoto(True, img)
except Exception:
pass # Fallback to default icon if loading fails
# Initialize fonts and styles
init_font_config()
setup_premium_styles()
# Create main container with premium styling
main_container = tk.Frame(root, bg=Colors.BG_PRIMARY)
main_container.pack(fill=tk.BOTH, expand=True, padx=Spacing.XL, pady=Spacing.LG)
# Header section with title and subtitle
header_frame = tk.Frame(main_container, bg=Colors.BG_PRIMARY)
header_frame.pack(fill=tk.X, pady=(0, Spacing.XL))
# App title
title_label = tk.Label(
header_frame,
text="Ogresync",
font=(FONT_FAMILY_PRIMARY, Typography.H2, Typography.BOLD),
bg=Colors.BG_PRIMARY,
fg=Colors.TEXT_PRIMARY
)
title_label.pack(anchor=tk.W)
# Subtitle
subtitle_label = tk.Label(
header_frame,
text="Obsidian Vault Synchronization",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.NORMAL),
bg=Colors.BG_PRIMARY,
fg=Colors.TEXT_SECONDARY
)
subtitle_label.pack(anchor=tk.W, pady=(2, 0))
# Main content area using PremiumCard
content_card = PremiumCard.create(main_container, padding=Spacing.XL)
# Activity log section
log_header = tk.Label(
content_card,
text=f"{Icons.FILE} Activity Log",
font=(FONT_FAMILY_PRIMARY, Typography.LG, Typography.SEMIBOLD),
bg=Colors.BG_CARD,
fg=Colors.TEXT_PRIMARY
)
log_header.pack(anchor=tk.W, pady=(0, Spacing.SM))
# Log text widget with premium styling
log_frame = tk.Frame(content_card, bg=Colors.BG_CARD)
log_frame.pack(fill=tk.BOTH, expand=True, pady=(0, Spacing.LG))
log_text_widget = scrolledtext.ScrolledText(
log_frame,
wrap=tk.WORD,
height=15,
state='disabled',
font=(FONT_FAMILY_MONO, Typography.SM),
bg=Colors.BG_SECONDARY,
fg=Colors.TEXT_PRIMARY,
insertbackground=Colors.TEXT_PRIMARY,
selectbackground=Colors.PRIMARY_LIGHT,
selectforeground=Colors.TEXT_PRIMARY,
relief=tk.FLAT,
borderwidth=1,
highlightthickness=1,
highlightcolor=Colors.BORDER_ACCENT,
highlightbackground=Colors.BORDER_DEFAULT
)
log_text_widget.pack(fill=tk.BOTH, expand=True)
# Progress section
progress_header = tk.Label(
content_card,
text=f"{Icons.SYNC} Progress",
font=(FONT_FAMILY_PRIMARY, Typography.MD, Typography.MEDIUM),
bg=Colors.BG_CARD,
fg=Colors.TEXT_PRIMARY
)
progress_header.pack(anchor=tk.W, pady=(0, Spacing.XS))
# Progress bar with premium styling
progress_frame = tk.Frame(content_card, bg=Colors.BG_CARD)
progress_frame.pack(fill=tk.X, pady=(0, Spacing.SM))
progress_bar_widget = ttk.Progressbar(
progress_frame,
style="Premium.Horizontal.TProgressbar",
orient="horizontal",
length=400,
mode="determinate"
)
progress_bar_widget.pack(fill=tk.X)
return root, log_text_widget, progress_bar_widget
# Enhanced conflict resolution dialog with premium styling
def create_premium_conflict_dialog(parent_window, conflict_files_text):
"""Creates a beautifully styled conflict resolution dialog."""
dialog, main_frame = PremiumDialog.create_base(
parent_window,
"Merge Conflict Detected",
width=500,
height=350,
resizable=False
)
# Header with icon and title
header_frame = tk.Frame(main_frame, bg=Colors.BG_PRIMARY)
header_frame.pack(fill=tk.X, pady=(0, Spacing.LG))
# Warning icon and title
title_frame = tk.Frame(header_frame, bg=Colors.BG_PRIMARY)
title_frame.pack(fill=tk.X)
icon_label = tk.Label(
title_frame,
text=Icons.WARNING,
font=(FONT_FAMILY_PRIMARY, Typography.H3),
bg=Colors.BG_PRIMARY,
fg=Colors.WARNING
)
icon_label.pack(side=tk.LEFT, padx=(0, Spacing.SM))
title_label = tk.Label(
title_frame,
text="Merge Conflict Detected",
font=(FONT_FAMILY_PRIMARY, Typography.XL, Typography.SEMIBOLD),
bg=Colors.BG_PRIMARY,
fg=Colors.TEXT_PRIMARY
)
title_label.pack(side=tk.LEFT, anchor=tk.W)
# Content card
content_card = PremiumCard.create(main_frame, padding=Spacing.LG)
# Message text
message_text = (
f"Conflicts were found in the following files:\n\n"
f"{conflict_files_text}\n\n"
f"Please choose how you'd like to resolve these conflicts:"
)
message_label = tk.Label(
content_card,
text=message_text,
font=(FONT_FAMILY_PRIMARY, Typography.MD),
bg=Colors.BG_CARD,
fg=Colors.TEXT_SECONDARY,
justify=tk.LEFT,
wraplength=420
)
message_label.pack(pady=(0, Spacing.LG), anchor=tk.W)
# Resolution choice storage
resolution = {"choice": None}
def set_choice(choice):
resolution["choice"] = choice
dialog.destroy()
# Action buttons with premium styling
button_frame = tk.Frame(content_card, bg=Colors.BG_CARD)
button_frame.pack(fill=tk.X, pady=(Spacing.MD, 0))
# Create premium buttons
btn_local = PremiumButton.create_secondary(
button_frame,
"Keep Local",
lambda: set_choice("ours"),
Icons.DOWNLOAD
)
btn_local.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, Spacing.SM))
btn_remote = PremiumButton.create_secondary(
button_frame,
"Keep Remote",
lambda: set_choice("theirs"),
Icons.UPLOAD
)
btn_remote.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(Spacing.SM, Spacing.SM))
btn_manual = PremiumButton.create_primary(
button_frame,
"Merge Manually",
lambda: set_choice("manual"),
Icons.GEAR
)
btn_manual.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(Spacing.SM, 0))
# Wait for user choice
parent_window.wait_window(dialog)
return resolution["choice"]
# Enhanced minimal UI for auto-sync with premium styling
def create_premium_minimal_ui(auto_run=False):
"""Creates a minimal UI with premium styling for auto-sync mode."""
root = tk.Tk()
root.title("Ogresync")
root.geometry("600x400")
root.configure(bg=Colors.BG_PRIMARY)
root.resizable(False, False)
# Set window icon with enhanced fallback support
try:
# Check if we're running from PyInstaller bundle
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# Try different icon files in order of preference
icon_files = ["new_logo_1.ico", "ogrelix_logo.ico", "new_logo_1.png", "logo.png"]
icon_path = None
for icon_file in icon_files:
test_path = os.path.join(sys._MEIPASS, "assets", icon_file) # type: ignore
if os.path.exists(test_path):
icon_path = test_path
break