From b4ff65c86a1e0a2a8c9a82a0780c72fbb06b7cd2 Mon Sep 17 00:00:00 2001 From: Artus Date: Sun, 5 Apr 2020 21:41:15 +0200 Subject: [PATCH] add key bindings for scrolling --- xerus/__main__.py | 4 +++- xerus/data.py | 6 ++++-- xerus/gui.py | 25 ++++++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/xerus/__main__.py b/xerus/__main__.py index 6c791c8..735aff8 100644 --- a/xerus/__main__.py +++ b/xerus/__main__.py @@ -1,11 +1,13 @@ # -*- coding:utf-8 -*- +import tkinter from .gui import NoteViewer from .data import Notes # Load notes notes = Notes("testdata") # View them -viewer = NoteViewer(notes) +root = tkinter.Tk() +viewer = NoteViewer(notes, master=root) viewer.run() diff --git a/xerus/data.py b/xerus/data.py index fce50f2..6dfd3bf 100644 --- a/xerus/data.py +++ b/xerus/data.py @@ -68,9 +68,10 @@ class Notes(dict): def load(self, source): if source is "testdata": for note in extract_test(): - self.insert(note.person, note.category, note.date, (note.time, note.text)) + self.insert(note.person, note.category, note.date + , time=note.time, text=note.text) - def insert(self, person, category, date, note): + def insert(self, person, category, date, time=None, author=None, text=None): """ Inserts a new note """ # Track existing categories if not category in self.categories: @@ -81,6 +82,7 @@ class Notes(dict): if not category in self[person]: self[person][category] = {} # Insertion + note = (time, text) if not date in self[person][category]: self[person][category][date] = [note] else: diff --git a/xerus/gui.py b/xerus/gui.py index c503a89..22bff0e 100644 --- a/xerus/gui.py +++ b/xerus/gui.py @@ -30,9 +30,23 @@ class NoteViewer(tk.Frame): self.notes = notes def run(self): - """ Launch the viewer """ + """ Configure and launch the viewer """ + + # Events + def scroll_down(event): + self.text.yview_scroll(1, "units") + + def scroll_up(event): + self.text.yview_scroll(-1, "units") + + self.bind_all("", scroll_down) + self.bind_all("j", scroll_down) + self.bind_all("", scroll_up) + self.bind_all("k", scroll_up) + # Enter loop self.mainloop() + @property def notes(self): return self.__notes @@ -49,6 +63,7 @@ class NoteViewer(tk.Frame): self.refresh_text(None) def refresh_text(self, event): + print("Refresh text :", event) self.text.config(state=tk.NORMAL) self.text.delete(1.0, tk.END) try: @@ -103,13 +118,13 @@ class NoteViewer(tk.Frame): # Text view textView = tk.Frame(self) textView.pack(fill=tk.BOTH, expand=True) - scrollbar = tk.Scrollbar(textView) - scrollbar.pack(side=tk.RIGHT, fill=tk.Y) - self.text = tk.Text(textView, yscrollcommand=scrollbar.set) + self.scrollbar = tk.Scrollbar(textView) + self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y) + self.text = tk.Text(textView, yscrollcommand=self.scrollbar.set) self.text.tag_config("d", underline=1) # Dates self.text.tag_config("t", foreground="grey") # Times self.text.pack(fill=tk.BOTH, expand=True) - scrollbar.config(command=self.text.yview) + self.scrollbar.config(command=self.text.yview)