diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index a3918bfc..690b8cd0 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """ The main session object. Here are the twitter functions to interact with the "model" of TWBlue.""" +import wx import urllib2 import config import twitter @@ -16,10 +17,11 @@ import config_utils import shelve import application import os -from mysc.thread_utils import stream_threaded +from mysc.thread_utils import stream_threaded, call_threaded from pubsub import pub log = logging.getLogger("sessionmanager.session") from long_tweets import tweets, twishort +from wxUI import authorisationDialog sessions = {} @@ -166,7 +168,20 @@ class Session(object): if self.logged == True: raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.") else: - self.twitter.authorise(self.settings) + self.authorisation_thread = call_threaded(self.twitter.authorise, self.settings) + self.authorisation_dialog = authorisationDialog() + self.authorisation_dialog.cancel.Bind(wx.EVT_BUTTON, self.authorisation_cancelled) + pub.subscribe(self.authorisation_accepted, "authorisation-accepted") + self.authorisation_dialog.ShowModal() + + def authorisation_cancelled(self, *args, **kwargs): + pub.sendMessage("authorisation-cancelled") + self.authorisation_dialog.Destroy() + del self.authorisation_dialog + + def authorisation_accepted(self): + pub.unsubscribe(self.authorisation_accepted, "authorisation-accepted") + self.authorisation_dialog.Destroy() def get_more_items(self, update_function, users=False, name=None, *args, **kwargs): results = [] diff --git a/src/sessionmanager/wxUI.py b/src/sessionmanager/wxUI.py index c57e1910..61df085e 100644 --- a/src/sessionmanager/wxUI.py +++ b/src/sessionmanager/wxUI.py @@ -73,4 +73,17 @@ class sessionManagerWindow(wx.Dialog): self.configuration.Hide() def destroy(self): - self.Destroy() \ No newline at end of file + self.Destroy() + +class authorisationDialog(wx.Dialog): + def __init__(self): + super(authorisationDialog, self).__init__(parent=None, title=_(u"Authorising account...")) + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + self.text = wx.TextCtrl(panel, -1, _("Waiting for account authorisation..."), style=wx.TE_READONLY|wx.TE_MULTILINE) + self.cancel = wx.Button(panel, wx.ID_CANCEL) + sizer.Add(self.text, 0, wx.ALL, 5) + sizer.Add(self.cancel, 0, wx.ALL, 5) + panel.SetSizer(sizer) + min = sizer.CalcMin() + self.SetClientSize(min) \ No newline at end of file diff --git a/src/twitter/authorisationHandler.py b/src/twitter/authorisationHandler.py index e7cc668a..b1a6d1f7 100644 --- a/src/twitter/authorisationHandler.py +++ b/src/twitter/authorisationHandler.py @@ -2,11 +2,12 @@ import BaseHTTPServer import application from urlparse import urlparse, parse_qs +from pubsub import pub logged = False verifier = None -class handler(BaseHTTPServer.BaseHTTPRequestHandler): +class handler(BaseHTTPServer.BaseHTTPRequestHandler, object): def do_GET(self): global logged @@ -18,4 +19,14 @@ class handler(BaseHTTPServer.BaseHTTPRequestHandler): global verifier verifier = params.get('oauth_verifier', [None])[0] self.wfile.write(u"You have successfully logged into Twitter with {0}. You can close this window now.".format(application.name)) + pub.sendMessage("authorisation-accepted") + pub.unsubscribe(self.cancelled, "authorisation-cancelled") self.finish() + + def __init__(self, *args, **kwargs): + pub.subscribe(self.cancelled, "authorisation-cancelled") + super(handler, self).__init__(*args, **kwargs) + + def cancelled(self): + pub.unsubscribe(self.cancelled, "authorisation-cancelled") + self.finish() \ No newline at end of file