From 9cd884948d906543d5dce8dba458d64cb7f827b6 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Mon, 11 Mar 2024 23:37:09 +0100 Subject: [PATCH] wip: add config window --- client.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 5 deletions(-) diff --git a/client.py b/client.py index f8d406c..a132082 100644 --- a/client.py +++ b/client.py @@ -3,6 +3,7 @@ import PIL import data_backend import client_details import pgwrapper +import sys customtkinter.set_appearance_mode("dark") customtkinter.set_default_color_theme("blue") @@ -11,12 +12,105 @@ app = customtkinter.CTk() app.geometry("1030x770") last_geometry = app.winfo_geometry() -app.title("Test") -app.update() buttons = [] details_elements = [] +non_disabled_entry_color = None + +def close_input_window(input_window): + # Placeholder function for the button action + print("Closing input window") + input_window.quit() + +def dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, + install_dir_entry): + + global non_disabled_entry_color + + # FIXME or not idfk # + if type(dropdown_var) != str: + dropdown_var = dropdown_var.get() + + # Check the current value of the dropdown and enable/disable user and password inputs accordingly + if dropdown_var == "Local Filesystem": + user_entry.configure(state=customtkinter.DISABLED) + password_entry.configure(state=customtkinter.DISABLED) + non_disabled_entry_color = password_entry.cget("fg_color") + print(non_disabled_entry_color) + password_entry.configure(fg_color="#CCCCCC") + user_entry.configure(fg_color="#CCCCCC") + server_path_entry.delete(0, customtkinter.END) + server_path_entry.insert(0, "C:/path/to/game/mount/") + else: + user_entry.configure(state=customtkinter.NORMAL) + password_entry.configure(state=customtkinter.NORMAL) + if non_disabled_entry_color: # else first run and nothing to do + password_entry.configure(fg_color=non_disabled_entry_color) + user_entry.configure(fg_color=non_disabled_entry_color) + server_path_entry.delete(0, customtkinter.END) + server_path_entry.insert(0, "ftp://server/path::port or ftps://server/path:port") + + install_dir_entry.delete(0, customtkinter.END) + install_dir_entry.insert(0, "./install-dir") + +# Create a frame to hold the inputs + +def get_config_inputs(): + '''Create a config input window and use the settings from it''' + + input_window = customtkinter.CTk() + input_window.geometry("500x250") + input_window.title("Vault Configuration") + + # Server/Path + server_path_label = customtkinter.CTkLabel(input_window, text="Server/Path:") + server_path_label.grid(row=1, column=0, sticky="w", padx=10, pady=5) + server_path_entry = customtkinter.CTkEntry(input_window) + server_path_entry.grid(row=1, column=1, padx=10, pady=5, sticky="ew", columnspan=2) + + # User + user_label = customtkinter.CTkLabel(input_window, text="User:") + user_label.grid(row=2, column=0, sticky="w", padx=10, pady=5) + user_entry = customtkinter.CTkEntry(input_window) + user_entry.grid(row=2, column=1, padx=10, pady=5) + + # Password + password_label = customtkinter.CTkLabel(input_window, text="Password:") + password_label.grid(row=3, column=0, sticky="w", padx=10, pady=5) + password_entry = customtkinter.CTkEntry(input_window, show="*") + password_entry.grid(row=3, column=1, padx=10, pady=5) + + # Install dir + install_dir_label = customtkinter.CTkLabel(input_window, text="Install dir:") + install_dir_label.grid(row=4, column=0, sticky="w", padx=10, pady=5) + install_dir_entry = customtkinter.CTkEntry(input_window) + install_dir_entry.grid(row=4, column=1, padx=10, pady=5, sticky="ew", columnspan=2) + + # Dropdown + dropdown_var = customtkinter.StringVar(value="Local Filesystem") + dropdown_label = customtkinter.CTkLabel(input_window, text="Select option:") + dropdown_label.grid(row=0, column=0, sticky="w", padx=10, pady=5) + dropdown = customtkinter.CTkOptionMenu(input_window, variable=dropdown_var, values=["FTP/FTPS", "Local Filesystem"], + command=lambda dropdown_var=dropdown_var, user_entry=user_entry, password_entry=password_entry, + server_path_entry=server_path_entry, install_dir_entry=install_dir_entry: + dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, install_dir_entry)) + + # set dropdown & field defaults + dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, install_dir_entry) + dropdown.grid(row=0, column=1, padx=10, pady=5) + + # Button to save & close # + save_button = customtkinter.CTkButton(input_window, text="Save & Close", command=lambda: close_input_window(input_window)) + save_button.grid(row=5, column=0, padx=10, pady=20) + + # Button to abort & close # + abort_button = customtkinter.CTkButton(input_window, text="Abort", command=lambda: input_window.quit()) + abort_button.grid(row=5, column=2, padx=10, pady=20) + + input_window.update() + input_window.mainloop() + def create_navbar(): '''Create basic navigation bar''' @@ -135,9 +229,13 @@ if __name__ == "__main__": # define data backend # #db = data_backend.LocalFS(None, None, "./install/", remote_root_dir="example_software_root") db = data_backend.FTP(None, None, "./install/", server="ftp://192.168.1.132:2121", - remote_root_dir="/", progress_bar_wrapper=pgw, tkinter_root=app) + remote_root_dir="/", progress_bar_wrapper=pgw, tkinter_root=app) # TODO load values instead of hardcode - load_main() + get_config_inputs() # TODO save values - # run app # + # geometry is set at the very beginning # + app.update() + + # fill and run app # + load_main() # TODO add button to reopen config # TODO add button to purge cache/purge cache window # TODO show cache size # TODO show game size on remote app.mainloop()