Add a dialog for adding a link
This commit is contained in:
parent
45ccacfa2a
commit
635800b923
34
src/main.py
34
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
|
||||
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("<ButtonPress>", start_rect)
|
||||
page_view.bind("<ButtonRelease>", 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("<Up>", lambda _: previous_page())
|
||||
root.bind("<Left>", lambda _: previous_page())
|
||||
|
@ -92,8 +119,7 @@ def main() -> None:
|
|||
root.bind("<Right>", lambda _: next_page())
|
||||
root.bind("<Next>", lambda _: next_page())
|
||||
|
||||
# Broken:
|
||||
# root.bind("<Control-W>", lambda _: root.destroy)
|
||||
root.bind("<Control-w>", lambda _: root.destroy())
|
||||
|
||||
load_page(CURRENT_PAGE)
|
||||
|
||||
|
|
Loading…
Reference in a new issue