Skip to content

Commit f75dce2

Browse files
committed
Refactor stylesheet to use dynamic properties for state management
Added a theme section so we can easily change values. Removed inline styles.
1 parent 0078410 commit f75dce2

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _create_input_section(self):
431431

432432
row = QHBoxLayout()
433433
self.input_label = QLabel("No file selected")
434-
self.input_label.setStyleSheet("color: #888888; padding: 5px;")
434+
self.input_label.setProperty("labelState", "inactive")
435435
self.input_label.setWordWrap(True)
436436
row.addWidget(self.input_label, 1)
437437

@@ -443,7 +443,7 @@ def _create_input_section(self):
443443
layout.addLayout(row)
444444

445445
self.page_info_label = QLabel("")
446-
self.page_info_label.setStyleSheet("color: #aaaaaa; font-size: 10pt;")
446+
self.page_info_label.setObjectName("pageInfoLabel")
447447
layout.addWidget(self.page_info_label)
448448

449449
group.setLayout(layout)
@@ -478,7 +478,7 @@ def _create_page_section(self):
478478
layout.addWidget(self.page_entry)
479479

480480
self.help_label = QLabel(self.current_mode.help_text)
481-
self.help_label.setStyleSheet("color: #aaaaaa; font-size: 9pt;")
481+
self.help_label.setObjectName("helpLabel")
482482
layout.addWidget(self.help_label)
483483

484484
group.setLayout(layout)
@@ -497,7 +497,7 @@ def _create_output_section(self):
497497

498498
row = QHBoxLayout()
499499
self.output_label = QLabel("No output location selected")
500-
self.output_label.setStyleSheet("color: #888888; padding: 5px;")
500+
self.output_label.setProperty("labelState", "inactive")
501501
self.output_label.setWordWrap(True)
502502
row.addWidget(self.output_label, 1)
503503

@@ -514,8 +514,18 @@ def _update_label(self, label, text, active=False):
514514
"""Update a label with truncated text and appropriate styling."""
515515
display_text = text if len(text) < 80 else f"...{text[-77:]}"
516516
label.setText(display_text)
517-
color = "#ffffff" if active else "#888888"
518-
label.setStyleSheet(f"color: {color}; padding: 5px;")
517+
# Use dynamic property instead of inline styles
518+
label.setProperty("labelState", "active" if active else "inactive")
519+
# Force style refresh
520+
label.style().unpolish(label)
521+
label.style().polish(label)
522+
523+
def _set_label_state(self, label, state):
524+
"""Set a label's state property and refresh styling."""
525+
label.setProperty("labelState", state)
526+
if style := label.style():
527+
style.unpolish(label)
528+
style.polish(label)
519529

520530
def _get_base_name(self):
521531
"""Get base filename from input path."""
@@ -615,7 +625,7 @@ def process_pdf(self):
615625
return
616626

617627
self.status_label.setText("Processing...")
618-
self.status_label.setStyleSheet("color: #aaaaaa;")
628+
self._set_label_state(self.status_label, "processing")
619629
QApplication.processEvents()
620630

621631
try:
@@ -641,7 +651,7 @@ def process_pdf(self):
641651

642652
except Exception as e:
643653
self.status_label.setText("Failed")
644-
self.status_label.setStyleSheet("color: #f44336;")
654+
self._set_label_state(self.status_label, "error")
645655
QMessageBox.critical(self, "Error", str(e))
646656

647657
def _confirm_overwrite(self):
@@ -656,7 +666,7 @@ def _confirm_overwrite(self):
656666
def _show_success(self, message):
657667
"""Display success message."""
658668
self.status_label.setText(f"Success! Saved to: {self.output_folder}")
659-
self.status_label.setStyleSheet("color: #4caf50;")
669+
self._set_label_state(self.status_label, "success")
660670

661671
# Create custom message box with "Open Folder" button
662672
msg_box = QMessageBox(self)

style.qss

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
1+
/*
2+
* ChiselPDF Dark Theme
3+
*
4+
* Color Palette:
5+
* - Background: #2b2b2b (dark gray)
6+
* - Secondary background: #3c3c3c (medium gray)
7+
* - Border: #555555 (light gray)
8+
* - Text primary: #ffffff (white)
9+
* - Text secondary: #aaaaaa (light gray)
10+
* - Text inactive: #888888 (medium gray)
11+
* - Accent (normal): #1b75d0 (blue)
12+
* - Accent (hover): #155ca1 (darker blue)
13+
* - Accent (pressed): #0c3b6a (darkest blue)
14+
* - Success: #4caf50 (green)
15+
* - Error: #f44336 (red)
16+
*/
17+
18+
/* Base Application Styles */
119
QMainWindow, QWidget {
220
background-color: #2b2b2b;
321
color: #ffffff;
422
}
23+
24+
/* Group Boxes */
525
QGroupBox {
626
border: 1px solid #555555;
727
border-radius: 5px;
828
margin-top: 10px;
929
padding-top: 10px;
1030
font-weight: bold;
1131
}
32+
1233
QGroupBox::title {
1334
subcontrol-origin: margin;
1435
left: 10px;
1536
padding: 0 5px;
1637
}
38+
39+
/* Text Input Fields */
1740
QLineEdit {
1841
background-color: #3c3c3c;
1942
color: #ffffff;
2043
border: 1px solid #555555;
2144
border-radius: 3px;
2245
padding: 5px;
2346
}
47+
48+
/* Buttons */
2449
QPushButton {
2550
background-color: #1b75d0;
2651
color: #ffffff;
@@ -29,26 +54,71 @@ QPushButton {
2954
padding: 8px;
3055
font-weight: bold;
3156
}
57+
3258
QPushButton:hover {
3359
background-color: #155ca1;
3460
}
61+
3562
QPushButton:pressed {
3663
background-color: #0c3b6a;
3764
}
65+
3866
QPushButton:disabled {
3967
background-color: #555555;
4068
color: #888888;
4169
}
70+
71+
/* Radio Buttons */
4272
QRadioButton::indicator {
4373
width: 14px;
4474
height: 14px;
4575
border-radius: 9px;
4676
background-color: #555555;
4777
border: 2px solid #555555;
4878
}
79+
4980
QRadioButton::indicator:checked {
5081
background-color: #1b75d0;
5182
}
83+
5284
QRadioButton::indicator:hover {
5385
border: 2px solid #155ca1;
5486
}
87+
88+
/* Labels - Dynamic States */
89+
QLabel[labelState="inactive"] {
90+
color: #888888;
91+
padding: 5px;
92+
}
93+
94+
QLabel[labelState="active"] {
95+
color: #ffffff;
96+
padding: 5px;
97+
}
98+
99+
QLabel[labelState="info"] {
100+
color: #aaaaaa;
101+
}
102+
103+
QLabel[labelState="processing"] {
104+
color: #aaaaaa;
105+
}
106+
107+
QLabel[labelState="success"] {
108+
color: #4caf50;
109+
}
110+
111+
QLabel[labelState="error"] {
112+
color: #f44336;
113+
}
114+
115+
/* Specific UI Elements */
116+
#pageInfoLabel {
117+
color: #aaaaaa;
118+
font-size: 10pt;
119+
}
120+
121+
#helpLabel {
122+
color: #aaaaaa;
123+
font-size: 9pt;
124+
}

0 commit comments

Comments
 (0)