# Module header import sys if __name__ == "__main__": sys.exit("This module is not intended to be executed as the main program.") # Imports 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") # ==== MENU ==== menu_bar = tk.Menu(root) root.config(menu=menu_bar) 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) # ==== HLAVNÍ RÁM ==== main_frame = tk.Frame(root) main_frame.pack(fill="both", expand=True) main_frame.columnconfigure(0, weight=1) main_frame.columnconfigure(1, weight=2) main_frame.rowconfigure(0, weight=1) # ==== 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} # ==== VLEVO: STROM ==== tree = ttk.Treeview(main_frame) tree.grid(row=0, column=0, sticky="nsew", padx=2, pady=2) # 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("", 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: # 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("", tree_right_click) listbox.bind("", list_right_click) root.mainloop()