mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Show dialog while waiting for account authorisation. Possibly fixes #101. Needs tests
This commit is contained in:
parent
5a249ba942
commit
76582c6313
@ -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 = []
|
||||
|
@ -74,3 +74,16 @@ class sessionManagerWindow(wx.Dialog):
|
||||
|
||||
def destroy(self):
|
||||
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)
|
@ -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()
|
Loading…
Reference in New Issue
Block a user