From 635800b923e0c12fd189ae91a90ccc494aade435 Mon Sep 17 00:00:00 2001 From: Rahix Date: Mon, 19 Aug 2024 03:14:54 +0200 Subject: [PATCH] Add a dialog for adding a link --- src/main.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 6d9dfa6..89ba508 100644 --- a/src/main.py +++ b/src/main.py @@ -6,6 +6,23 @@ from tkinter import ttk from PIL import Image, ImageTk CURRENT_PAGE = 0 +RECT_START = None + + +class AddLinkDialog: + def __init__(self, root, rect, toc) -> None: + self.top = tkinter.Toplevel(root) + frm = ttk.Frame(self.top, padding=10) + frm.grid() + + toc_values = list(t for _, t, _ in toc) + + ttk.Label(frm, text=f"Rectangle: {rect!r}").grid(column=0, row=0, columnspan=3) + ttk.Label(frm, text="Target:").grid(column=0, row=1) + entry = ttk.Entry(frm) + entry.grid(column=1, row=1, columnspan=2, sticky="EW") + ttk.Button(frm, text="Add", command=self.top.destroy).grid(column=2, row=2) + ttk.Button(frm, text="Cancel", command=self.top.destroy).grid(column=3, row=2) def main() -> None: @@ -47,14 +64,20 @@ def main() -> None: page_view.grid(column=2, row=1) def start_rect(event): + global RECT_START if event.num != 1: return print(f"DOWN @ {event.x}/{event.y}") + RECT_START = (event.x, event.y) def end_rect(event): + global RECT_START if event.num != 1: return - print(f"UP @ {event.x}/{event.y}") + if RECT_START is not None: + print(f"UP @ {event.x}/{event.y}") + AddLinkDialog(root, [*RECT_START, event.x, event.y], toc) + RECT_START = None page_view.bind("", start_rect) page_view.bind("", end_rect) @@ -81,8 +104,12 @@ def main() -> None: CURRENT_PAGE -= 1 load_page(CURRENT_PAGE) - ttk.Button(frm, text="Previous", command=previous_page).grid(column=1, row=1, sticky="NS", padx=5, pady=5) - ttk.Button(frm, text="Next", command=next_page).grid(column=3, row=1, sticky="NS", padx=5, pady=5) + ttk.Button(frm, text="Previous", command=previous_page).grid( + column=1, row=1, sticky="NS", padx=5, pady=5 + ) + ttk.Button(frm, text="Next", command=next_page).grid( + column=3, row=1, sticky="NS", padx=5, pady=5 + ) root.bind("", lambda _: previous_page()) root.bind("", lambda _: previous_page()) @@ -92,8 +119,7 @@ def main() -> None: root.bind("", lambda _: next_page()) root.bind("", lambda _: next_page()) - # Broken: - # root.bind("", lambda _: root.destroy) + root.bind("", lambda _: root.destroy()) load_page(CURRENT_PAGE)