left tabs swtitching

This commit is contained in:
dez 2024-03-01 13:28:54 +01:00
parent e29f985a45
commit 980c148b29

81
src/gui_left_tabs.py Normal file
View file

@ -0,0 +1,81 @@
import threading
import math
from tkinter import Canvas, Tk, Frame, Button
# Modified code
root = Tk()
root.geometry("1000x600")
from gui_starfield import StarField # Assuming gui_starfield.py contains the StarField class
container_x = -320
col_isDark = True
current_container = None # To keep track of the current container
close_finished_event = threading.Event()
def open_container():
global container_x
if container_x < 0:
container_x += 5
current_container.place(x=container_x, y=0)
if container_x >= 0:
pass # If you need to execute something when the container is fully open, add it here
else:
root.after(5, open_container)
def close_container():
global container_x
global close_finished_event
if current_container:
container_x -= 5
current_container.place(x=container_x, y=0)
if container_x <= -320:
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
else:
root.after(5, close_container)
def switch_to_tab(tab_name):
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.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)
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)
else:
print("Unknown tab name:", tab_name)
open_container() # Open the new container
def switch_to_tab_threaded(tab_name):
thread = threading.Thread(target=lambda: switch_to_tab(tab_name))
thread.start()
# Widgets
container = Frame(root, width=320, height=600, bg="black", relief="flat")
container.place(x=-320, y=0)
btn_starfield = Button(root, text="Switch to Starfield", command=lambda: switch_to_tab_threaded("Starfield"))
btn_starfield.place(x=500, y=50)
btn_blocking = Button(root, text="Switch to Blocking", command=lambda: switch_to_tab_threaded("Blocking"))
btn_blocking.place(x=500, y=100)
root.mainloop()