Repository navigation
Expand file tree
/
Copy paththeme.py
More file actions
775 lines (717 loc) · 26.9 KB
/
Copy paththeme.py
File metadata and controls
775 lines (717 loc) · 26.9 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
"""
theme.py — Centralized theme system for the application.
Provides 4 dark themes (blue, green, red, purple) that can be applied globally
to all windows and buttons via QApplication.setStyleSheet().
The global stylesheet uses class-based selectors (QWidget, QPushButton, etc.).
Per-widget stylesheets set via setStyleSheet() in existing code continue to work
— they override the global theme for the widgets that have them. The theme
provides the BASE look (backgrounds, base text, borders) for everything else.
Public API:
THEMES → dict of all themes
get_theme() → current theme dict
generate_global_stylesheet() → QSS string for the current theme
apply_theme(app) → apply the current theme to a QApplication
refresh_theme() → re-apply the current theme (call after settings change)
"""
import sys
import traceback
# ═══════════════════════ Theme definitions ═══════════════════════
# Each theme defines a coherent dark palette. The structure is identical
# across themes so the generated QSS is consistent.
THEMES = {
"blue": {
"name": "Bleu sombre",
"icon": "🔵",
"bg": "#0F172A",
"bg_alt": "#1E293B",
"bg_card": "#1E293B",
"bg_input": "#0F172A",
"border": "#334155",
"border_hover": "#475569",
"accent": "#3b82f6",
"accent_hover": "#2563eb",
"accent_pressed": "#1d4ed8",
"accent_text": "#60a5fa",
"text": "#E2E8F0",
"text_dim": "#94A3B8",
"text_muted": "#64748b",
"success": "#22c55e",
"warning": "#f59e0b",
"danger": "#ef4444",
},
"green": {
"name": "Vert sombre",
"icon": "🟢",
"bg": "#0a1f12",
"bg_alt": "#0f2918",
"bg_card": "#0f2918",
"bg_input": "#0a1f12",
"border": "#1f4d2e",
"border_hover": "#2d6845",
"accent": "#22c55e",
"accent_hover": "#16a34a",
"accent_pressed": "#15803d",
"accent_text": "#4ade80",
"text": "#dcfce7",
"text_dim": "#86efac",
"text_muted": "#4ade80",
"success": "#22c55e",
"warning": "#f59e0b",
"danger": "#ef4444",
},
"red": {
"name": "Rouge sombre",
"icon": "🔴",
"bg": "#1f0a0a",
"bg_alt": "#2a0f0f",
"bg_card": "#2a0f0f",
"bg_input": "#1f0a0a",
"border": "#4d1f1f",
"border_hover": "#682d2d",
"accent": "#ef4444",
"accent_hover": "#dc2626",
"accent_pressed": "#b91c1c",
"accent_text": "#f87171",
"text": "#fee2e2",
"text_dim": "#fca5a5",
"text_muted": "#f87171",
"success": "#22c55e",
"warning": "#f59e0b",
"danger": "#ef4444",
},
"purple": {
"name": "Violet sombre",
"icon": "🟣",
"bg": "#1a0a24",
"bg_alt": "#250f33",
"bg_card": "#250f33",
"bg_input": "#1a0a24",
"border": "#3d1f4d",
"border_hover": "#522d68",
"accent": "#a855f7",
"accent_hover": "#9333ea",
"accent_pressed": "#7e22ce",
"accent_text": "#c084fc",
"text": "#f3e8ff",
"text_dim": "#d8b4fe",
"text_muted": "#c084fc",
"success": "#22c55e",
"warning": "#f59e0b",
"danger": "#ef4444",
},
}
def _log_err(context, error):
"""Log a theme error to stderr + errors_logs.txt + victim logs (debug mode).
Kept independent from helpers.py to avoid circular imports during early startup."""
try:
sys.stderr.write(f"[theme.{context}] {error}\n{traceback.format_exc()}\n")
except Exception:
pass
try:
from helpers import log_error
log_error(f"theme.{context}", error)
except Exception:
pass
# Constante partagée pour la police emoji (utilisée dans tous les btn_style_*)
_EMOJI_FONT = "'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', 'DejaVu Sans', Arial"
def get_theme():
"""Return the current theme dict. Falls back to 'blue' on any error."""
try:
from config import get_theme_color
color_key = get_theme_color()
if color_key not in THEMES:
color_key = "blue"
return THEMES[color_key]
except Exception as e:
_log_err("get_theme", e)
return THEMES["blue"]
def generate_global_stylesheet():
"""Generate the global QSS stylesheet for the current theme.
Uses class-based selectors so per-widget stylesheets still override
individual properties (cascade behavior)."""
try:
t = get_theme()
return f"""
/* ── Base widgets ── */
QWidget {{
background-color: {t['bg']};
color: {t['text']};
font-size: 12px;
}}
QMainWindow, QDialog {{
background-color: {t['bg']};
}}
/* ── Buttons ── */
QPushButton {{
background-color: {t['bg_alt']};
color: {t['text']};
border: 1px solid {t['border']};
border-radius: 6px;
padding: 8px 16px;
font-weight: normal;
}}
QPushButton:hover {{
background-color: {t['border_hover']};
border-color: {t['accent']};
color: {t['accent_text']};
}}
QPushButton:pressed {{
background-color: {t['border']};
}}
QPushButton:disabled {{
background-color: {t['bg_alt']};
color: {t['text_muted']};
border-color: {t['border']};
}}
/* ── Input widgets ── */
QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QDoubleSpinBox {{
background-color: {t['bg_input']};
color: {t['text']};
border: 1px solid {t['border']};
border-radius: 6px;
padding: 8px 10px;
selection-background-color: {t['accent']};
selection-color: white;
}}
QLineEdit:focus, QTextEdit:focus, QPlainTextEdit:focus,
QSpinBox:focus, QDoubleSpinBox:focus {{
border-color: {t['accent']};
}}
QLineEdit:read-only {{
color: {t['text_dim']};
background-color: {t['bg_alt']};
}}
/* ── ComboBox ── */
QComboBox {{
background-color: {t['bg_alt']};
color: {t['text']};
border: 1px solid {t['border']};
border-radius: 6px;
padding: 8px 12px;
min-height: 18px;
}}
QComboBox:hover {{
border-color: {t['accent']};
}}
QComboBox:focus {{
border-color: {t['accent']};
}}
QComboBox::drop-down {{
border: none;
width: 28px;
}}
QComboBox::down-arrow {{
image: none;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid {t['accent_text']};
width: 0;
height: 0;
}}
QComboBox QAbstractItemView {{
background-color: {t['bg']};
color: {t['text']};
border: 1px solid {t['accent']};
border-radius: 6px;
padding: 6px;
outline: none;
selection-background-color: {t['accent']};
selection-color: white;
}}
QComboBox QAbstractItemView::item {{
padding: 8px 14px;
border-radius: 4px;
}}
QComboBox QAbstractItemView::item:hover {{
background-color: {t['bg_alt']};
color: {t['accent_text']};
}}
/* ── GroupBox ── */
QGroupBox {{
background-color: {t['bg_alt']};
border: 1px solid {t['border']};
border-radius: 10px;
margin-top: 14px;
padding: 18px 14px 14px 14px;
font-weight: bold;
font-size: 13px;
color: {t['text_dim']};
}}
QGroupBox::title {{
subcontrol-origin: margin;
subcontrol-position: top left;
padding: 2px 10px;
color: {t['accent']};
}}
/* ── Labels ── */
QLabel {{
color: {t['text']};
background: transparent;
border: none;
}}
/* ── ScrollArea ── */
QScrollArea {{
background-color: {t['bg']};
border: 1px solid {t['border']};
border-radius: 8px;
}}
QScrollBar:vertical {{
background: {t['bg_alt']};
width: 12px;
border-radius: 6px;
}}
QScrollBar::handle:vertical {{
background: {t['border_hover']};
min-height: 30px;
border-radius: 6px;
}}
QScrollBar::handle:vertical:hover {{
background: {t['accent']};
}}
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{
background: none;
border: none;
}}
QScrollBar:horizontal {{
background: {t['bg_alt']};
height: 12px;
border-radius: 6px;
}}
QScrollBar::handle:horizontal {{
background: {t['border_hover']};
min-width: 30px;
border-radius: 6px;
}}
QScrollBar::handle:horizontal:hover {{
background: {t['accent']};
}}
/* ── List widgets ── */
QListWidget {{
background-color: {t['bg_alt']};
color: {t['text']};
border: 1px solid {t['border']};
border-radius: 6px;
padding: 4px;
}}
QListWidget::item {{
background-color: transparent;
border: none;
margin-bottom: 4px;
padding: 4px;
}}
QListWidget::item:hover {{
background-color: {t['bg_input']};
border-radius: 4px;
}}
QListWidget::item:selected {{
background-color: {t['accent']};
color: white;
border-radius: 4px;
}}
/* ── Tabs ── */
QTabWidget::pane {{
border: 1px solid {t['border']};
border-radius: 8px;
background-color: {t['bg']};
top: -1px;
}}
QTabBar::tab {{
background-color: {t['bg_alt']};
color: {t['text_dim']};
padding: 8px 16px;
margin-right: 2px;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
font-weight: 600;
}}
QTabBar::tab:selected {{
background-color: {t['border']};
color: {t['accent_text']};
}}
QTabBar::tab:hover {{
background-color: {t['border_hover']};
color: {t['text']};
}}
/* ── CheckBox & RadioButton ── */
QCheckBox, QRadioButton {{
color: {t['text']};
spacing: 6px;
background: transparent;
border: none;
}}
QCheckBox:hover, QRadioButton:hover {{
color: {t['accent_text']};
}}
QCheckBox::indicator, QRadioButton::indicator {{
width: 16px;
height: 16px;
border: 2px solid {t['border_hover']};
background: {t['bg_input']};
}}
QCheckBox::indicator:checked {{
background: {t['accent']};
border-color: {t['accent']};
}}
QRadioButton::indicator {{
border-radius: 9px;
}}
QRadioButton::indicator:checked {{
background: {t['accent']};
border-color: {t['accent']};
}}
/* ── Menu ── */
QMenu {{
background-color: {t['bg_alt']};
color: {t['text']};
border: 1px solid {t['border']};
border-radius: 6px;
padding: 6px;
}}
QMenu::item {{
padding: 8px 24px;
border-radius: 4px;
}}
QMenu::item:selected {{
background-color: {t['accent']};
color: white;
}}
QMenu::separator {{
height: 1px;
background: {t['border']};
margin: 4px 8px;
}}
/* ── ToolTip ── */
QToolTip {{
background-color: {t['bg_alt']};
color: {t['text']};
border: 1px solid {t['accent']};
border-radius: 4px;
padding: 6px 10px;
}}
/* ── Frame ── */
QFrame {{
background-color: transparent;
border: none;
}}
/* ── StatusBar ── */
QStatusBar {{
background-color: {t['bg_alt']};
color: {t['text_dim']};
border-top: 1px solid {t['border']};
}}
/* ── ProgressBar ── */
QProgressBar {{
background-color: {t['bg_input']};
border: 1px solid {t['border']};
border-radius: 4px;
text-align: center;
color: {t['text']};
}}
QProgressBar::chunk {{
background-color: {t['accent']};
border-radius: 3px;
}}
/* ── Slider ── */
QSlider::groove:horizontal {{
background: {t['bg_input']};
height: 4px;
border-radius: 2px;
}}
QSlider::handle:horizontal {{
background: {t['accent']};
width: 14px;
height: 14px;
margin: -5px 0;
border-radius: 7px;
}}
QSlider::handle:horizontal:hover {{
background: {t['accent_hover']};
}}
/* ── MessageBox ── */
QMessageBox {{
background-color: {t['bg']};
}}
QMessageBox QLabel {{
color: {t['text']};
}}
"""
except Exception as e:
_log_err("generate_global_stylesheet", e)
# Return a minimal stylesheet as fallback
return "QWidget { background-color: #0F172A; color: #E2E8F0; }"
def apply_theme(app):
"""Apply the current theme to a QApplication instance.
Safe to call multiple times — clears and re-applies to force a refresh."""
try:
qss = generate_global_stylesheet()
# Clear first, then re-apply — forces Qt to re-evaluate the stylesheet
# on all widgets (otherwise some widgets keep their old style).
app.setStyleSheet("")
app.setStyleSheet(qss)
except Exception as e:
_log_err("apply_theme", e)
def refresh_theme():
"""Re-apply the current theme. Call this after the theme color changes
in System Settings so all open windows pick up the new look.
Walks all top-level widgets and calls _apply_theme_style() on every window
that defines it. This re-builds each window's stylesheet with the new theme
colors. Also forces a repaint of all ModernToggleSwitch widgets (which use
custom painting and read theme colors at paint time)."""
try:
from PyQt6.QtWidgets import QApplication
app = QApplication.instance()
if app is not None:
apply_theme(app)
# Walk all top-level windows and re-apply their per-window stylesheets
# using the new theme colors. Each window class that has a
# _apply_theme_style() method will rebuild its stylesheet.
try:
for w in app.topLevelWidgets():
_refresh_window_style(w)
except Exception as e:
_log_err("refresh_theme.refresh_windows", e)
# Force every ModernToggleSwitch to repaint (custom paintEvent)
try:
for w in app.topLevelWidgets():
_repaint_toggles(w)
except Exception as e:
_log_err("refresh_theme.repaint_toggles", e)
except Exception as e:
_log_err("refresh_theme", e)
def _refresh_window_style(widget):
"""Recursively walk the widget tree and call _apply_theme_style() on every
widget that defines it. This rebuilds per-window stylesheets with the new
theme colors. Also refreshes publication/ad lists on TargetConfigWindow
so the row colors pick up the new theme."""
try:
# If this widget has _apply_theme_style, call it (re-builds the stylesheet)
if hasattr(widget, "_apply_theme_style") and callable(getattr(widget, "_apply_theme_style")):
try:
widget._apply_theme_style()
except Exception as e:
_log_err(f"_refresh_window_style.apply[{type(widget).__name__}]", e)
# If this widget has refresh_pub_list (TargetConfigWindow), call it
# so the publication rows pick up the new theme colors.
if hasattr(widget, "refresh_pub_list") and callable(getattr(widget, "refresh_pub_list")):
try:
widget.refresh_pub_list()
except Exception as e:
_log_err(f"_refresh_window_style.refresh_pub_list[{type(widget).__name__}]", e)
if hasattr(widget, "refresh_ad_list") and callable(getattr(widget, "refresh_ad_list")):
try:
widget.refresh_ad_list()
except Exception as e:
_log_err(f"_refresh_window_style.refresh_ad_list[{type(widget).__name__}]", e)
# If this widget has rebuild_target_list (PanneauAdmin), call it
if hasattr(widget, "rebuild_target_list") and callable(getattr(widget, "rebuild_target_list")):
try:
widget.rebuild_target_list()
except Exception as e:
_log_err(f"_refresh_window_style.rebuild_target_list[{type(widget).__name__}]", e)
# If this widget has refresh_list (CorbeilleWindow), call it
if hasattr(widget, "refresh_list") and callable(getattr(widget, "refresh_list")):
try:
widget.refresh_list()
except Exception as e:
_log_err(f"_refresh_window_style.refresh_list[{type(widget).__name__}]", e)
# If this widget has refresh (CredentialsWindow), call it
if hasattr(widget, "refresh") and callable(getattr(widget, "refresh")):
try:
widget.refresh()
except Exception as e:
_log_err(f"_refresh_window_style.refresh[{type(widget).__name__}]", e)
# Recurse into children
for child in widget.children():
try:
from PyQt6.QtWidgets import QWidget as _QWidget
if isinstance(child, _QWidget):
_refresh_window_style(child)
except Exception:
pass
except Exception as e:
_log_err("_refresh_window_style", e)
def _repaint_toggles(widget):
"""Recursively walk the widget tree and call update() on every
ModernToggleSwitch so its custom paintEvent re-reads theme colors."""
try:
# Check if this widget is a ModernToggleSwitch (duck-typed to avoid
# an import cycle — toggle_switch.py imports from theme.py indirectly).
if hasattr(widget, "paintEvent") and hasattr(widget, "is_on") and hasattr(widget, "_progress"):
try:
widget.update()
except Exception:
pass
# Recurse into children
for child in widget.children():
try:
# Only recurse into QWidget instances (skip layouts, etc.)
from PyQt6.QtWidgets import QWidget as _QWidget
if isinstance(child, _QWidget):
_repaint_toggles(child)
except Exception:
pass
except Exception as e:
_log_err("_repaint_toggles", e)
def get_available_themes():
"""Return a list of (key, label) tuples for all available themes.
Used by the System Settings UI to populate the theme picker."""
try:
return [(key, f"{t['icon']} {t['name']}") for key, t in THEMES.items()]
except Exception as e:
_log_err("get_available_themes", e)
return [("blue", "🔵 Bleu sombre")]
# ═══════════════════════ Button style helpers ═══════════════════════
# These helpers return QSS strings for individual buttons. They should be
# used in place of hardcoded colors so every button picks up the active theme.
# Semantic colors: "accent" (primary), "success" (green), "warning" (orange),
# "danger" (red). Each maps to the corresponding theme color.
def btn_style_accent():
"""Primary button — fond accent, coins 8px, effet profondeur."""
try:
t = get_theme()
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {t['accent']}; color: white; border: none;
font-weight: normal; border-radius: 8px; padding: 9px 18px;
}}
QPushButton:hover {{ background-color: {t['accent_hover']}; }}
QPushButton:pressed {{ background-color: {t['accent_pressed']}; padding-top: 10px; }}
QPushButton:disabled {{ background-color: {t['bg_alt']}; color: {t.get('text_muted', '#64748b')}; }}
"""
except Exception as e:
_log_err("btn_style_accent", e)
return ""
def btn_style_success():
"""Success button — vert, coins 8px, effet profondeur."""
try:
t = get_theme()
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {t['success']}; color: white; border: none;
font-weight: normal; border-radius: 8px; padding: 10px 18px;
min-height: 20px;
}}
QPushButton:hover {{ background-color: #16a34a; }}
QPushButton:pressed {{ background-color: #15803d; padding-top: 11px; }}
QPushButton:disabled {{ background-color: {t['bg_alt']}; color: {t.get('text_muted', '#64748b')}; }}
"""
except Exception as e:
_log_err("btn_style_success", e)
return ""
def btn_style_warning():
"""Warning button — orange, coins 8px, effet profondeur."""
try:
t = get_theme()
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {t['warning']}; color: white; border: none;
font-weight: normal; border-radius: 8px; padding: 9px 18px;
}}
QPushButton:hover {{ background-color: #d97706; }}
QPushButton:pressed {{ background-color: #b45309; padding-top: 10px; }}
QPushButton:disabled {{ background-color: {t['bg_alt']}; color: {t.get('text_muted', '#64748b')}; }}
"""
except Exception as e:
_log_err("btn_style_warning", e)
return ""
def btn_style_danger():
"""Danger button — rouge, coins 8px, effet profondeur."""
try:
t = get_theme()
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {t['danger']}; color: white; border: none;
font-weight: normal; border-radius: 8px; padding: 9px 18px;
}}
QPushButton:hover {{ background-color: #dc2626; }}
QPushButton:pressed {{ background-color: #b91c1c; padding-top: 10px; }}
QPushButton:disabled {{ background-color: {t['bg_alt']}; color: {t.get('text_muted', '#64748b')}; }}
"""
except Exception as e:
_log_err("btn_style_danger", e)
return ""
def btn_style_neutral():
"""Neutral button — fond bg_alt, bordure subtile, coins 8px."""
try:
t = get_theme()
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {t['bg_alt']}; color: {t['text']}; border: 1px solid {t['border_hover']};
font-weight: normal; border-radius: 8px; padding: 9px 18px;
}}
QPushButton:hover {{ background-color: {t['border']}; border-color: {t['accent']}; color: {t['accent_text']}; }}
QPushButton:pressed {{ background-color: {t['border_hover']}; }}
QPushButton:disabled {{ background-color: {t['bg_alt']}; color: {t.get('text_muted', '#64748b')}; border-color: {t['border']}; }}
"""
except Exception as e:
_log_err("btn_style_neutral", e)
return ""
def btn_style_icon(color_type="accent"):
"""Small icon button (32×32) — coins 6px, police emoji."""
try:
t = get_theme()
color_map = {
"accent": (t['accent'], t['accent_hover'], t['accent_pressed']),
"success": (t['success'], "#16a34a", "#15803d"),
"warning": (t['warning'], "#d97706", "#b45309"),
"danger": (t['danger'], "#dc2626", "#b91c1c"),
"neutral": (t['bg_alt'], t['border_hover'], t['border']),
}
bg, hover, pressed = color_map.get(color_type, color_map["accent"])
text_color = "white" if color_type != "neutral" else t['text']
border = "none" if color_type != "neutral" else f"1px solid {t['border_hover']}"
return f"""
QPushButton {{
font-family: {_EMOJI_FONT};
background-color: {bg}; color: {text_color}; border: {border};
border-radius: 6px; padding: 0px; font-size: 15px; font-weight: normal;
}}
QPushButton:hover {{ background-color: {hover}; }}
QPushButton:pressed {{ background-color: {pressed}; }}
"""
except Exception as e:
_log_err("btn_style_icon", e)
return ""
def list_widget_style():
"""QListWidget style — uses the theme's colors."""
try:
t = get_theme()
return f"""
QListWidget {{
border: 1px solid {t['border']};
border-radius: 6px;
background-color: {t['bg_alt']};
padding: 4px;
}}
QListWidget::item {{
background-color: transparent;
border: none;
margin-bottom: 4px;
}}
QListWidget::item:selected {{
background-color: {t['border']};
border-radius: 6px;
}}
"""
except Exception as e:
_log_err("list_widget_style", e)
return ""
def checkbox_style(color_var="accent"):
"""QCheckBox style — uses the theme's accent or a specified color.
color_var can be: 'accent', 'success', 'warning', 'danger'."""
try:
t = get_theme()
c = t.get(color_var, t['accent'])
return f"""
QCheckBox {{ color: {t['text']}; spacing: 8px; background: transparent; }}
QCheckBox::indicator {{ width: 16px; height: 16px; border-radius: 4px; border: 2px solid {t['border_hover']}; background: {t['bg_input']}; }}
QCheckBox::indicator:checked {{ background: {c}; border: 2px solid {c}; }}
"""
except Exception as e:
_log_err("checkbox_style", e)
return ""