Made posting an update a threaded action
This commit is contained in:
parent
8764cc77c3
commit
cc99e36ed3
|
@ -260,6 +260,29 @@ class GetUserLists(ApiThread):
|
|||
|
||||
|
||||
|
||||
class PostUpdate(ApiThread):
|
||||
def __init__(self, api, update, reply_id):
|
||||
ApiThread.__init__(self, api)
|
||||
self.sig_proxy = SigProxy()
|
||||
|
||||
self.update = update
|
||||
self.reply_id = reply_id
|
||||
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
with self.api.lock:
|
||||
self.api.PostUpdate(self.update, in_reply_to_status_id=self.reply_id)
|
||||
success = True
|
||||
except (HTTPError, URLError):
|
||||
success = False
|
||||
|
||||
self.sig_proxy.emit('update-posted', success)
|
||||
|
||||
### End class PostUpdate
|
||||
|
||||
|
||||
|
||||
class SigProxy(gtk.Alignment):
|
||||
"""
|
||||
This little class exists just so that we can have a gtk class in our
|
||||
|
@ -276,6 +299,10 @@ gobject.signal_new("lists-ready", SigProxy,
|
|||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT))
|
||||
|
||||
gobject.signal_new("update-posted", 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.
|
||||
|
|
28
mytwitter.py
28
mytwitter.py
|
@ -182,19 +182,13 @@ class MyTwitter():
|
|||
def update_status(self):
|
||||
reply_id = self.reply_id
|
||||
text = self.update_entry.get_text()
|
||||
self.update_entry.set_text("")
|
||||
|
||||
with self.api.lock:
|
||||
try:
|
||||
self.api.PostUpdate(text, in_reply_to_status_id=reply_id)
|
||||
except HTTPError,URLError:
|
||||
self.update_status_bar('Failed to post tweet')
|
||||
self.reply_id = None
|
||||
return
|
||||
thread = apithreads.PostUpdate(self.api, text, reply_id)
|
||||
thread.sig_proxy.connect('update-posted', self.on_update_posted)
|
||||
self.update_entry.set_sensitive(False)
|
||||
self.update_status_bar('Posting...')
|
||||
thread.start()
|
||||
|
||||
self.reply_id = None
|
||||
self.update_status_bar('Tweet Posted')
|
||||
|
||||
|
||||
def update_status_callback(self, widget):
|
||||
self.update_status()
|
||||
|
@ -483,7 +477,17 @@ class MyTwitter():
|
|||
def on_resize(self, widget, event):
|
||||
self.db['width'] = event.width
|
||||
self.db['height'] = event.height
|
||||
|
||||
|
||||
|
||||
def on_update_posted(self, widget, success):
|
||||
if success:
|
||||
self.reply_id = None
|
||||
self.update_entry.set_text("")
|
||||
self.update_status_bar('Tweet Posted')
|
||||
else:
|
||||
self.update_status_bar('Failed to post tweet')
|
||||
|
||||
self.update_entry.set_sensitive(True)
|
||||
|
||||
### end class MyTwitter
|
||||
|
||||
|
|
Reference in New Issue
Block a user