add key bindings for scrolling
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
25
xerus/gui.py
25
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("<Down>", scroll_down)
|
||||
self.bind_all("j", scroll_down)
|
||||
self.bind_all("<Up>", 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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user