update py

This commit is contained in:
2024-07-14 23:06:07 +02:00
parent 13bcc98cac
commit 33054a1f1c
6 changed files with 101 additions and 94 deletions

View File

@@ -46,6 +46,11 @@ class ConfigEncryptor:
return {key: config[key] for key in keys_to_return if key in config} return {key: config[key] for key in keys_to_return if key in config}
except FileNotFoundError: except FileNotFoundError:
return None return None
def load_credentials(self):
config = self.load_config()
if config:
return config.get("credentials")
return None
@staticmethod @staticmethod
def is_json_serializable(value): def is_json_serializable(value):

24
main.py
View File

@@ -23,8 +23,7 @@ class ImageProcessorApp:
""" """
self.root = root self.root = root
self.root.title("Image Processor") self.root.title("Image Processor")
self.root.geometry("520x600") self.root.geometry("480x800")
# Create menu frame at the top # Create menu frame at the top
menu_frame = ctk.CTkFrame(self.root) menu_frame = ctk.CTkFrame(self.root)
menu_frame.pack(side="top", fill="x") menu_frame.pack(side="top", fill="x")
@@ -37,7 +36,7 @@ class ImageProcessorApp:
# Create main frame to hold tabs and log window # Create main frame to hold tabs and log window
main_frame = ctk.CTkFrame(self.root) 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 = ctk.CTkFrame(main_frame)
self.tab_parent.grid(row=0, column=0, sticky="nsew") 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 = ctk.CTkFrame(main_frame)
self.log_frame.grid(row=1, column=0, sticky="nsew") self.log_frame.grid(row=1, column=0, sticky="nsew")
main_frame.grid_rowconfigure(0, weight=3) main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_rowconfigure(1, weight=1)
main_frame.grid_columnconfigure(0, weight=1) main_frame.grid_columnconfigure(0, weight=1)
self.log_window = LogWindow(self.log_frame) self.log_window = LogWindow(self.log_frame)
@@ -63,7 +62,7 @@ class ImageProcessorApp:
""" """
Show the Local Processing tab. Show the Local Processing tab.
""" """
self.local_processing_tab.tab.tkraise() self.local_processing_tab.tab.tkraise()
def show_settings_tab(self): def show_settings_tab(self):
""" """
@@ -81,12 +80,13 @@ class ImageProcessorApp:
if __name__ == "__main__": if __name__ == "__main__":
try: try:
decryptor = ConfigEncryptor(DECRYPTION_KEY) decryptor = ConfigEncryptor(DECRYPTION_KEY)
config = decryptor.load_config() config = decryptor.load_credentials()
wc_url = config["url"] if config:
wc_consumer_key = config["consumer_key"] wc_url = config["url"]
wc_consumer_secret = config["consumer_secret"] wc_consumer_key = config["consumer_key"]
wp_username = config["username"] wc_consumer_secret = config["consumer_secret"]
wp_password = config["password"] wp_username = config["username"]
wp_password = config["password"]
except FileNotFoundError as e: except FileNotFoundError as e:
print(f"File not found: {e}") print(f"File not found: {e}")

View File

@@ -29,7 +29,7 @@ exe = EXE(
upx=True, upx=True,
upx_exclude=[], upx_exclude=[],
runtime_tmpdir=None, runtime_tmpdir=None,
console=True, console=False,
disable_windowed_traceback=False, disable_windowed_traceback=False,
argv_emulation=False, argv_emulation=False,
target_arch=None, target_arch=None,

View File

@@ -1,7 +1,3 @@
"""
Module for the Local Processing Tab in the Image Processor application.
"""
import tempfile import tempfile
import threading import threading
import customtkinter as ctk import customtkinter as ctk
@@ -58,7 +54,6 @@ class LocalProcessingTab:
def load_config(self): def load_config(self):
config = self.config.load_config() config = self.config.load_config()
print(config)
if config: if config:
if options := config.get("options"): if options := config.get("options"):
self.canvas_width = options.get("canvas_width", 900) self.canvas_width = options.get("canvas_width", 900)
@@ -75,103 +70,104 @@ class LocalProcessingTab:
Set up the user interface for the tab. Set up the user interface for the tab.
""" """
current_row = 0 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.options_button = ctk.CTkButton(
self.source_label = ctk.CTkLabel(self.tab, anchor="w", width=500, text="Source Type:") start_options_frame, text="Options", command=self.open_options_window
self.source_label.grid(row=current_row, column=0, columnspan=6, padx=5, pady=5, sticky="w") )
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 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.source_dropdown = ctk.CTkComboBox(
self.tab, source_frame,
variable=self.source_type, variable=self.source_type,
values=["directory", "file", "wp_image", "product", "all_products"], values=["directory", "file", "wp_image", "product", "all_products"],
state="readonly", state="readonly",
command=self.update_options 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( self.source_dropdown.bind(
"<<ComboboxSelected>>", lambda e: self.update_options() "<<ComboboxSelected>>", 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.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.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(source_frame, text="Get", width=25)
self.product_id_button = ctk.CTkButton(self.tab, text="Get", width=25) self.product_id_button.grid(row=2, column=4, columnspan=1, padx=5, pady=5, sticky="w")
self.product_id_button.grid(row=2, column=2, columnspan=1, padx=5, pady=5, sticky="w")
self.product_id_entry = ctk.CTkEntry(self.tab) self.product_id_entry = ctk.CTkEntry(source_frame)
self.product_id_entry.grid(row=current_row, column=0, columnspan=2,padx=5, pady=5, sticky="w") 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(source_frame, text="Add suffix:")
self.additional_name_label = ctk.CTkLabel(self.tab, text="Add suffix:") self.additional_name_label.grid(row=2, column=7, padx=5, pady=5, sticky="w")
self.additional_name_label.grid(
row=current_row, column=1, padx=5, pady=5, sticky="w")
self.additional_name_entry = ctk.CTkEntry(self.tab) self.additional_name_entry = ctk.CTkEntry(source_frame)
self.additional_name_entry.grid( self.additional_name_entry.grid(row=2, column=8, padx=5, pady=5, sticky="w")
row=current_row, column=2, padx=5, pady=5, sticky="w")
current_row += 1
# Destination selection section # 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 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( # destination_label = ctk.CTkLabel(destination_frame, anchor="w", text="Destination Type:")
self.tab, # destination_label.grid(row=0, column=0, columnspan=6, padx=5, pady=5, sticky="w")
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(
"<<ComboboxSelected>>", lambda e: self.update_options()
)
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 # # Start and Options section
self.before_label = ctk.CTkLabel(self.tab, text="Before:") # current_row += 1
self.before_label.grid(row=current_row, column=0, padx=5, pady=5, sticky="w")
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.before_label = ctk.CTkLabel(preview_frame, text="Before:")
self.after_label.grid(row=current_row, column=3, padx=5, pady=5, sticky="w") 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.before_image_label = ctk.CTkLabel(preview_frame, text="")
self.after_image_label.grid( self.before_image_label.grid(row=1, column=0, columnspan=3, padx=5, pady=5, sticky="w")
row=current_row, column=3, columnspan=3, padx=5, pady=5, sticky="w")
self.after_image_label = ctk.CTkLabel(preview_frame, text="")
self.before_image_label = ctk.CTkLabel(self.tab, text="") self.after_image_label.grid(row=1, column=3, columnspan=3, padx=5, pady=5, sticky="w")
self.before_image_label.grid(
row=current_row, column=0, 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): def update_options(self, text=None):
""" """
@@ -201,8 +197,6 @@ class LocalProcessingTab:
after_path (str, optional): The path to the 'after' image. after_path (str, optional): The path to the 'after' image.
""" """
first_image_path = self.file.get_first_image_path() 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: if before_path and after_path:
before_img = Image.open(before_path) before_img = Image.open(before_path)
before_img.thumbnail((200, 200)) before_img.thumbnail((200, 200))
@@ -275,7 +269,6 @@ class LocalProcessingTab:
self.apply_options(self.get_options()) self.apply_options(self.get_options())
self.update_previews() self.update_previews()
def apply_canvas_size(self): def apply_canvas_size(self):
""" """
Apply the canvas size settings and update previews. Apply the canvas size settings and update previews.

View File

@@ -10,13 +10,22 @@ class SettingsTab:
self.setup_ui() self.setup_ui()
def setup_ui(self): def setup_ui(self):
settings_options = { if self.credentials:
"url": {"type": "text", "label": "WooCommerce URL:", "default": self.credentials.get('url', '')}, settings_options = {
"consumer_key": {"type": "text", "label": "Consumer Key:", "default": self.credentials.get('consumer_key', '')}, "url": {"type": "text", "label": "WooCommerce URL:", "default": self.credentials.get('url', '')},
"consumer_secret": {"type": "text", "label": "Consumer Secret:", "default": self.credentials.get('consumer_secret', '')}, "consumer_key": {"type": "text", "label": "Consumer Key:", "default": self.credentials.get('consumer_key', '')},
"username": {"type": "text", "label": "Username:", "default": self.credentials.get('username', '')}, "consumer_secret": {"type": "text", "label": "Consumer Secret:", "default": self.credentials.get('consumer_secret', '')},
"password": {"type": "text", "label": "Password:", "default": self.credentials.get('password', ''), "show": "*"} "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 row_index = 0
for name, details in settings_options.items(): for name, details in settings_options.items():

View File

@@ -43,7 +43,7 @@ class FileProcessor:
""" """
if self.selected_file: if self.selected_file:
return self.selected_file return self.selected_file
return None
if not self.selected_directory: if not self.selected_directory:
return None return None