Threaded adding/removing friends, and made it a little more robust. Still buggy, but it always was.

This commit is contained in:
Anna
2010-05-19 13:58:11 -04:00
parent 5c642bd479
commit e4ff126d12
3 changed files with 79 additions and 21 deletions

View File

@ -3,6 +3,7 @@
import re
import gtk, gobject
from threading import Thread,RLock
import twitter_pb2
from twitter import Api
from urllib2 import HTTPError,URLError
import avcache
@ -304,6 +305,46 @@ class PostRetweet(ApiThread):
class ChangeFriendship(ApiThread):
def __init__(self, api, pane, user_name, follow=True):
ApiThread.__init__(self, api)
self.sig_proxy = SigProxy()
self.user_name = user_name
self.follow = follow
self.pane = pane
def run(self):
try:
with self.api.lock:
if self.follow:
user = self.api.CreateFriendship(self.user_name)
else:
user = self.api.DestroyFriendship(self.user_name)
if user.__class__ == twitter_pb2.User:
success = True
else:
success = False
except (HTTPError, URLError):
success = False
gtk.gdk.threads_enter()
try:
if self.follow:
self.pane.set_following(success)
else:
self.pane.set_following(not success)
finally:
gtk.gdk.threads_leave()
self.sig_proxy.emit('friendship-changed', {'user_name': self.user_name, 'follow': self.follow, 'success': success})
### End class ChangeFriendship
class SigProxy(gtk.Alignment):
"""
This little class exists just so that we can have a gtk class in our
@ -328,6 +369,10 @@ gobject.signal_new("retweet-posted", SigProxy,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("friendship-changed", SigProxy,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
# We use these classes to emulate a Status object when we need
# one to be built out of something else.