File structure organised
42
GUI.py
@@ -1,42 +0,0 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from PIL import Image, ImageTk # Pillow je nutné mít nainstalované
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
root.title("Treeview s checkboxy")
|
||||
|
||||
tree = ttk.Treeview(root)
|
||||
tree.pack(fill="both", expand=True)
|
||||
|
||||
# Funkce pro načtení a zmenšení obrázku na 16x16
|
||||
def load_icon(path):
|
||||
img = Image.open(path)
|
||||
img = img.resize((16, 16), Image.Resampling.LANCZOS)
|
||||
return ImageTk.PhotoImage(img)
|
||||
|
||||
unchecked = load_icon("/home/honza/Documents/Tagger/src/images/32/32_unchecked.png")
|
||||
checked = load_icon("/home/honza/Documents/Tagger/src/images/32/32_checked.png")
|
||||
|
||||
# Slovník pro ukládání stavů
|
||||
states = {}
|
||||
|
||||
# Přidání uzlu se stavem
|
||||
item = tree.insert("", "end", text="Položka 1", image=unchecked)
|
||||
states[item] = False
|
||||
|
||||
# Funkce pro přepnutí checkboxu
|
||||
def toggle(event):
|
||||
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=checked if states[item_id] else unchecked)
|
||||
|
||||
tree.bind("<Button-1>", toggle)
|
||||
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
77
Tagger.py
@@ -1,79 +1,6 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
root.title("Ukázka rozložení")
|
||||
root.geometry("800x600")
|
||||
from src.gui.gui import main
|
||||
|
||||
# ==== 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)
|
||||
|
||||
# ==== VLEVO: STROM ====
|
||||
tree = ttk.Treeview(main_frame)
|
||||
tree.grid(row=0, column=0, sticky="nsew", padx=2, pady=2)
|
||||
|
||||
root_node = tree.insert("", "end", text="Root")
|
||||
tree.insert(root_node, "end", text="Child 1")
|
||||
tree.insert(root_node, "end", text="Child 2")
|
||||
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()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
0
src/__init__.py
Normal file
BIN
src/__pycache__/__init__.cpython-313.pyc
Normal file
0
src/core/SQL_handler.py
Normal file
0
src/core/__init__.py
Normal file
BIN
src/core/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
src/core/__pycache__/image_handler.cpython-313.pyc
Normal file
0
src/core/file_handler.py
Normal file
6
src/core/image_handler.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
def load_icon(path):
|
||||
img = Image.open(path)
|
||||
img = img.resize((16, 16), Image.Resampling.LANCZOS)
|
||||
return ImageTk.PhotoImage(img)
|
||||
0
src/gui/__init__.py
Normal file
BIN
src/gui/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
src/gui/__pycache__/gui.cpython-313.pyc
Normal file
105
src/gui/gui.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from src.core.image_handler import load_icon
|
||||
|
||||
def main():
|
||||
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):
|
||||
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: # 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()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Before Width: | Height: | Size: 596 B After Width: | Height: | Size: 596 B |
|
Before Width: | Height: | Size: 892 B After Width: | Height: | Size: 892 B |
|
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 618 B |
|
Before Width: | Height: | Size: 961 B After Width: | Height: | Size: 961 B |
|
Before Width: | Height: | Size: 710 B After Width: | Height: | Size: 710 B |
|
Before Width: | Height: | Size: 716 B After Width: | Height: | Size: 716 B |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |