wip tabs 2.0

This commit is contained in:
dez 2024-03-01 14:45:13 +01:00
parent dabc74f0a1
commit 2c296f25cd
2 changed files with 34 additions and 48 deletions

View file

@ -1,22 +1,14 @@
import threading import threading
import time from tkinter import Frame, Button
import math
from tkinter import Canvas, Tk, Frame, Button
# Constants # Constants
FRAME_INTERVAL = 1 # milliseconds, adjust to control the animation speed FRAME_INTERVAL = 1 # milliseconds, adjust to control the animation speed
# Modified code container_x_size = 320
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 = -container_x_size container_x = -container_x_size
col_isDark = True col_isDark = True
current_container = None # To keep track of the current container current_container = None
close_finished_event = threading.Event() close_finished_event = threading.Event()
def open_container(): def open_container():
@ -25,10 +17,10 @@ def open_container():
container_x += 1 container_x += 1
current_container.place(x=container_x, y=0) current_container.place(x=container_x, y=0)
if container_x >= 0: if container_x >= 0:
container_x = 0 # This is stupid, but just to make sure container_x = 0
pass # If you need to execute something when the container is fully open, add it here pass
else: else:
root.after(FRAME_INTERVAL, open_container) current_container.after(FRAME_INTERVAL, open_container)
def close_container(): def close_container():
global container_x global container_x
@ -37,52 +29,48 @@ def close_container():
container_x -= 1 container_x -= 1
current_container.place(x=container_x, y=0) current_container.place(x=container_x, y=0)
if container_x <= -container_x_size: if container_x <= -container_x_size:
container_x = -container_x_size # This is stupid, but just to make sure container_x = -container_x_size
close_finished_event.set() # Signal that the closing animation is finished close_finished_event.set()
pass # If you need to execute something when the container is fully closed, add it here pass
else: 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 current_container
global close_finished_event global close_finished_event
if current_container: if current_container:
close_finished_event.clear() # Clear the event flag close_finished_event.clear()
close_container() # Close the current container close_container()
# Wait for the closing animation to finish
close_finished_event.wait() close_finished_event.wait()
# Delete the current container
current_container.destroy() current_container.destroy()
# Change to the new container (placeholder for now)
if tab_name == "Starfield": if tab_name == "Starfield":
current_container = Frame(root, width=320, height=600, bg="black", relief="flat") current_container = Frame(root, width=320, height=600, bg="black", relief="flat")
star_field = StarField(current_container, 400, 600, col_isDark) current_container.place(x=0, y=0) # Place the container inside the given Tk instance
star_field.canvas.pack(side="left", fill="y") # Add your StarField code here
current_container.place(x=-320, y=0)
elif tab_name == "Blocking": elif tab_name == "Blocking":
current_container = Frame(root, width=320, height=600, bg="blue", relief="flat") # Placeholder color current_container = Frame(root, width=320, height=600, bg="blue", relief="flat")
current_container.place(x=-320, y=0) current_container.place(x=0, y=0)
else: else:
print("Unknown tab name:", tab_name) print("Unknown tab name:", tab_name)
open_container() # Open the new container open_container()
def switch_to_tab_threaded(tab_name): def switch_to_tab_threaded(tab_name, root):
thread = threading.Thread(target=lambda: switch_to_tab(tab_name)) thread = threading.Thread(target=lambda: switch_to_tab(tab_name, root))
thread.start() thread.start()
def create_gui_left_tabs(root):
global container
# Widgets # Widgets
container = Frame(root, width=320, height=600, bg="black", relief="flat") container = Frame(root, width=320, height=600, bg="black", relief="flat")
container.place(x=-320, y=0) container.place(x=-320, y=0)
btn_starfield = Button(root, text="Switch to Starfield", command=lambda: switch_to_tab_threaded("Starfield")) 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_starfield.place(x=500, y=50)
btn_blocking = Button(root, text="Switch to Blocking", command=lambda: switch_to_tab_threaded("Blocking")) btn_blocking = Button(root, text="TEST SWITCH TAB 2", command=lambda: switch_to_tab_threaded("Blocking", root))
btn_blocking.place(x=500, y=100) btn_blocking.place(x=500, y=100)
root.mainloop()

View file

@ -3,9 +3,11 @@ import os
from customtkinter import * from customtkinter import *
from tkinter import PhotoImage from tkinter import PhotoImage
from PIL import Image, ImageTk from PIL import Image, ImageTk
from tkinter import Frame
import download_main import download_main
from gui_starfield import StarField from gui_starfield import StarField
import gui_left_tabs
def run_installer(download_folder_tmp, col_isDark): def run_installer(download_folder_tmp, col_isDark):
global visible_widgets, tab_combobox, progress_bar # Declare tab_combobox as a global variable 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) 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(): def create_widgets_for_current_tab():
# Remove currently visible widgets # Remove currently visible widgets
for widget in visible_widgets: for widget in visible_widgets:
@ -183,7 +180,8 @@ def run_installer(download_folder_tmp, col_isDark):
container = CTkFrame(app) container = CTkFrame(app)
container.pack(ipadx="110") 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 = CTkComboBox(master=app, values=list(tabs.keys()))
tab_combobox.set(list(tabs.keys())[0]) tab_combobox.set(list(tabs.keys())[0])