From 33054a1f1c7430222d966b07396644fe4665990f Mon Sep 17 00:00:00 2001 From: QuBerto Date: Sun, 14 Jul 2024 23:06:07 +0200 Subject: [PATCH] update py --- config/encrypt_config.py | 5 ++ main.py | 24 +++---- main.spec | 2 +- ui/local_processing_tab.py | 139 ++++++++++++++++++------------------- ui/settings_tab.py | 23 ++++-- utils/file_operations.py | 2 +- 6 files changed, 101 insertions(+), 94 deletions(-) diff --git a/config/encrypt_config.py b/config/encrypt_config.py index 074f25d..764e960 100644 --- a/config/encrypt_config.py +++ b/config/encrypt_config.py @@ -46,6 +46,11 @@ class ConfigEncryptor: return {key: config[key] for key in keys_to_return if key in config} except FileNotFoundError: return None + def load_credentials(self): + config = self.load_config() + if config: + return config.get("credentials") + return None @staticmethod def is_json_serializable(value): diff --git a/main.py b/main.py index 7ec7128..1579c34 100644 --- a/main.py +++ b/main.py @@ -23,8 +23,7 @@ class ImageProcessorApp: """ self.root = root self.root.title("Image Processor") - self.root.geometry("520x600") - + self.root.geometry("480x800") # Create menu frame at the top menu_frame = ctk.CTkFrame(self.root) menu_frame.pack(side="top", fill="x") @@ -37,7 +36,7 @@ class ImageProcessorApp: # Create main frame to hold tabs and log window main_frame = ctk.CTkFrame(self.root) - main_frame.pack(expand=True, fill="both") + main_frame.pack(expand=True, fill="x") self.tab_parent = ctk.CTkFrame(main_frame) self.tab_parent.grid(row=0, column=0, sticky="nsew") @@ -45,8 +44,8 @@ class ImageProcessorApp: self.log_frame = ctk.CTkFrame(main_frame) self.log_frame.grid(row=1, column=0, sticky="nsew") - main_frame.grid_rowconfigure(0, weight=3) - main_frame.grid_rowconfigure(1, weight=1) + main_frame.grid_rowconfigure(0, weight=1) + main_frame.grid_columnconfigure(0, weight=1) self.log_window = LogWindow(self.log_frame) @@ -63,7 +62,7 @@ class ImageProcessorApp: """ Show the Local Processing tab. """ - self.local_processing_tab.tab.tkraise() + self.local_processing_tab.tab.tkraise() def show_settings_tab(self): """ @@ -81,12 +80,13 @@ class ImageProcessorApp: if __name__ == "__main__": try: decryptor = ConfigEncryptor(DECRYPTION_KEY) - config = decryptor.load_config() - wc_url = config["url"] - wc_consumer_key = config["consumer_key"] - wc_consumer_secret = config["consumer_secret"] - wp_username = config["username"] - wp_password = config["password"] + config = decryptor.load_credentials() + if config: + wc_url = config["url"] + wc_consumer_key = config["consumer_key"] + wc_consumer_secret = config["consumer_secret"] + wp_username = config["username"] + wp_password = config["password"] except FileNotFoundError as e: print(f"File not found: {e}") diff --git a/main.spec b/main.spec index 2ba8dd9..c55496f 100644 --- a/main.spec +++ b/main.spec @@ -29,7 +29,7 @@ exe = EXE( upx=True, upx_exclude=[], runtime_tmpdir=None, - console=True, + console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, diff --git a/ui/local_processing_tab.py b/ui/local_processing_tab.py index 94a9337..53fc6e4 100644 --- a/ui/local_processing_tab.py +++ b/ui/local_processing_tab.py @@ -1,7 +1,3 @@ -""" -Module for the Local Processing Tab in the Image Processor application. -""" - import tempfile import threading import customtkinter as ctk @@ -58,7 +54,6 @@ class LocalProcessingTab: def load_config(self): config = self.config.load_config() - print(config) if config: if options := config.get("options"): self.canvas_width = options.get("canvas_width", 900) @@ -75,103 +70,104 @@ class LocalProcessingTab: Set up the user interface for the tab. """ current_row = 0 + start_options_frame = ctk.CTkFrame(self.tab, bg_color="gray30") + start_options_frame.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="ew") - # Source selection section - self.source_label = ctk.CTkLabel(self.tab, anchor="w", width=500, text="Source Type:") - self.source_label.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="w") + self.options_button = ctk.CTkButton( + start_options_frame, text="Options", command=self.open_options_window + ) + self.options_button.grid(row=0, column=0, columnspan=2, padx=5, pady=5, sticky="w") + self.button_start = ctk.CTkButton( + start_options_frame, text="Start Processing", command=self.start_processing + ) + self.button_start.grid(row=0, column=2, columnspan=2, padx=5, pady=5, sticky="w") + + # Image previews section current_row += 1 + # Source selection section + source_frame = ctk.CTkFrame(self.tab, bg_color="gray20") + source_frame.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="ew") + + source_label = ctk.CTkLabel(source_frame, anchor="w", text="Source Type:") + source_label.grid(row=0, column=0, columnspan=6, padx=5, pady=5, sticky="w") + self.source_dropdown = ctk.CTkComboBox( - self.tab, + source_frame, variable=self.source_type, values=["directory", "file", "wp_image", "product", "all_products"], state="readonly", command=self.update_options ) - self.source_dropdown.grid(row=current_row, column=0, columnspan=2, padx=5, pady=5, sticky="w") + self.source_dropdown.grid(row=1, column=0, columnspan=2, padx=5, pady=5, sticky="w") self.source_dropdown.bind( "<>", lambda e: self.update_options() ) - # Options button - self.options_button = ctk.CTkButton( - self.tab, text="Options", command=self.open_options_window - ) - self.options_button.grid(row=current_row, column=4, columnspan=2, padx=5, pady=5, sticky="w") - - current_row += 1 - - self.button_start = ctk.CTkButton( - self.tab, text="Start Processing", command=self.start_processing - ) - self.button_start.grid( - row=current_row, column=4, columnspan=2, padx=5, pady=5, sticky="w" - ) self.browse_button = ctk.CTkButton( - self.tab, text="Browse directory", command=self.browse_directory_command + source_frame, text="Browse directory", command=self.browse_directory_command ) - self.browse_button.grid(row=current_row, column=0, columnspan=2, padx=5, pady=5, sticky="w") + self.browse_button.grid(row=2, column=0, columnspan=2, padx=5, pady=5, sticky="w") self.browse_file_button = ctk.CTkButton( - self.tab, text="Browse file", command=self.browse_file_command + source_frame, text="Browse file", command=self.browse_file_command ) - self.browse_file_button.grid(row=current_row, column=0, columnspan=2, padx=5, pady=5, sticky="w") + self.browse_file_button.grid(row=2, column=2, columnspan=2, padx=5, pady=5, sticky="w") - # WooCommerce Product ID section - self.product_id_button = ctk.CTkButton(self.tab, text="Get", width=25) - self.product_id_button.grid(row=2, column=2, columnspan=1, padx=5, pady=5, sticky="w") + self.product_id_button = ctk.CTkButton(source_frame, text="Get", width=25) + self.product_id_button.grid(row=2, column=4, columnspan=1, padx=5, pady=5, sticky="w") - self.product_id_entry = ctk.CTkEntry(self.tab) - self.product_id_entry.grid(row=current_row, column=0, columnspan=2,padx=5, pady=5, sticky="w") + self.product_id_entry = ctk.CTkEntry(source_frame) + self.product_id_entry.grid(row=2, column=5, columnspan=2, padx=5, pady=5, sticky="w") - # SKU section - self.additional_name_label = ctk.CTkLabel(self.tab, text="Add suffix:") - self.additional_name_label.grid( - row=current_row, column=1, padx=5, pady=5, sticky="w") + self.additional_name_label = ctk.CTkLabel(source_frame, text="Add suffix:") + self.additional_name_label.grid(row=2, column=7, padx=5, pady=5, sticky="w") - self.additional_name_entry = ctk.CTkEntry(self.tab) - self.additional_name_entry.grid( - row=current_row, column=2, padx=5, pady=5, sticky="w") - - current_row += 1 + self.additional_name_entry = ctk.CTkEntry(source_frame) + self.additional_name_entry.grid(row=2, column=8, padx=5, pady=5, sticky="w") # Destination selection section - self.destionation_label = ctk.CTkLabel(self.tab, anchor="w", width=500, text="Destination Type:") - self.destionation_label.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="w") - current_row += 1 + # destination_frame = ctk.CTkFrame(self.tab, bg_color="gray25") + # destination_frame.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="ew") - self.destionation_dropdown = ctk.CTkComboBox( - self.tab, - variable=self.source_type, - values=["auto", "directory", "file", "wp_image", "product"], - state="readonly", - command=self.update_options - ) - self.destionation_dropdown.grid(row=current_row, column=0, columnspan=2, padx=5, pady=5, sticky="w") - self.destionation_dropdown.bind( - "<>", lambda e: self.update_options() - ) + # destination_label = ctk.CTkLabel(destination_frame, anchor="w", text="Destination Type:") + # destination_label.grid(row=0, column=0, columnspan=6, padx=5, pady=5, sticky="w") - current_row += 1 + # self.destination_dropdown = ctk.CTkComboBox( + # destination_frame, + # variable=self.source_type, + # values=["auto", "directory", "file", "wp_image", "product"], + # state="readonly", + # command=self.update_options + # ) + # self.destination_dropdown.grid(row=1, column=0, columnspan=2, padx=5, pady=5, sticky="w") - # Image previews - self.before_label = ctk.CTkLabel(self.tab, text="Before:") - self.before_label.grid(row=current_row, column=0, padx=5, pady=5, sticky="w") + # # Start and Options section + # current_row += 1 + + preview_frame = ctk.CTkFrame(self.tab, bg_color="gray35") + preview_frame.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="ew") - self.after_label = ctk.CTkLabel(self.tab, text="After:") - self.after_label.grid(row=current_row, column=3, padx=5, pady=5, sticky="w") + self.before_label = ctk.CTkLabel(preview_frame, text="Before:") + self.before_label.grid(row=0, column=0, padx=5, pady=5, sticky="w") - current_row += 1 + self.after_label = ctk.CTkLabel(preview_frame, text="After:") + self.after_label.grid(row=0, column=3, padx=5, pady=5, sticky="w") - self.after_image_label = ctk.CTkLabel(self.tab, text="") - self.after_image_label.grid( - row=current_row, column=3, columnspan=3, padx=5, pady=5, sticky="w") - - self.before_image_label = ctk.CTkLabel(self.tab, text="") - self.before_image_label.grid( - row=current_row, column=0, columnspan=3, padx=5, pady=5, sticky="w") + self.before_image_label = ctk.CTkLabel(preview_frame, text="") + self.before_image_label.grid(row=1, column=0, columnspan=3, padx=5, pady=5, sticky="w") + + self.after_image_label = ctk.CTkLabel(preview_frame, text="") + self.after_image_label.grid(row=1, column=3, columnspan=3, padx=5, pady=5, sticky="w") + + # Configure grid weights to make frames span the full width + self.tab.grid_columnconfigure(0, weight=1) + source_frame.grid_columnconfigure(0, weight=1) + + start_options_frame.grid_columnconfigure(0, weight=1) + preview_frame.grid_columnconfigure(0, weight=1) def update_options(self, text=None): """ @@ -201,8 +197,6 @@ class LocalProcessingTab: after_path (str, optional): The path to the 'after' image. """ first_image_path = self.file.get_first_image_path() - if not before_path and not first_image_path: - first_image_path = "images/image-7.jpg" # Set the path to your image here if before_path and after_path: before_img = Image.open(before_path) before_img.thumbnail((200, 200)) @@ -275,7 +269,6 @@ class LocalProcessingTab: self.apply_options(self.get_options()) self.update_previews() - def apply_canvas_size(self): """ Apply the canvas size settings and update previews. diff --git a/ui/settings_tab.py b/ui/settings_tab.py index af198fa..8baf02a 100644 --- a/ui/settings_tab.py +++ b/ui/settings_tab.py @@ -10,13 +10,22 @@ class SettingsTab: self.setup_ui() def setup_ui(self): - settings_options = { - "url": {"type": "text", "label": "WooCommerce URL:", "default": self.credentials.get('url', '')}, - "consumer_key": {"type": "text", "label": "Consumer Key:", "default": self.credentials.get('consumer_key', '')}, - "consumer_secret": {"type": "text", "label": "Consumer Secret:", "default": self.credentials.get('consumer_secret', '')}, - "username": {"type": "text", "label": "Username:", "default": self.credentials.get('username', '')}, - "password": {"type": "text", "label": "Password:", "default": self.credentials.get('password', ''), "show": "*"} - } + if self.credentials: + settings_options = { + "url": {"type": "text", "label": "WooCommerce URL:", "default": self.credentials.get('url', '')}, + "consumer_key": {"type": "text", "label": "Consumer Key:", "default": self.credentials.get('consumer_key', '')}, + "consumer_secret": {"type": "text", "label": "Consumer Secret:", "default": self.credentials.get('consumer_secret', '')}, + "username": {"type": "text", "label": "Username:", "default": self.credentials.get('username', '')}, + "password": {"type": "text", "label": "Password:", "default": self.credentials.get('password', ''), "show": "*"} + } + else: + settings_options = { + "url": {"type": "text", "label": "WooCommerce URL:", "default": ""}, + "consumer_key": {"type": "text", "label": "Consumer Key:", "default": ""}, + "consumer_secret": {"type": "text", "label": "Consumer Secret:", "default": ""}, + "username": {"type": "text", "label": "Username:", "default": ""}, + "password": {"type": "text", "label": "Password:", "default": "", "show": "*"} + } row_index = 0 for name, details in settings_options.items(): diff --git a/utils/file_operations.py b/utils/file_operations.py index 308ea0c..45c4d60 100644 --- a/utils/file_operations.py +++ b/utils/file_operations.py @@ -43,7 +43,7 @@ class FileProcessor: """ if self.selected_file: return self.selected_file - + return None if not self.selected_directory: return None