Threaded the calls to GetUserList, so that the View menu is populated asynchronously and startup time can be faster.
This commit is contained in:
@ -1,20 +1,38 @@
|
||||
# Python module that handles calls to the twitter API as a separate thread
|
||||
|
||||
import re
|
||||
import gtk
|
||||
import gtk, gobject
|
||||
from threading import Thread,RLock
|
||||
from twitter import Api
|
||||
from urllib2 import HTTPError,URLError
|
||||
|
||||
class SafeApi(Api):
|
||||
''' This is just a Twitter API with an RLock for multi-threaded access '''
|
||||
class CustomApi(Api):
|
||||
'''
|
||||
This is a Twitter API with an RLock for multi-threaded access
|
||||
Also included is logic for processing the list names when the object is
|
||||
instantiated
|
||||
'''
|
||||
|
||||
def __init__(self, username, password):
|
||||
Api.__init__(self, username, password)
|
||||
self.lock = RLock()
|
||||
self.sig_proxy = SigProxy()
|
||||
|
||||
# End class SafeApi
|
||||
self.username = username
|
||||
|
||||
thread = GetUserLists(api=self)
|
||||
thread.sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||
thread.start()
|
||||
|
||||
|
||||
def on_lists_ready(self, widget, lists, ignored):
|
||||
list_names = []
|
||||
for l in lists['lists']:
|
||||
list_names.append(l.name)
|
||||
list_names.sort()
|
||||
self.sig_proxy.emit('lists-ready', self.username, list_names)
|
||||
|
||||
# End class CustomApi
|
||||
|
||||
|
||||
class ApiThread(Thread):
|
||||
@ -152,6 +170,41 @@ class GetVerified(ApiThread):
|
||||
### End class GetVerified
|
||||
|
||||
|
||||
class GetUserLists(ApiThread):
|
||||
def __init__(self, api):
|
||||
ApiThread.__init__(self, api)
|
||||
self.sig_proxy = SigProxy()
|
||||
|
||||
|
||||
def run(self):
|
||||
lists = []
|
||||
done = False
|
||||
|
||||
while not done:
|
||||
done = True
|
||||
try:
|
||||
with self.api.lock:
|
||||
lists = self.api.GetUserLists()
|
||||
except (HTTPError, URLError):
|
||||
done = False
|
||||
|
||||
self.sig_proxy.emit('lists-ready', lists, None)
|
||||
|
||||
### End class GetUserLists
|
||||
|
||||
|
||||
|
||||
class SigProxy(gtk.Alignment):
|
||||
|
||||
def __init__(self):
|
||||
gtk.Alignment.__init__(self)
|
||||
|
||||
# End class SigProxy
|
||||
|
||||
gobject.signal_new("lists-ready", SigProxy,
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT))
|
||||
|
||||
|
||||
# We use these classes to emulate a Status object when we need
|
||||
# one to be built out of something else.
|
||||
|
Reference in New Issue
Block a user