Navigation works!
This commit is contained in:
43
main.py
43
main.py
@@ -9,16 +9,18 @@ import urwid
|
||||
|
||||
import secrets
|
||||
from ui.auth import AuthPrompt
|
||||
from ui.palette import palette
|
||||
from ui.constants import palette
|
||||
from ui.ui import Ui, loading
|
||||
|
||||
from asana_service import AsanaService
|
||||
|
||||
class NotAuthedException(Exception):
|
||||
def __init__(self):
|
||||
super(NotAuthedException, self)
|
||||
|
||||
class CmdAsana(object):
|
||||
"""The main urwid loop
|
||||
"""
|
||||
loop = None
|
||||
nav_stack = []
|
||||
|
||||
"""Try to get an Asana client using stored tokens
|
||||
|
||||
@@ -37,6 +39,10 @@ class CmdAsana(object):
|
||||
token=token,
|
||||
token_updater=self.save_token,
|
||||
auto_refresh_url=AsanaOAuth2Session.token_url,
|
||||
auto_refresh_kwargs={
|
||||
'client_id': secrets.CLIENT_ID,
|
||||
'client_secret': secrets.CLIENT_SECRET
|
||||
}
|
||||
)
|
||||
except IOError:
|
||||
raise NotAuthedException()
|
||||
@@ -48,6 +54,10 @@ class CmdAsana(object):
|
||||
redirect_uri='urn:ietf:wg:oauth:2.0:oob',
|
||||
token_updater=self.save_token,
|
||||
auto_refresh_url=AsanaOAuth2Session.token_url,
|
||||
auto_refresh_kwargs={
|
||||
'client_id': secrets.CLIENT_ID,
|
||||
'client_secret': secrets.CLIENT_SECRET
|
||||
}
|
||||
)
|
||||
(url, _) = self.client.session.authorization_url()
|
||||
auth = AuthPrompt(url, self.auth_callback)
|
||||
@@ -74,9 +84,31 @@ class CmdAsana(object):
|
||||
def exit_handler(self, key):
|
||||
if key in ('q', 'Q', 'esc'):
|
||||
raise urwid.ExitMainLoop()
|
||||
print(key)
|
||||
if key in ('backspace'):
|
||||
self.ui.go_back()
|
||||
|
||||
def get_asana_service(self):
|
||||
self.asana_service = AsanaService(self.client)
|
||||
|
||||
def get_ui(self):
|
||||
self.ui = Ui(self.asana_service, self.update)
|
||||
|
||||
def run(self):
|
||||
print("Running...", self.client.users.me())
|
||||
self.placeholder = urwid.WidgetPlaceholder(loading())
|
||||
self.loop = urwid.MainLoop(
|
||||
self.placeholder,
|
||||
unhandled_input=self.exit_handler,
|
||||
palette=palette
|
||||
)
|
||||
self.ui.my_tasks()
|
||||
|
||||
def update(self, widget):
|
||||
self.loop.widget.original_widget = widget
|
||||
try:
|
||||
self.loop.draw_screen()
|
||||
except Exception:
|
||||
self.loop.run()
|
||||
|
||||
def save_token(self, token):
|
||||
f = open('.oauth', 'w')
|
||||
@@ -91,6 +123,9 @@ def main():
|
||||
except NotAuthedException:
|
||||
cmd_asana.authorize()
|
||||
|
||||
cmd_asana.get_asana_service()
|
||||
cmd_asana.get_ui()
|
||||
|
||||
cmd_asana.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user