Task list navigation working

This commit is contained in:
Aaron Gutierrez
2015-07-19 18:00:27 -07:00
parent fd0d619fa8
commit b07ca5c78a
4 changed files with 74 additions and 11 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
*.pyc
.config
urwid-src

3
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "python-asana"]
path = python-asana
url = git@github.com:Asana/python-asana.git
[submodule "urwid"]
path = urwid
url = ./urwid

View File

@@ -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()

57
ui.py Normal file
View File

@@ -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