Dataclasses WIP
This commit is contained in:
177
src/gui/gui.py
177
src/gui/gui.py
@@ -9,102 +9,105 @@ import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from src.core.image_handler import load_icon
|
||||
|
||||
# Functions
|
||||
def main() -> None:
|
||||
root = tk.Tk()
|
||||
root.title("Ukázka rozložení")
|
||||
root.geometry("800x600")
|
||||
class App():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# ==== MENU ====
|
||||
menu_bar = tk.Menu(root)
|
||||
root.config(menu=menu_bar)
|
||||
def main(self) -> None:
|
||||
root = tk.Tk()
|
||||
root.title("Ukázka rozložení")
|
||||
root.geometry("800x600")
|
||||
|
||||
file_menu = tk.Menu(menu_bar, tearoff=0)
|
||||
file_menu.add_command(label="Otevřít")
|
||||
file_menu.add_command(label="Ukončit", command=root.quit)
|
||||
menu_bar.add_cascade(label="Soubor", menu=file_menu)
|
||||
# ==== MENU ====
|
||||
menu_bar = tk.Menu(root)
|
||||
root.config(menu=menu_bar)
|
||||
|
||||
# ==== HLAVNÍ RÁM ====
|
||||
main_frame = tk.Frame(root)
|
||||
main_frame.pack(fill="both", expand=True)
|
||||
file_menu = tk.Menu(menu_bar, tearoff=0)
|
||||
file_menu.add_command(label="Otevřít")
|
||||
file_menu.add_command(label="Ukončit", command=root.quit)
|
||||
menu_bar.add_cascade(label="Soubor", menu=file_menu)
|
||||
|
||||
main_frame.columnconfigure(0, weight=1)
|
||||
main_frame.columnconfigure(1, weight=2)
|
||||
main_frame.rowconfigure(0, weight=1)
|
||||
# ==== HLAVNÍ RÁM ====
|
||||
main_frame = tk.Frame(root)
|
||||
main_frame.pack(fill="both", expand=True)
|
||||
|
||||
# ==== Ikony ====
|
||||
unchecked = load_icon("src/resources/images/32/32_unchecked.png")
|
||||
checked = load_icon("src/resources/images/32/32_checked.png")
|
||||
icons = {"unchecked": unchecked, "checked": checked}
|
||||
main_frame.columnconfigure(0, weight=1)
|
||||
main_frame.columnconfigure(1, weight=2)
|
||||
main_frame.rowconfigure(0, weight=1)
|
||||
|
||||
# ==== VLEVO: STROM ====
|
||||
tree = ttk.Treeview(main_frame)
|
||||
tree.grid(row=0, column=0, sticky="nsew", padx=2, pady=2)
|
||||
# ==== Ikony ====
|
||||
unchecked = load_icon("src/resources/images/32/32_unchecked.png")
|
||||
checked = load_icon("src/resources/images/32/32_checked.png")
|
||||
icons = {"unchecked": unchecked, "checked": checked}
|
||||
|
||||
# Slovník pro stavy checkboxů
|
||||
states = {}
|
||||
# ==== VLEVO: STROM ====
|
||||
tree = ttk.Treeview(main_frame)
|
||||
tree.grid(row=0, column=0, sticky="nsew", padx=2, pady=2)
|
||||
|
||||
# Funkce pro přepnutí checkboxu
|
||||
def toggle(event) -> None:
|
||||
region = tree.identify("region", event.x, event.y)
|
||||
if region == "tree":
|
||||
# Slovník pro stavy checkboxů
|
||||
states = {}
|
||||
|
||||
# Funkce pro přepnutí checkboxu
|
||||
def toggle(event) -> None:
|
||||
region = tree.identify("region", event.x, event.y)
|
||||
if region == "tree":
|
||||
item_id = tree.identify_row(event.y)
|
||||
if item_id:
|
||||
states[item_id] = not states[item_id]
|
||||
tree.item(item_id, image=icons["checked"] if states[item_id] else icons["unchecked"])
|
||||
|
||||
tree.bind("<Button-1>", toggle)
|
||||
|
||||
# Přidání uzlů se stavem
|
||||
root_node = tree.insert("", "end", text="Root", image=icons["unchecked"])
|
||||
states[root_node] = False
|
||||
|
||||
child1 = tree.insert(root_node, "end", text="Child 1", image=icons["unchecked"])
|
||||
states[child1] = False
|
||||
child2 = tree.insert(root_node, "end", text="Child 2", image=icons["unchecked"])
|
||||
states[child2] = False
|
||||
|
||||
tree.item(root_node, open=True)
|
||||
|
||||
# ==== VPRAVO: SEZNAM ====
|
||||
listbox = tk.Listbox(main_frame)
|
||||
listbox.grid(row=0, column=1, sticky="nsew", padx=2, pady=2)
|
||||
|
||||
for i in range(1, 21):
|
||||
listbox.insert("end", f"Položka {i}")
|
||||
|
||||
# ==== STAVOVÝ ŘÁDEK ====
|
||||
status_bar = tk.Label(root, text="Připraven", anchor="w", relief="sunken")
|
||||
status_bar.pack(side="bottom", fill="x")
|
||||
|
||||
# ==== KONTEXTOVÁ MENU ====
|
||||
tree_menu = tk.Menu(root, tearoff=0)
|
||||
tree_menu.add_command(
|
||||
label="Akce na stromu",
|
||||
command=lambda: status_bar.config(text="Klikl jsi na strom")
|
||||
)
|
||||
|
||||
list_menu = tk.Menu(root, tearoff=0)
|
||||
list_menu.add_command(
|
||||
label="Akce na seznamu",
|
||||
command=lambda: status_bar.config(text="Klikl jsi na seznam")
|
||||
)
|
||||
|
||||
# ==== HANDLERY ====
|
||||
def tree_right_click(event):
|
||||
item_id = tree.identify_row(event.y)
|
||||
if item_id:
|
||||
states[item_id] = not states[item_id]
|
||||
tree.item(item_id, image=icons["checked"] if states[item_id] else icons["unchecked"])
|
||||
if item_id: # klik na uzel
|
||||
tree.selection_set(item_id)
|
||||
tree_menu.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
tree.bind("<Button-1>", toggle)
|
||||
def list_right_click(event):
|
||||
index = listbox.nearest(event.y)
|
||||
if index >= 0: # klik na položku
|
||||
listbox.selection_clear(0, "end")
|
||||
listbox.selection_set(index)
|
||||
list_menu.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
# Přidání uzlů se stavem
|
||||
root_node = tree.insert("", "end", text="Root", image=icons["unchecked"])
|
||||
states[root_node] = False
|
||||
tree.bind("<Button-3>", tree_right_click)
|
||||
listbox.bind("<Button-3>", list_right_click)
|
||||
|
||||
child1 = tree.insert(root_node, "end", text="Child 1", image=icons["unchecked"])
|
||||
states[child1] = False
|
||||
child2 = tree.insert(root_node, "end", text="Child 2", image=icons["unchecked"])
|
||||
states[child2] = False
|
||||
|
||||
tree.item(root_node, open=True)
|
||||
|
||||
# ==== VPRAVO: SEZNAM ====
|
||||
listbox = tk.Listbox(main_frame)
|
||||
listbox.grid(row=0, column=1, sticky="nsew", padx=2, pady=2)
|
||||
|
||||
for i in range(1, 21):
|
||||
listbox.insert("end", f"Položka {i}")
|
||||
|
||||
# ==== STAVOVÝ ŘÁDEK ====
|
||||
status_bar = tk.Label(root, text="Připraven", anchor="w", relief="sunken")
|
||||
status_bar.pack(side="bottom", fill="x")
|
||||
|
||||
# ==== KONTEXTOVÁ MENU ====
|
||||
tree_menu = tk.Menu(root, tearoff=0)
|
||||
tree_menu.add_command(
|
||||
label="Akce na stromu",
|
||||
command=lambda: status_bar.config(text="Klikl jsi na strom")
|
||||
)
|
||||
|
||||
list_menu = tk.Menu(root, tearoff=0)
|
||||
list_menu.add_command(
|
||||
label="Akce na seznamu",
|
||||
command=lambda: status_bar.config(text="Klikl jsi na seznam")
|
||||
)
|
||||
|
||||
# ==== HANDLERY ====
|
||||
def tree_right_click(event):
|
||||
item_id = tree.identify_row(event.y)
|
||||
if item_id: # klik na uzel
|
||||
tree.selection_set(item_id)
|
||||
tree_menu.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
def list_right_click(event):
|
||||
index = listbox.nearest(event.y)
|
||||
if index >= 0: # klik na položku
|
||||
listbox.selection_clear(0, "end")
|
||||
listbox.selection_set(index)
|
||||
list_menu.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
tree.bind("<Button-3>", tree_right_click)
|
||||
listbox.bind("<Button-3>", list_right_click)
|
||||
|
||||
root.mainloop()
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user