Task list navigation working
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
.config
|
.config
|
||||||
|
urwid-src
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
|||||||
[submodule "python-asana"]
|
[submodule "python-asana"]
|
||||||
path = python-asana
|
path = python-asana
|
||||||
url = git@github.com:Asana/python-asana.git
|
url = git@github.com:Asana/python-asana.git
|
||||||
[submodule "urwid"]
|
|
||||||
path = urwid
|
|
||||||
url = ./urwid
|
|
||||||
|
|||||||
24
cmdasana.py
24
cmdasana.py
@@ -1,7 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
import asana
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import urwid
|
||||||
|
import asana
|
||||||
|
|
||||||
|
import ui
|
||||||
|
|
||||||
class CmdAsana:
|
class CmdAsana:
|
||||||
ASANA_API_KEY = os.environ['ASANA_API_KEY']
|
ASANA_API_KEY = os.environ['ASANA_API_KEY']
|
||||||
|
|
||||||
@@ -21,26 +25,30 @@ class CmdAsana:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def allMyTasks(self):
|
def allMyTasks(self):
|
||||||
|
task_list = []
|
||||||
for workspace in self.me['workspaces']:
|
for workspace in self.me['workspaces']:
|
||||||
if not self.shouldShowWorkspace(workspace['id']):
|
if not self.shouldShowWorkspace(workspace['id']):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print "*" * 80
|
|
||||||
print workspace['id'], ': ', workspace['name'], " Tasks"
|
|
||||||
print "*" * 80, "\n"
|
|
||||||
|
|
||||||
tasks = self.client.tasks.find_all(params={
|
tasks = self.client.tasks.find_all(params={
|
||||||
'assignee': self.me['id'],
|
'assignee': self.me['id'],
|
||||||
'workspace': workspace['id'],
|
'workspace': workspace['id'],
|
||||||
'completed_since': 'now'
|
'completed_since': 'now'
|
||||||
})
|
})
|
||||||
|
|
||||||
for task in tasks:
|
task_list += tasks
|
||||||
print task['name']
|
return task_list
|
||||||
|
|
||||||
|
def handleInput(key):
|
||||||
|
if key in ('q', 'Q'):
|
||||||
|
raise urwid.ExitMainLoop()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cmdasana = CmdAsana()
|
cmdasana = CmdAsana()
|
||||||
|
task_list = cmdasana.allMyTasks()
|
||||||
|
|
||||||
|
loop = urwid.MainLoop(ui.TaskList(task_list), unhandled_input=handleInput)
|
||||||
|
loop.run()
|
||||||
|
|
||||||
cmdasana.allMyTasks()
|
|
||||||
|
|
||||||
if __name__ == "__main__": main()
|
if __name__ == "__main__": main()
|
||||||
|
|||||||
57
ui.py
Normal file
57
ui.py
Normal 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
|
||||||
Reference in New Issue
Block a user