before frames update

This commit is contained in:
2024-07-14 19:50:15 +02:00
parent d7b8f65627
commit 13bcc98cac
9 changed files with 400 additions and 330 deletions

View File

@@ -1,60 +1,49 @@
import tkinter as tk
from tkinter import ttk
import customtkinter as ctk
from api.woocommerce_api import save_credentials, load_credentials
class SettingsTab:
def __init__(self, tab_parent, text):
self.tab = ttk.Frame(tab_parent)
tab_parent.add(self.tab, text=text)
def __init__(self, tab_parent):
self.tab = ctk.CTkFrame(tab_parent)
self.tab.grid(row=0, column=0, sticky="nsew")
self.credentials = load_credentials()
self.inputs = {}
self.setup_ui()
def setup_ui(self):
url_label = tk.Label(self.tab, text="WooCommerce URL:")
url_label.pack(pady=5)
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": "*"}
}
self.url_entry = tk.Entry(self.tab)
self.url_entry.insert(0, self.credentials.get('url', ''))
self.url_entry.pack(pady=5)
row_index = 0
for name, details in settings_options.items():
self.create_setting(name, details, row_index)
row_index += 1
consumer_key_label = tk.Label(self.tab, text="Consumer Key:")
consumer_key_label.pack(pady=5)
save_button = ctk.CTkButton(self.tab, text="Save Credentials", command=self.save_credentials)
save_button.grid(row=row_index, column=0, columnspan=2, pady=10)
self.consumer_key_entry = tk.Entry(self.tab)
self.consumer_key_entry.insert(0, self.credentials.get('consumer_key', ''))
self.consumer_key_entry.pack(pady=5)
def create_setting(self, name, details, row_index):
"""
Create a setting based on its type.
"""
lbl = ctk.CTkLabel(self.tab, text=details["label"])
lbl.grid(row=row_index, column=0, padx=5, pady=5, sticky="w")
consumer_secret_label = tk.Label(self.tab, text="Consumer Secret:")
consumer_secret_label.pack(pady=5)
self.consumer_secret_entry = tk.Entry(self.tab, show="*")
self.consumer_secret_entry.insert(0, self.credentials.get('consumer_secret', ''))
self.consumer_secret_entry.pack(pady=5)
username_label = tk.Label(self.tab, text="Username:")
username_label.pack(pady=5)
self.username_entry = tk.Entry(self.tab)
self.username_entry.insert(0, self.credentials.get('username', ''))
self.username_entry.pack(pady=5)
password_label = tk.Label(self.tab, text="Password:")
password_label.pack(pady=5)
self.password_entry = tk.Entry(self.tab, show="*")
self.password_entry.insert(0, self.credentials.get('password', ''))
self.password_entry.pack(pady=5)
save_button = tk.Button(self.tab, text="Save Credentials", command=self.save_credentials)
save_button.pack(pady=5)
if details["type"] == "text":
entry = ctk.CTkEntry(self.tab, show=details.get("show", None))
entry.insert(0, details["default"])
entry.grid(row=row_index, column=1, padx=5, pady=5, sticky="w")
self.inputs[name] = entry
def save_credentials(self):
save_credentials(
self.url_entry.get(),
self.consumer_key_entry.get(),
self.consumer_secret_entry.get(),
self.username_entry.get(),
self.password_entry.get()
)
self.inputs["url"].get(),
self.inputs["consumer_key"].get(),
self.inputs["consumer_secret"].get(),
self.inputs["username"].get(),
self.inputs["password"].get()
)