Improvements
This commit is contained in:
@@ -2,8 +2,8 @@ import urwid
|
||||
from lineWalker import LineWalker
|
||||
import uuid
|
||||
from time import sleep
|
||||
|
||||
|
||||
import mainUI
|
||||
import pdb
|
||||
|
||||
class EditorUI(object):
|
||||
|
||||
@@ -13,7 +13,7 @@ class EditorUI(object):
|
||||
|
||||
self.filename = filename
|
||||
|
||||
self.default_footer = urwid.AttrWrap(urwid.Text("<Alt + s> Save as | <Alt + q> Close"), "standard")
|
||||
self.default_footer = urwid.AttrWrap(urwid.Text("<Alt + y> Save as | <Alt + q> Close"), "standard")
|
||||
|
||||
self.walker = LineWalker(filename)
|
||||
self.content = urwid.ListBox(self.walker)
|
||||
@@ -24,19 +24,41 @@ class EditorUI(object):
|
||||
|
||||
|
||||
|
||||
def main(self):
|
||||
def open(self, loop = None, callback = None, quicknote = False):
|
||||
|
||||
if quicknote:
|
||||
self.central_frame.set_header(urwid.AttrWrap(urwid.Text("Notology Quicknote\n" + self.filename, align = "center"), "header"))
|
||||
|
||||
self.callback = callback
|
||||
self.palette = [("standard", "light blue", "black"),
|
||||
("warning", "yellow", "black")]
|
||||
self.loop = urwid.MainLoop(self.central_frame, self.palette, unhandled_input = self.keypress_handler)
|
||||
self.loop.run()
|
||||
("warning", "yellow", "black"),
|
||||
("header", "black", "dark blue")]
|
||||
fresh = False
|
||||
if loop == None:
|
||||
self.loop = urwid.MainLoop(self.central_frame, self.palette, unhandled_input = self.keypress_handler)
|
||||
fresh = True
|
||||
else:
|
||||
loop.widget = self.central_frame
|
||||
loop.unhandled_input = self.keypress_handler
|
||||
loop.screen.register_palette(self.palette)
|
||||
loop.draw_screen()
|
||||
self.loop = loop
|
||||
|
||||
if fresh:
|
||||
self.loop.run()
|
||||
return 0
|
||||
|
||||
def keypress_handler(self, key):
|
||||
|
||||
if key == "meta q":
|
||||
raise urwid.ExitMainLoop()
|
||||
if not self.callback:
|
||||
raise urwid.ExitMainLoop()
|
||||
else:
|
||||
#mainUI.MainUI().open(self.loop)
|
||||
self.callback(self.loop)
|
||||
|
||||
elif key == "meta s":
|
||||
self.save(self.filename)
|
||||
elif key == "meta y":
|
||||
self.save(self.filename, verbose = True)
|
||||
|
||||
elif key == "delete":
|
||||
# delete at end of line
|
||||
@@ -66,7 +88,7 @@ class EditorUI(object):
|
||||
|
||||
return True
|
||||
|
||||
def save(self, save_filename):
|
||||
def save(self, save_filename, verbose = False):
|
||||
walker = self.walker
|
||||
lines = []
|
||||
|
||||
@@ -78,19 +100,20 @@ class EditorUI(object):
|
||||
|
||||
while walker.file is not None:
|
||||
lines.append(walker.read_next_line())
|
||||
|
||||
#pdb.set_trace()
|
||||
file_handle = open(save_filename, "w")
|
||||
|
||||
|
||||
prefix = ""
|
||||
for line in lines:
|
||||
file_handle.write(line)
|
||||
file_handle.write(prefix + line)
|
||||
prefix = "\n"
|
||||
|
||||
self.central_frame.footer = urwid.AttrWrap(urwid.Text(save_filename + " saved."), "warning")
|
||||
self.loop.draw_screen()
|
||||
sleep(2)
|
||||
self.central_frame.footer = self.default_footer
|
||||
if verbose:
|
||||
self.central_frame.footer = urwid.AttrWrap(urwid.Text(save_filename + " saved."), "warning")
|
||||
self.loop.draw_screen()
|
||||
sleep(2)
|
||||
self.central_frame.footer = self.default_footer
|
||||
|
||||
def re_tab(s):
|
||||
"""Return a tabbed string from an expanded one."""
|
||||
|
||||
36
src/main.py
36
src/main.py
@@ -1,7 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import editorUI
|
||||
import mainUI
|
||||
import getopt
|
||||
from uuid import uuid4
|
||||
import editorUI
|
||||
import urwid
|
||||
import sys
|
||||
import os
|
||||
|
||||
ui=editorUI.EditorUI("quicknotes/" + str(uuid4()) + ".txt")
|
||||
ui.main()
|
||||
def new_quicknote():
|
||||
path = os.path.expanduser("~") + "/.notology/quicknotes/"
|
||||
filename = path + str(uuid4()) + ".txt"
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
editorUI.EditorUI(filename).open(quicknote = True)
|
||||
|
||||
def main():
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "q", ["quicknote"])
|
||||
except getopt.GetoptError as err:
|
||||
# print help information and exit:
|
||||
print(err)
|
||||
sys.exit(2)
|
||||
if not opts:
|
||||
mainUI.MainUI().open()
|
||||
|
||||
for o, a in opts:
|
||||
if o in ("-q", "--quicknote"):
|
||||
print("New quicknote")
|
||||
new_quicknote()
|
||||
else:
|
||||
assert False, "unhandled option"
|
||||
#print(mainUI.MainUI().open())
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,35 +1,44 @@
|
||||
import urwid
|
||||
import sys
|
||||
|
||||
class fileIndexer(object):
|
||||
class SelectionDialog(object):
|
||||
|
||||
def menu(self, title, choices):
|
||||
body = [urwid.Text(title), urwid.Divider()]
|
||||
body = [ urwid.Text(title, align = "center"), urwid.Divider()]
|
||||
'''headline = urwid.BigText("Notology", None)
|
||||
headline = urwid.Padding(headline)
|
||||
headline = urwid.Filler(headline, "bottom", None, 7)
|
||||
headline = urwid.BoxAdapter(headline, 7)
|
||||
body.append(headline)'''
|
||||
for c in choices:
|
||||
button = urwid.Button(c)
|
||||
urwid.connect_signal(button, 'click', self.item_chosen, c)
|
||||
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
|
||||
body.append(urwid.Text("------"))
|
||||
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
|
||||
|
||||
def item_chosen(self, button, choice):
|
||||
self.choice = choice
|
||||
response = urwid.Text([u'You chose ', choice, u'\n'])
|
||||
done = urwid.Button(u'Ok')
|
||||
urwid.connect_signal(done, 'click', self.exit_program)
|
||||
self.mainpd.original_widget = urwid.Filler(urwid.Pile([response,
|
||||
urwid.AttrMap(done, None, focus_map='reversed')]))
|
||||
self.exit_program()
|
||||
|
||||
def exit_program(self, button):
|
||||
def exit_program(self):
|
||||
raise urwid.ExitMainLoop()
|
||||
|
||||
def __init__ (self, title, choices):
|
||||
self.mainpd = urwid.Padding(self.menu(title, choices), left=2, right=2)
|
||||
def __init__ (self, title, choices, width = 60, height = 60):
|
||||
self.choices = choices
|
||||
self.mainpd = urwid.Padding(self.menu(title, choices), left=1, right=1)
|
||||
self.top = urwid.Overlay(self.mainpd, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
|
||||
align='center', width=('relative', 60),
|
||||
valign='middle', height=('relative', 60),
|
||||
min_width=20, min_height=9)
|
||||
|
||||
def start(self):
|
||||
urwid.MainLoop(self.top, palette=[('reversed', 'standout', '')]).run()
|
||||
return self.choice
|
||||
bt = urwid.BigText("Notology.", urwid.font.HalfBlock5x4Font())
|
||||
bt = urwid.Padding(bt, "center", width = "clip")
|
||||
bt = urwid.Filler(bt, "bottom")
|
||||
bt = urwid.BoxAdapter(bt, height = 5)
|
||||
self.main_frame = urwid.Frame(self.top, header = bt)
|
||||
|
||||
def start(self):
|
||||
urwid.MainLoop(self.main_frame, palette=[('reversed', 'standout', '')]).run()
|
||||
return self.choices.index(self.choice)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user