Skip to content

Commit

Permalink
refactor(ui): update styles and improve metadata handling
Browse files Browse the repository at this point in the history
- Remove hardcoded color values from stylesheet
- Fix typos and formatting issues in stylesheet
- Improve handling of save_metadata_checkbox to prevent null
  pointer exceptions
- Add warning messages for debugging purposes
  • Loading branch information
rtuszik committed Aug 22, 2024
1 parent 32feff9 commit e7dc8ad
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions FluxLoraGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ def __init__(self, pixmap, file_path, parent=None):
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setStyleSheet("""
QLabel {
border: 2px solid #555555;
border: 2px solid
border-radius: 10px;
padding: 5px;
margin: 5px;
}
QLabel:hover {
border-color: #0078d7;
border-color:
}
""")
self.setMinimumSize(310, 310)
Expand All @@ -194,9 +194,13 @@ def __init__(self):
self.threadpool = QThreadPool()
self.current_thread = None
self.is_grid_view = True
self.save_metadata_checkbox = None
self.initUI()
self.loadSettings()
self.save_metadata_checkbox = None
if self.save_metadata_checkbox is None:
print(
"Warning: save_metadata_checkbox is still None after initUI and loadSettings"
)
QTimer.singleShot(100, self.loadImagesAsync)

def initUI(self):
Expand All @@ -213,64 +217,64 @@ def initUI(self):
def getStyleSheet(self):
return """
QMainWindow, QWidget {
background-color: #2b2b2b;
color: #f0f0f0;
background-color:
color:
font-family: 'Arial', 'Sans-Serif';
font-size: 13px;
}
QLineEdit, QTextEdit, QComboBox, QSpinBox, QDoubleSpinBox {
background-color: #3c3c3c;
border: 1px solid #555555;
border-radius: 5px;
background-color:
border: 1px solid
borderradius: 5px;
padding: 5px;
color: #f0f0f0;
color:
width: 100%;
}
QPushButton {
background-color: #5c5c5c;
background-color:
color: white;
border: none;
border-radius: 5px;
borderradius: 5px;
padding: 8px 16px;
font-weight: 500;
min-height: 30px;
width: 100%;
}
QPushButton:hover {
background-color: #6c6c6c;
background-color:
}
QPushButton:pressed {
background-color: #4c4c4c;
border: 1px solid #333333;
background-color:
border: 1px solid
}
QLabel {
color: #f0f0f0;
color:
}
QScrollArea {
border: none;
background-color: #3c3c3c;
background-color:
}
QCheckBox {
spacing: 5px;
color: #f0f0f0;
spacin: 5px;
color:
}
QCheckBox::indicator {
width: 18px;
height: 18px;
}
QCheckBox::indicator:unchecked {
border: 2px solid #888888;
background-color: #3c3c3c;
border 2px solid
background-color:
}
QCheckBox::indicator:checked {
border: 2px solid #0078d7;
background-color: #0078d7;
border: 2px solid
background-color:
}
"""

def setupMainWidget(self):
main_widget = QWidget()
main_layout = QVBoxLayout(main_widget)
main_layout = QVBoxLayout(main_widget) # Corrected line
main_layout.setContentsMargins(20, 20, 20, 20)
main_layout.setSpacing(20)
self.setCentralWidget(main_widget)
Expand Down Expand Up @@ -472,7 +476,6 @@ def updateGallery(self, image_paths=None):
col = 0
self.gallery_layout.addWidget(preview, row, col)

# Ensure all widgets are visible
for i in range(self.gallery_layout.count()):
self.gallery_layout.itemAt(i).widget().show()

Expand All @@ -484,7 +487,7 @@ def clearGallery(self):
for i in reversed(range(self.gallery_layout.count())):
widget = self.gallery_layout.itemAt(i).widget()
if widget is not None:
widget.hide() # Hide the widget instead of deleting it
widget.hide()
self.gallery_layout.removeWidget(widget)

def center(self):
Expand Down Expand Up @@ -514,10 +517,15 @@ def display_images(self, image_urls):
counter += 1
urlretrieve(image_url, image_path)

if self.save_metadata_checkbox.isChecked():
if (
self.save_metadata_checkbox is not None
and self.save_metadata_checkbox.isChecked()
):
self.add_metadata_to_image(
image_path, self.prompt_input.toPlainText()
)
else:
print("Warning: save_metadata_checkbox is None or not checked")

new_image_paths.append(image_path)
else:
Expand All @@ -540,7 +548,7 @@ def add_metadata_to_image(self, image_path, prompt):
img.save(image_path, pnginfo=metadata)
elif img.format in ["JPEG", "WEBP"]:
exif = img.getexif()
exif[0x9286] = prompt # 0x9286 is the UserComment EXIF tag
exif[0x9286] = prompt
img.save(image_path, exif=exif)
except Exception as e:
print(f"Error adding metadata to {image_path}: {str(e)}")
Expand Down Expand Up @@ -600,7 +608,13 @@ def saveSettings(self):
)
self.settings.setValue("auto_save", self.auto_save_checkbox.isChecked())
self.settings.setValue("save_directory", self.save_dir_input.text())
self.settings.setValue("save_metadata", self.save_metadata_checkbox.isChecked())

if self.save_metadata_checkbox is not None:
self.settings.setValue(
"save_metadata", self.save_metadata_checkbox.isChecked()
)
else:
print("Warning: save_metadata_checkbox is None")

def choose_save_directory(self):
dir_path = QFileDialog.getExistingDirectory(self, "Choose Save Directory")
Expand Down

0 comments on commit e7dc8ad

Please sign in to comment.