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):
|
class SigProxy(gtk.Alignment):
|
||||||
"""
|
"""
|
||||||
This little class exists just so that we can have a gtk class in our
|
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.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT))
|
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
|
# We use these classes to emulate a Status object when we need
|
||||||
# one to be built out of something else.
|
# one to be built out of something else.
|
||||||
|
|
26
mytwitter.py
26
mytwitter.py
|
@ -182,18 +182,12 @@ class MyTwitter():
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
reply_id = self.reply_id
|
reply_id = self.reply_id
|
||||||
text = self.update_entry.get_text()
|
text = self.update_entry.get_text()
|
||||||
self.update_entry.set_text("")
|
|
||||||
|
|
||||||
with self.api.lock:
|
thread = apithreads.PostUpdate(self.api, text, reply_id)
|
||||||
try:
|
thread.sig_proxy.connect('update-posted', self.on_update_posted)
|
||||||
self.api.PostUpdate(text, in_reply_to_status_id=reply_id)
|
self.update_entry.set_sensitive(False)
|
||||||
except HTTPError,URLError:
|
self.update_status_bar('Posting...')
|
||||||
self.update_status_bar('Failed to post tweet')
|
thread.start()
|
||||||
self.reply_id = None
|
|
||||||
return
|
|
||||||
|
|
||||||
self.reply_id = None
|
|
||||||
self.update_status_bar('Tweet Posted')
|
|
||||||
|
|
||||||
|
|
||||||
def update_status_callback(self, widget):
|
def update_status_callback(self, widget):
|
||||||
|
@ -485,6 +479,16 @@ class MyTwitter():
|
||||||
self.db['height'] = event.height
|
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
|
### end class MyTwitter
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user