add key bindings for scrolling
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
import tkinter
|
||||||
from .gui import NoteViewer
|
from .gui import NoteViewer
|
||||||
from .data import Notes
|
from .data import Notes
|
||||||
|
|
||||||
# Load notes
|
# Load notes
|
||||||
notes = Notes("testdata")
|
notes = Notes("testdata")
|
||||||
# View them
|
# View them
|
||||||
viewer = NoteViewer(notes)
|
root = tkinter.Tk()
|
||||||
|
viewer = NoteViewer(notes, master=root)
|
||||||
viewer.run()
|
viewer.run()
|
||||||
|
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ class Notes(dict):
|
|||||||
def load(self, source):
|
def load(self, source):
|
||||||
if source is "testdata":
|
if source is "testdata":
|
||||||
for note in extract_test():
|
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 """
|
""" Inserts a new note """
|
||||||
# Track existing categories
|
# Track existing categories
|
||||||
if not category in self.categories:
|
if not category in self.categories:
|
||||||
@@ -81,6 +82,7 @@ class Notes(dict):
|
|||||||
if not category in self[person]:
|
if not category in self[person]:
|
||||||
self[person][category] = {}
|
self[person][category] = {}
|
||||||
# Insertion
|
# Insertion
|
||||||
|
note = (time, text)
|
||||||
if not date in self[person][category]:
|
if not date in self[person][category]:
|
||||||
self[person][category][date] = [note]
|
self[person][category][date] = [note]
|
||||||
else:
|
else:
|
||||||
|
|||||||
25
xerus/gui.py
25
xerus/gui.py
@@ -30,9 +30,23 @@ class NoteViewer(tk.Frame):
|
|||||||
self.notes = notes
|
self.notes = notes
|
||||||
|
|
||||||
def run(self):
|
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()
|
self.mainloop()
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notes(self):
|
def notes(self):
|
||||||
return self.__notes
|
return self.__notes
|
||||||
@@ -49,6 +63,7 @@ class NoteViewer(tk.Frame):
|
|||||||
self.refresh_text(None)
|
self.refresh_text(None)
|
||||||
|
|
||||||
def refresh_text(self, event):
|
def refresh_text(self, event):
|
||||||
|
print("Refresh text :", event)
|
||||||
self.text.config(state=tk.NORMAL)
|
self.text.config(state=tk.NORMAL)
|
||||||
self.text.delete(1.0, tk.END)
|
self.text.delete(1.0, tk.END)
|
||||||
try:
|
try:
|
||||||
@@ -103,13 +118,13 @@ class NoteViewer(tk.Frame):
|
|||||||
# Text view
|
# Text view
|
||||||
textView = tk.Frame(self)
|
textView = tk.Frame(self)
|
||||||
textView.pack(fill=tk.BOTH, expand=True)
|
textView.pack(fill=tk.BOTH, expand=True)
|
||||||
scrollbar = tk.Scrollbar(textView)
|
self.scrollbar = tk.Scrollbar(textView)
|
||||||
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||||
self.text = tk.Text(textView, yscrollcommand=scrollbar.set)
|
self.text = tk.Text(textView, yscrollcommand=self.scrollbar.set)
|
||||||
self.text.tag_config("d", underline=1) # Dates
|
self.text.tag_config("d", underline=1) # Dates
|
||||||
self.text.tag_config("t", foreground="grey") # Times
|
self.text.tag_config("t", foreground="grey") # Times
|
||||||
self.text.pack(fill=tk.BOTH, expand=True)
|
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