diff --git a/.gitignore b/.gitignore index f64ecad..87b62ae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pyc .config +urwid-src diff --git a/.gitmodules b/.gitmodules index 356a565..6bc49c6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "python-asana"] path = python-asana url = git@github.com:Asana/python-asana.git -[submodule "urwid"] - path = urwid - url = ./urwid diff --git a/cmdasana.py b/cmdasana.py index c242424..7fac8f8 100644 --- a/cmdasana.py +++ b/cmdasana.py @@ -1,7 +1,11 @@ import os -import asana import json +import urwid +import asana + +import ui + class CmdAsana: ASANA_API_KEY = os.environ['ASANA_API_KEY'] @@ -21,26 +25,30 @@ class CmdAsana: return True def allMyTasks(self): + task_list = [] for workspace in self.me['workspaces']: if not self.shouldShowWorkspace(workspace['id']): continue - print "*" * 80 - print workspace['id'], ': ', workspace['name'], " Tasks" - print "*" * 80, "\n" - tasks = self.client.tasks.find_all(params={ 'assignee': self.me['id'], 'workspace': workspace['id'], 'completed_since': 'now' }) - for task in tasks: - print task['name'] + task_list += tasks + return task_list + +def handleInput(key): + if key in ('q', 'Q'): + raise urwid.ExitMainLoop() def main(): cmdasana = CmdAsana() + task_list = cmdasana.allMyTasks() + + loop = urwid.MainLoop(ui.TaskList(task_list), unhandled_input=handleInput) + loop.run() - cmdasana.allMyTasks() if __name__ == "__main__": main() diff --git a/ui.py b/ui.py new file mode 100644 index 0000000..499a60e --- /dev/null +++ b/ui.py @@ -0,0 +1,57 @@ +import urwid + +# TaskEdit modes +EDIT = 'edit' +LIST = 'list' + +class TaskList(urwid.ListBox): + def __init__(self, tasks): + self.tasks = tasks + task_widgets = urwid.Pile( + [TaskEdit(task) for task in tasks] + ) + + body = urwid.SimpleFocusListWalker([task_widgets]) + super(TaskList, self).__init__(body) + + def keypress(self, size, key): + # The ListBox will handle scrolling for us, so we trick it into thinking + # it's being passed arrow keys + if key == 'j': + key = 'down' + elif key == 'k': + key = 'up' + + key = super(TaskList, self).keypress(size, key) + + if key in ('q', 'Q'): + raise urwid.ExitMainLoop() + else: + return key + +class TaskEdit(urwid.Edit): + mode = LIST + def __init__(self, task): + super(TaskEdit, self).__init__(task["name"]) + + def keypress(self, size, key): + if self.mode == EDIT: + key = super(TaskEdit, self).keypress(size, key) + + if key == 'esc': + self.mode = LIST + self.set_caption(self.edit_text) + self.set_edit_text('') + else: + return key + else: + if key == 'i': + self.mode = EDIT + self.set_edit_text(self.caption) + self.set_caption('') + elif key == 'enter': + self.set_caption(self.caption + ' [done]') + elif key in ('l', 'tab'): + self.set_caption(self.caption + ' [details]') + else: + return key