Keyboard automation

This commit is contained in:
Rahix 2024-08-19 02:58:04 +02:00
parent 88ffc7ab30
commit 45ccacfa2a

View file

@ -27,6 +27,7 @@ def main() -> None:
last_title = t
root = tkinter.Tk()
root.title("PDF Navigation Annotator Tool")
frm = ttk.Frame(root, padding=10)
frm.grid()
@ -45,6 +46,19 @@ def main() -> None:
page_view = ttk.Label(frm)
page_view.grid(column=2, row=1)
def start_rect(event):
if event.num != 1:
return
print(f"DOWN @ {event.x}/{event.y}")
def end_rect(event):
if event.num != 1:
return
print(f"UP @ {event.x}/{event.y}")
page_view.bind("<ButtonPress>", start_rect)
page_view.bind("<ButtonRelease>", end_rect)
def load_page(page_num: int):
page = doc[page_num]
pix = page.get_pixmap()
@ -70,6 +84,17 @@ def main() -> None:
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())
root.bind("<Prior>", lambda _: previous_page())
root.bind("<Down>", lambda _: next_page())
root.bind("<Right>", lambda _: next_page())
root.bind("<Next>", lambda _: next_page())
# Broken:
# root.bind("<Control-W>", lambda _: root.destroy)
load_page(CURRENT_PAGE)
root.mainloop()