Improvements
This commit is contained in:
@@ -2,8 +2,8 @@ import urwid
|
|||||||
from lineWalker import LineWalker
|
from lineWalker import LineWalker
|
||||||
import uuid
|
import uuid
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import mainUI
|
||||||
|
import pdb
|
||||||
|
|
||||||
class EditorUI(object):
|
class EditorUI(object):
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class EditorUI(object):
|
|||||||
|
|
||||||
self.filename = filename
|
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.walker = LineWalker(filename)
|
||||||
self.content = urwid.ListBox(self.walker)
|
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"),
|
self.palette = [("standard", "light blue", "black"),
|
||||||
("warning", "yellow", "black")]
|
("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)
|
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()
|
self.loop.run()
|
||||||
|
return 0
|
||||||
|
|
||||||
def keypress_handler(self, key):
|
def keypress_handler(self, key):
|
||||||
|
|
||||||
if key == "meta q":
|
if key == "meta q":
|
||||||
|
if not self.callback:
|
||||||
raise urwid.ExitMainLoop()
|
raise urwid.ExitMainLoop()
|
||||||
|
else:
|
||||||
|
#mainUI.MainUI().open(self.loop)
|
||||||
|
self.callback(self.loop)
|
||||||
|
|
||||||
elif key == "meta s":
|
elif key == "meta y":
|
||||||
self.save(self.filename)
|
self.save(self.filename, verbose = True)
|
||||||
|
|
||||||
elif key == "delete":
|
elif key == "delete":
|
||||||
# delete at end of line
|
# delete at end of line
|
||||||
@@ -66,7 +88,7 @@ class EditorUI(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self, save_filename):
|
def save(self, save_filename, verbose = False):
|
||||||
walker = self.walker
|
walker = self.walker
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
@@ -78,15 +100,16 @@ class EditorUI(object):
|
|||||||
|
|
||||||
while walker.file is not None:
|
while walker.file is not None:
|
||||||
lines.append(walker.read_next_line())
|
lines.append(walker.read_next_line())
|
||||||
|
#pdb.set_trace()
|
||||||
file_handle = open(save_filename, "w")
|
file_handle = open(save_filename, "w")
|
||||||
|
|
||||||
|
|
||||||
prefix = ""
|
prefix = ""
|
||||||
for line in lines:
|
for line in lines:
|
||||||
file_handle.write(line)
|
file_handle.write(prefix + line)
|
||||||
prefix = "\n"
|
prefix = "\n"
|
||||||
|
|
||||||
|
if verbose:
|
||||||
self.central_frame.footer = urwid.AttrWrap(urwid.Text(save_filename + " saved."), "warning")
|
self.central_frame.footer = urwid.AttrWrap(urwid.Text(save_filename + " saved."), "warning")
|
||||||
self.loop.draw_screen()
|
self.loop.draw_screen()
|
||||||
sleep(2)
|
sleep(2)
|
||||||
|
|||||||
36
src/main.py
36
src/main.py
@@ -1,7 +1,37 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import editorUI
|
import mainUI
|
||||||
|
import getopt
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
import editorUI
|
||||||
|
import urwid
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
ui=editorUI.EditorUI("quicknotes/" + str(uuid4()) + ".txt")
|
def new_quicknote():
|
||||||
ui.main()
|
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 urwid
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class fileIndexer(object):
|
class SelectionDialog(object):
|
||||||
|
|
||||||
def menu(self, title, choices):
|
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:
|
for c in choices:
|
||||||
button = urwid.Button(c)
|
button = urwid.Button(c)
|
||||||
urwid.connect_signal(button, 'click', self.item_chosen, c)
|
urwid.connect_signal(button, 'click', self.item_chosen, c)
|
||||||
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
|
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
|
||||||
|
body.append(urwid.Text("------"))
|
||||||
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
|
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
|
||||||
|
|
||||||
def item_chosen(self, button, choice):
|
def item_chosen(self, button, choice):
|
||||||
self.choice = choice
|
self.choice = choice
|
||||||
response = urwid.Text([u'You chose ', choice, u'\n'])
|
self.exit_program()
|
||||||
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')]))
|
|
||||||
|
|
||||||
def exit_program(self, button):
|
def exit_program(self):
|
||||||
raise urwid.ExitMainLoop()
|
raise urwid.ExitMainLoop()
|
||||||
|
|
||||||
def __init__ (self, title, choices):
|
def __init__ (self, title, choices, width = 60, height = 60):
|
||||||
self.mainpd = urwid.Padding(self.menu(title, choices), left=2, right=2)
|
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}'),
|
self.top = urwid.Overlay(self.mainpd, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
|
||||||
align='center', width=('relative', 60),
|
align='center', width=('relative', 60),
|
||||||
valign='middle', height=('relative', 60),
|
valign='middle', height=('relative', 60),
|
||||||
min_width=20, min_height=9)
|
min_width=20, min_height=9)
|
||||||
|
|
||||||
def start(self):
|
bt = urwid.BigText("Notology.", urwid.font.HalfBlock5x4Font())
|
||||||
urwid.MainLoop(self.top, palette=[('reversed', 'standout', '')]).run()
|
bt = urwid.Padding(bt, "center", width = "clip")
|
||||||
return self.choice
|
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