From 182b0f9fe085c8cdf66d15b9d93eee373fe49455 Mon Sep 17 00:00:00 2001 From: CodeByMrFinchum Date: Thu, 9 Jan 2025 11:31:58 +0100 Subject: [PATCH] Few new checks and options, see changelog. --- src/OptimaLab35/gui.py | 58 +- src/OptimaLab35/ui/exif_handler_window.py | 2 +- src/OptimaLab35/ui/main_window.ui | 614 +++++++++++++++------- src/OptimaLab35/ui/preview_window.ui | 303 +++++++++++ 4 files changed, 782 insertions(+), 195 deletions(-) create mode 100644 src/OptimaLab35/ui/preview_window.ui diff --git a/src/OptimaLab35/gui.py b/src/OptimaLab35/gui.py index 10421cf..2f03582 100644 --- a/src/OptimaLab35/gui.py +++ b/src/OptimaLab35/gui.py @@ -57,10 +57,6 @@ class PreviewWindow(QMainWindow, Ui_Preview_Window): self.ui.image_path_lineEdit.setText(file[0]) self._update_preview() - def _supdate_preview(self): - self._update_preview() - pass - def _update_preview(self): path = self.ui.image_path_lineEdit.text() if not os.path.isfile(path): @@ -70,15 +66,13 @@ class PreviewWindow(QMainWindow, Ui_Preview_Window): save = False, image_input_file = path, image_output_file = "", - quality = 50, - optimize = True, grayscale = self.ui.grayscale_checkBox.isChecked(), brightness = int(self.ui.brightness_spinBox.text()), contrast = int(self.ui.contrast_spinBox.text()), ) - except Exception: + except Exception as e: QMessageBox.warning(self, "Warning", "Error loading image...") - print("Error loading image...") + print(f"Error loading image...\n{e}") return # Create a QPixmap object from an image file @@ -99,6 +93,7 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): self.ui = Ui_MainWindow() self.ui.setupUi(self) self.o = OptimaManager() + self.check_version() self.u = Utilities() self.u.program_configs() self.exif_file = os.path.expanduser("~/.config/OptimaLab35/exif.yaml") @@ -156,13 +151,14 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): self.ui.progressBar.setValue(0) def _info_window(self): + # ChatGPT, mainly info_text = f"""

{self.name} v{self.version}

{self.name} is a GUI for {self.o.name} (v{self.o.version}).

-

For more details, visit:

+

Both projects are in active development, for more details, visit:

""" @@ -278,9 +274,27 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): elif index == 0: # Main Tab self._handle_exif_file("write") + def _sort_dict_of_lists(self, input_dict): + # Partily ChatGPT + sorted_dict = {} + for key, lst in input_dict.items(): + # Sort alphabetically for strings, numerically for numbers + if key == "iso": + lst = [int(x) for x in lst] + lst = sorted(lst) + lst = [str(x) for x in lst] + sorted_dict["iso"] = lst + + elif all(isinstance(x, str) for x in lst): + sorted_dict[key] = sorted(lst, key=str.lower) # Case-insensitive sort for strings + + return sorted_dict + + def _handle_exif_file(self, do): if do == "read": - self.available_exif_data = self.u.read_yaml(self.exif_file) + file_dict = self.u.read_yaml(self.exif_file) + self.available_exif_data = self._sort_dict_of_lists(file_dict) elif do == "write": self.u.write_yaml(self.exif_file, self.available_exif_data) @@ -297,6 +311,7 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): "artist": self.ui.artist_comboBox, "copyright_info": self.ui.copyright_info_comboBox, } + self._populate_comboboxes(combo_mapping) def _populate_comboboxes(self, combo_mapping): @@ -400,7 +415,9 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): self.settings["contrast"] = int(self.ui.contrast_spinBox.text()) if self.ui.contrast_spinBox.text() != "0" else None #self._get_spinbox_value(self.ui.contrast_spinBox) if self.ui.contrast_checkbox.isChecked() else None - self.settings["new_file_names"] = self._get_text_value(self.ui.filename, False) if self.ui.rename_checkbox.isChecked() else False + new_name = self._get_text_value(self.ui.filename, False) if self.ui.rename_checkbox.isChecked() else False + if isinstance(new_name, str): new_name = new_name.replace(" ", "_") + self.settings["new_file_names"] = new_name self.settings["watermark"] = self.ui.watermark_lineEdit.text() if len(self.ui.watermark_lineEdit.text()) != 0 else None #self._get_text_value(self.ui.watermark_lineEdit) if self.ui.watermark_checkbox.isChecked() else None @@ -426,12 +443,27 @@ class OptimaLab35(QMainWindow, Ui_MainWindow): user_data["user_comment"] = self.ui.user_comment_comboBox.currentText() user_data["artist"] = self.ui.artist_comboBox.currentText() user_data["copyright_info"] = self.ui.copyright_info_comboBox.currentText() - user_data["software"] = f"{self.o.name} {self.o.version}" + user_data["software"] = f"{self.name} {self.version} with {self.o.name} {self.o.version}" return user_data def closeEvent(self, event): self.preview_window.close() + def check_version(self, min_version="0.6.5-a1"): + # Mainly ChatGPT + from packaging import version # Use `packaging` for robust version comparison + + current_version = self.o.version + if version.parse(current_version) < version.parse(min_version): + msg = ( + f"optima35 version {current_version} detected.\n" + f"Minimum required version is {min_version}.\n" + "Please update the core package to continue.\n" + "https://pypi.org/project/optima35/" + ) + QMessageBox.critical(None, "Version Error", msg) + sys.exit(1) + def main(): app = QtWidgets.QApplication(sys.argv) window = OptimaLab35() diff --git a/src/OptimaLab35/ui/exif_handler_window.py b/src/OptimaLab35/ui/exif_handler_window.py index 8564cba..930fb51 100644 --- a/src/OptimaLab35/ui/exif_handler_window.py +++ b/src/OptimaLab35/ui/exif_handler_window.py @@ -69,7 +69,7 @@ class ExifEditor(QMainWindow): self.list_widget.addItem(new_item) self.line_edit.clear() else: - QMessageBox.warning(self, "Warning", "Cannot add an empty item.") + QMessageBox.warning(self, "Warning", f"Cannot add an empty item.\nDelete {self.exif_file}...") def delete_item(self): """Delete the selected item from the list.""" diff --git a/src/OptimaLab35/ui/main_window.ui b/src/OptimaLab35/ui/main_window.ui index b75e88f..f4e3ac7 100644 --- a/src/OptimaLab35/ui/main_window.ui +++ b/src/OptimaLab35/ui/main_window.ui @@ -6,8 +6,8 @@ 0 0 - 450 - 708 + 440 + 756 @@ -18,7 +18,7 @@ - 500 + 1000 1000 @@ -52,6 +52,23 @@ + + + + input + + + + + + + + + + Enter output folder + + + @@ -62,24 +79,7 @@ - - - - - - - Enter output folder - - - - - - - input - - - - + output @@ -101,33 +101,83 @@ Essential group - - + + - Resize + Quality - - + + + + 1 + + + 100 + + + 90 + + + + + + + Export Format + + + + + + + optimize + + + + + + + 1 + + + 9 + + + 1 + + + 6 + + + Qt::Horizontal + + + + + - false + true 1 - 200 - - - 1 + 9 - 80 + 6 - + + + + Quality + + + + @@ -146,21 +196,47 @@ - - + + 1 100 - - 80 + + 90 + + + Qt::Horizontal - - + + + + Resize + + + + + + + 1 + + + 200 + + + 100 + + + Qt::Horizontal + + + + + true @@ -168,27 +244,17 @@ 1 - 9 + 200 + + + 1 - 6 - - - - - - - optimize + 100 - png_quality_spinBox - resize_checkbox - resize_spinBox - image_type - jpg_quality_spinBox - optimize_checkBox @@ -199,14 +265,124 @@ 16777215 + + false + Extra stuff - + + + + Brightness + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + true + + + -100 + + + 100 + + + 0 + + + + + + + true + + + -100 + + + 100 + + + 0 + + + + + + + Contrast + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + Turn image to Black and White + + + + + + + Preview + + + + + + + + + + true + + + Watermark + + + false + + + false + + + false + + + - false + true @@ -216,67 +392,14 @@ - - + + - Brightness + Size - - - - Grayscale - - - - - - - false - - - -100 - - - 100 - - - 10 - - - - - - - Watermark - - - - - - - false - - - -100 - - - 100 - - - -10 - - - - - - - Contrast - - - - + Normal @@ -671,90 +794,43 @@ 0 0 - 450 + 440 27 - Info + Settings - + + + + + Help + + + - Info + About + + + + + Preview image + + + + + About - - resize_checkbox - toggled(bool) - resize_spinBox - setEnabled(bool) - - - 75 - 96 - - - 196 - 118 - - - - - brightness_checkbox - toggled(bool) - brightness_spinBox - setEnabled(bool) - - - 83 - 363 - - - 83 - 399 - - - - - contrast_checkbox - toggled(bool) - contrast_spinBox - setEnabled(bool) - - - 185 - 363 - - - 185 - 399 - - - - - watermark_checkbox - toggled(bool) - watermark_lineEdit - setEnabled(bool) - - - 83 - 435 - - - 237 - 435 - - - rename_checkbox toggled(bool) @@ -915,5 +991,181 @@ + + brightness_horizontalSlider + valueChanged(int) + brightness_spinBox + setValue(int) + + + 187 + 393 + + + 378 + 393 + + + + + brightness_spinBox + valueChanged(int) + brightness_horizontalSlider + setValue(int) + + + 378 + 393 + + + 187 + 393 + + + + + contrast_horizontalSlider + valueChanged(int) + contrast_spinBox + setValue(int) + + + 187 + 458 + + + 378 + 458 + + + + + contrast_spinBox + valueChanged(int) + contrast_horizontalSlider + setValue(int) + + + 378 + 458 + + + 187 + 458 + + + + + resize_Slider + valueChanged(int) + resize_spinBox + setValue(int) + + + 218 + 252 + + + 380 + 252 + + + + + jpg_quality_Slider + valueChanged(int) + jpg_quality_spinBox + setValue(int) + + + 218 + 289 + + + 380 + 289 + + + + + jpg_quality_spinBox + valueChanged(int) + jpg_quality_Slider + setValue(int) + + + 380 + 289 + + + 218 + 289 + + + + + resize_spinBox + valueChanged(int) + resize_Slider + setValue(int) + + + 380 + 252 + + + 218 + 252 + + + + + resize_Slider + valueChanged(int) + resize_spinBox + setValue(int) + + + 218 + 252 + + + 380 + 252 + + + + + png_quality_Slider + valueChanged(int) + png_quality_spinBox + setValue(int) + + + 218 + 326 + + + 380 + 326 + + + + + png_quality_spinBox + valueChanged(int) + png_quality_Slider + setValue(int) + + + 380 + 326 + + + 218 + 326 + + + diff --git a/src/OptimaLab35/ui/preview_window.ui b/src/OptimaLab35/ui/preview_window.ui new file mode 100644 index 0000000..29a8057 --- /dev/null +++ b/src/OptimaLab35/ui/preview_window.ui @@ -0,0 +1,303 @@ + + + Preview_Window + + + + 0 + 0 + 803 + 700 + + + + + 800 + 700 + + + + OptimaLab35 - Preview + + + + + + + + 628 + 628 + + + + QFrame::Box + + + + + + true + + + + + + + + 140 + 628 + + + + + 140 + 16777215 + + + + + + + Path to image + + + + + + + Select image + + + + + + + + 16777215 + 120 + + + + + + + Brightness + + + + + + + -100 + + + 100 + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + Reset + + + + + + + + + + + 16777215 + 120 + + + + + + + Contrast + + + + + + + -100 + + + 100 + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + Reset + + + + + + + + + + Grayscale + + + + + + + Update preview + + + + + + + + + + Copy values to main window when closing + + + false + + + true + + + + + + + Copy Values + + + true + + + + + + + Close + + + + + + + + + + + + + + + 0 + 0 + 803 + 27 + + + + + + + + brightness_Slider + valueChanged(int) + brightness_spinBox + setValue(int) + + + 720 + 311 + + + 706 + 282 + + + + + brightness_spinBox + valueChanged(int) + brightness_Slider + setValue(int) + + + 706 + 282 + + + 720 + 311 + + + + + contrast_Slider + valueChanged(int) + contrast_spinBox + setValue(int) + + + 720 + 454 + + + 699 + 425 + + + + + contrast_spinBox + valueChanged(int) + contrast_Slider + setValue(int) + + + 699 + 425 + + + 720 + 454 + + + + +