Add crude TOC display

This commit is contained in:
Rahix 2024-08-19 02:42:27 +02:00
parent 0d9dbd7cb4
commit e30421fab9

View file

@ -30,11 +30,20 @@ def main() -> None:
frm = ttk.Frame(root, padding=10) frm = ttk.Frame(root, padding=10)
frm.grid() frm.grid()
columns = ("title", "page")
toc_tree = ttk.Treeview(frm, columns=columns, show="headings")
toc_tree.heading("title", text="Title")
toc_tree.heading("page", text="Page")
toc_tree.grid(column=0, row=1)
for lvl, t, p in toc:
toc_tree.insert("", tkinter.END, values=(" " * lvl + t, str(p)))
page_title = ttk.Label(frm) page_title = ttk.Label(frm)
page_title.grid(column=1, row=0) page_title.grid(column=2, row=0)
page_view = ttk.Label(frm) page_view = ttk.Label(frm)
page_view.grid(column=1, row=1) page_view.grid(column=2, row=1)
def load_page(page_num: int): def load_page(page_num: int):
page = doc[page_num] page = doc[page_num]
@ -58,8 +67,8 @@ def main() -> None:
CURRENT_PAGE -= 1 CURRENT_PAGE -= 1
load_page(CURRENT_PAGE) load_page(CURRENT_PAGE)
ttk.Button(frm, text="Previous", command=previous_page).grid(column=0, row=1) ttk.Button(frm, text="Previous", command=previous_page).grid(column=1, row=1)
ttk.Button(frm, text="Next", command=next_page).grid(column=2, row=1) ttk.Button(frm, text="Next", command=next_page).grid(column=3, row=1)
load_page(CURRENT_PAGE) load_page(CURRENT_PAGE)