From 2c296f25cd85a30c2c364ec24f8e558d4573beb8 Mon Sep 17 00:00:00 2001 From: dez Date: Fri, 1 Mar 2024 14:45:13 +0100 Subject: [PATCH] wip tabs 2.0 --- src/gui_left_tabs.py | 72 ++++++++++++++++++-------------------------- src/gui_main.py | 10 +++--- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/gui_left_tabs.py b/src/gui_left_tabs.py index f4aea11..b5952cf 100644 --- a/src/gui_left_tabs.py +++ b/src/gui_left_tabs.py @@ -1,22 +1,14 @@ import threading -import time -import math -from tkinter import Canvas, Tk, Frame, Button +from tkinter import Frame, Button # Constants FRAME_INTERVAL = 1 # milliseconds, adjust to control the animation speed -# Modified code -root = Tk() -root.geometry("1000x600") - -from gui_starfield import StarField # Assuming gui_starfield.py contains the StarField class - -container_x_size = 320 # Defined size of tab/container +container_x_size = 320 container_x = -container_x_size col_isDark = True -current_container = None # To keep track of the current container +current_container = None close_finished_event = threading.Event() def open_container(): @@ -25,10 +17,10 @@ def open_container(): container_x += 1 current_container.place(x=container_x, y=0) if container_x >= 0: - container_x = 0 # This is stupid, but just to make sure - pass # If you need to execute something when the container is fully open, add it here + container_x = 0 + pass else: - root.after(FRAME_INTERVAL, open_container) + current_container.after(FRAME_INTERVAL, open_container) def close_container(): global container_x @@ -37,52 +29,48 @@ def close_container(): container_x -= 1 current_container.place(x=container_x, y=0) if container_x <= -container_x_size: - container_x = -container_x_size # This is stupid, but just to make sure - close_finished_event.set() # Signal that the closing animation is finished - pass # If you need to execute something when the container is fully closed, add it here + container_x = -container_x_size + close_finished_event.set() + pass else: - root.after(FRAME_INTERVAL, close_container) + current_container.after(FRAME_INTERVAL, close_container) -def switch_to_tab(tab_name): +def switch_to_tab(tab_name, root): global current_container global close_finished_event if current_container: - close_finished_event.clear() # Clear the event flag - close_container() # Close the current container - - # Wait for the closing animation to finish + close_finished_event.clear() + close_container() close_finished_event.wait() - - # Delete the current container current_container.destroy() - # Change to the new container (placeholder for now) if tab_name == "Starfield": current_container = Frame(root, width=320, height=600, bg="black", relief="flat") - star_field = StarField(current_container, 400, 600, col_isDark) - star_field.canvas.pack(side="left", fill="y") - current_container.place(x=-320, y=0) + current_container.place(x=0, y=0) # Place the container inside the given Tk instance + # Add your StarField code here elif tab_name == "Blocking": - current_container = Frame(root, width=320, height=600, bg="blue", relief="flat") # Placeholder color - current_container.place(x=-320, y=0) + current_container = Frame(root, width=320, height=600, bg="blue", relief="flat") + current_container.place(x=0, y=0) else: print("Unknown tab name:", tab_name) - open_container() # Open the new container + open_container() -def switch_to_tab_threaded(tab_name): - thread = threading.Thread(target=lambda: switch_to_tab(tab_name)) +def switch_to_tab_threaded(tab_name, root): + thread = threading.Thread(target=lambda: switch_to_tab(tab_name, root)) thread.start() -# Widgets -container = Frame(root, width=320, height=600, bg="black", relief="flat") -container.place(x=-320, y=0) +def create_gui_left_tabs(root): + global container -btn_starfield = Button(root, text="Switch to Starfield", command=lambda: switch_to_tab_threaded("Starfield")) -btn_starfield.place(x=500, y=50) + # Widgets + container = Frame(root, width=320, height=600, bg="black", relief="flat") + container.place(x=-320, y=0) -btn_blocking = Button(root, text="Switch to Blocking", command=lambda: switch_to_tab_threaded("Blocking")) -btn_blocking.place(x=500, y=100) + btn_starfield = Button(root, text="TEST SWITCH TAB 1", command=lambda: switch_to_tab_threaded("Starfield", root)) + btn_starfield.place(x=500, y=50) + + btn_blocking = Button(root, text="TEST SWITCH TAB 2", command=lambda: switch_to_tab_threaded("Blocking", root)) + btn_blocking.place(x=500, y=100) -root.mainloop() diff --git a/src/gui_main.py b/src/gui_main.py index e8aceba..c631d31 100644 --- a/src/gui_main.py +++ b/src/gui_main.py @@ -3,9 +3,11 @@ import os from customtkinter import * from tkinter import PhotoImage from PIL import Image, ImageTk +from tkinter import Frame import download_main from gui_starfield import StarField +import gui_left_tabs def run_installer(download_folder_tmp, col_isDark): global visible_widgets, tab_combobox, progress_bar # Declare tab_combobox as a global variable @@ -37,11 +39,6 @@ def run_installer(download_folder_tmp, col_isDark): progress_label.pack(pady=20, padx=20) - def display_star_field(container): - global star_field - star_field = StarField(container, 400, 600, col_isDark) - star_field.canvas.pack(side="left", fill="y") - def create_widgets_for_current_tab(): # Remove currently visible widgets for widget in visible_widgets: @@ -183,7 +180,8 @@ def run_installer(download_folder_tmp, col_isDark): container = CTkFrame(app) container.pack(ipadx="110") - display_star_field(container) + # Display the left tabs + gui_left_tabs.create_gui_left_tabs(app) tab_combobox = CTkComboBox(master=app, values=list(tabs.keys())) tab_combobox.set(list(tabs.keys())[0])