117 lines
12 KiB
Python
117 lines
12 KiB
Python
"""
|
||
Module for the Local Processing Tab in the Image Processor application.
|
||
"""
|
||
|
||
import tempfile
|
||
import threading
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
from tkinter.scrolledtext import ScrolledText
|
||
from tkinter import Tk, Label, Button, Entry, Toplevel, StringVar, BooleanVar
|
||
from PIL import Image, ImageTk
|
||
from utils.file_operations import FileProcessor
|
||
from utils.image_processing import ImageProcessor
|
||
from api.woocommerce_api import process_product_images, process_all_products
|
||
from ui.options_window import OptionsWindow
|
||
|
||
|
||
class LocalProcessingTab:
|
||
"""
|
||
Class for the Local Processing Tab in the Image Processor application.
|
||
"""
|
||
|
||
def __init__(self, tab_parent, text, log):
|
||
"""
|
||
Initialize the LocalProcessingTab.
|
||
|
||
Args:
|
||
tab_parent (ttk.Notebook): The parent notebook widget.
|
||
text (str): The text to display on the tab.
|
||
log (function): The function to log messages.
|
||
"""
|
||
self.log = log
|
||
self.tab = ttk.Frame(tab_parent)
|
||
self.root = self.tab.winfo_toplevel() # Store the root window reference
|
||
tab_parent.add(self.tab, text=text)
|
||
|
||
self.log_window = None
|
||
|
||
self.canvas_width = 900
|
||
self.canvas_height = 900
|
||
self.template = "{slug}_{sku}_{width}x{height}"
|
||
self.delete_images = False
|
||
|
||
self.source_type = StringVar(value="local")
|
||
self.checkbox_var = BooleanVar(value=False)
|
||
self.file = FileProcessor()
|
||
self.image = ImageProcessor()
|
||
# Automatically open the options window with default options
|
||
|
||
self.setup_ui()
|
||
self.update_options()
|
||
|
||
def create_log_window(self):
|
||
"""
|
||
Create and display the log window.
|
||
"""
|
||
if self.log_window and Toplevel.winfo_exists(self.log_window):
|
||
return
|
||
self.log_window = Toplevel()
|
||
self.log_window.title("Processing Log")
|
||
self.log_text = ScrolledText(
|
||
self.log_window, state="disabled", wrap="word", height=20, width=80
|
||
)
|
||
self.log_text.pack(expand=True, fill="both")
|
||
|
||
def log_message(self, message):
|
||
"""
|
||
Log a message to the log window.
|
||
|
||
Args:
|
||
message (str): The message to log.
|
||
"""
|
||
self.log_text.config(state="normal")
|
||
self.log_text.insert(tk.END, message + "\n")
|
||
self.log_text.see(tk.END)
|
||
self.log_text.config(state="disabled")
|
||
self.log_text.update_idletasks()
|
||
|
||
def setup_ui(self):
|
||
"""
|
||
Set up the user interface for the tab.
|
||
"""
|
||
# Source selection section
|
||
self.source_label = Label(self.tab, text="Source Type:")
|
||
self.source_label.grid(row=0, column=0, padx=5, pady=5, sticky="w")
|
||
|
||
self.source_dropdown = ttk.Combobox(
|
||
self.tab,
|
||
textvariable=self.source_type,
|
||
values=["local", "product", "all_products"],
|
||
state="readonly",
|
||
)
|
||
self.source_dropdown.grid(row=1, column=0, padx=5, pady=5, sticky="w")
|
||
self.source_dropdown.bind(
|
||
"<<ComboboxSelected>>", lambda e: self.update_options()
|
||
)
|
||
|
||
self.browse_button = ttk.Button(
|
||
self.tab, text="Browse", command=self.browse_directory_command
|
||
)
|
||
self.browse_button.grid(row=2, column=0, padx=5, pady=5, sticky="w")
|
||
|
||
# WooCommerce Product ID section
|
||
self.product_id_label = Label(self.tab, text="Product ID:")
|
||
self.product_id_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
|
||
|
||
self.product_id_entry = Entry(self.tab)
|
||
self.product_id_entry.grid(row=3, column=0, padx=5, pady=5, sticky="w")
|
||
|
||
# SKU section
|
||
self.additional_name_label = Label(self.tab, text="Add suffix:")
|
||
self.additional_name_label.grid(
|
||
row=2, column=1, padx=5, pady=5, sticky="w")
|
||
|
||
self.additional_name_entry = Entry(self.tab)
|
||
self.additional_name_entry.grid(
|
||
|