Initial commit of 'conversation' button... needs a lot of work still
This commit is contained in:
parent
0ead5932a5
commit
3357249d28
|
@ -145,6 +145,53 @@ class GetSingleTweet(ApiThread):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class GetConversation(ApiThread):
|
||||||
|
def __init__(self, api, pane, root_tweet_id):
|
||||||
|
ApiThread.__init__(self, api)
|
||||||
|
self.pane = pane
|
||||||
|
self.root_tweet_id = root_tweet_id
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
statuses = []
|
||||||
|
last_tweet = None
|
||||||
|
|
||||||
|
# Get the root tweet
|
||||||
|
try:
|
||||||
|
with self.api.lock:
|
||||||
|
last_tweet = self.api.GetStatus(self.single_tweet)
|
||||||
|
statuses.append(last_tweet)
|
||||||
|
except (HTTPError, URLError):
|
||||||
|
statuses = None
|
||||||
|
last_tweet = None
|
||||||
|
|
||||||
|
# get tweets in a loop, until there is no in_reply_to_status_id
|
||||||
|
if last_tweet is not None:
|
||||||
|
while last_tweet.in_reply_to_status_id is not None:
|
||||||
|
try:
|
||||||
|
with self.api.lock:
|
||||||
|
last_tweet = self.api.GetStatus(self.single_tweet)
|
||||||
|
statuses.append(last_tweet)
|
||||||
|
except (HTTPError, URLError):
|
||||||
|
last_tweet = None
|
||||||
|
|
||||||
|
# In case we've never seen some of these users, grab their profile images and cache them
|
||||||
|
for status in statuses:
|
||||||
|
avcache.add_to_cache(status.user)
|
||||||
|
|
||||||
|
statuses.reverse()
|
||||||
|
|
||||||
|
gtk.gdk.threads_enter()
|
||||||
|
try:
|
||||||
|
self.pane.update_window(statuses)
|
||||||
|
finally:
|
||||||
|
gtk.gdk.threads_leave()
|
||||||
|
|
||||||
|
|
||||||
|
### End class GetConversation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GetFollowing(ApiThread):
|
class GetFollowing(ApiThread):
|
||||||
def __init__(self, api, pane, user):
|
def __init__(self, api, pane, user):
|
||||||
ApiThread.__init__(self, api)
|
ApiThread.__init__(self, api)
|
||||||
|
|
12
mytwitter.py
12
mytwitter.py
|
@ -238,6 +238,10 @@ class MyTwitter():
|
||||||
self.add_to_notebook(data['name'], data['id'])
|
self.add_to_notebook(data['name'], data['id'])
|
||||||
|
|
||||||
|
|
||||||
|
def on_conversation(self, widget, data):
|
||||||
|
self.add_to_notebook(data['name'], data['id'], True)
|
||||||
|
|
||||||
|
|
||||||
def on_view_selected(self, event, username, name):
|
def on_view_selected(self, event, username, name):
|
||||||
if name == 'Home' or name == 'Direct Messages':
|
if name == 'Home' or name == 'Direct Messages':
|
||||||
full_name = username + '/' + name
|
full_name = username + '/' + name
|
||||||
|
@ -269,7 +273,7 @@ class MyTwitter():
|
||||||
self.remove_view(name, single_tweet)
|
self.remove_view(name, single_tweet)
|
||||||
|
|
||||||
|
|
||||||
def add_to_notebook(self, name, single_tweet=None):
|
def add_to_notebook(self, name, single_tweet=None, conversation=False):
|
||||||
# If it already exists, don't add it, just switch to it
|
# If it already exists, don't add it, just switch to it
|
||||||
for i in range(self.tweet_notebook.get_n_pages()):
|
for i in range(self.tweet_notebook.get_n_pages()):
|
||||||
pane = self.tweet_notebook.get_nth_page(i)
|
pane = self.tweet_notebook.get_nth_page(i)
|
||||||
|
@ -305,12 +309,18 @@ class MyTwitter():
|
||||||
new_pane.connect('tweet-reply', self.on_reply)
|
new_pane.connect('tweet-reply', self.on_reply)
|
||||||
new_pane.connect('tweet-retweet', self.on_retweet)
|
new_pane.connect('tweet-retweet', self.on_retweet)
|
||||||
new_pane.connect('tweet-in-reply-to', self.on_reply_to)
|
new_pane.connect('tweet-in-reply-to', self.on_reply_to)
|
||||||
|
new_pane.connect('tweet-conversation', self.on_conversation)
|
||||||
new_pane.connect('show-user', self.show_user_callback)
|
new_pane.connect('show-user', self.show_user_callback)
|
||||||
new_pane.connect('following-set', self.update_follow_button)
|
new_pane.connect('following-set', self.update_follow_button)
|
||||||
new_pane.connect('verified-set', self.update_verified_label)
|
new_pane.connect('verified-set', self.update_verified_label)
|
||||||
|
|
||||||
# Special logic for single tweet pane
|
# Special logic for single tweet pane
|
||||||
if single_tweet is not None:
|
if single_tweet is not None:
|
||||||
|
if conversation:
|
||||||
|
apithreads.GetConversation(api=self.api,
|
||||||
|
pane=new_pane,
|
||||||
|
root_tweet_id=single_tweet).start()
|
||||||
|
else:
|
||||||
apithreads.GetSingleTweet(api=self.api,
|
apithreads.GetSingleTweet(api=self.api,
|
||||||
pane=new_pane,
|
pane=new_pane,
|
||||||
single_tweet=single_tweet).start()
|
single_tweet=single_tweet).start()
|
||||||
|
|
|
@ -63,6 +63,7 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
self.tweets[i].connect('reply', self.on_tweet_reply)
|
self.tweets[i].connect('reply', self.on_tweet_reply)
|
||||||
self.tweets[i].connect('retweet', self.on_retweet)
|
self.tweets[i].connect('retweet', self.on_retweet)
|
||||||
self.tweets[i].connect('in-reply-to', self.on_tweet_reply_to)
|
self.tweets[i].connect('in-reply-to', self.on_tweet_reply_to)
|
||||||
|
self.tweets[i].connect('conversation', self.on_tweet_conversation)
|
||||||
self.tweets[i].connect('show-user', self.on_show_user)
|
self.tweets[i].connect('show-user', self.on_show_user)
|
||||||
|
|
||||||
viewport.add(tweet_box)
|
viewport.add(tweet_box)
|
||||||
|
@ -173,6 +174,9 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
self.emit('tweet-in-reply-to', data)
|
self.emit('tweet-in-reply-to', data)
|
||||||
|
|
||||||
|
|
||||||
|
def on_tweet_conversation(self, widget, data):
|
||||||
|
self.emit('tweet-conversation', data)
|
||||||
|
|
||||||
def on_show_user(self, widget, data):
|
def on_show_user(self, widget, data):
|
||||||
self.emit('show-user', data)
|
self.emit('show-user', data)
|
||||||
|
|
||||||
|
@ -216,6 +220,9 @@ gobject.signal_new("tweet-retweet", TweetPane,
|
||||||
gobject.signal_new("tweet-in-reply-to", TweetPane,
|
gobject.signal_new("tweet-in-reply-to", TweetPane,
|
||||||
gobject.SIGNAL_RUN_LAST,
|
gobject.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
|
gobject.signal_new("tweet-conversation", TweetPane,
|
||||||
|
gobject.SIGNAL_RUN_LAST,
|
||||||
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
gobject.signal_new("show-user", TweetPane,
|
gobject.signal_new("show-user", TweetPane,
|
||||||
gobject.SIGNAL_RUN_LAST,
|
gobject.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
|
@ -301,6 +308,11 @@ class TweetBox(gtk.HBox):
|
||||||
button_box.pack_start(self.reply_to_button, expand=False)
|
button_box.pack_start(self.reply_to_button, expand=False)
|
||||||
self.reply_to_button.connect("clicked", self.on_in_reply_to_clicked)
|
self.reply_to_button.connect("clicked", self.on_in_reply_to_clicked)
|
||||||
|
|
||||||
|
self.conversation_button = gtk.Button("Conversation")
|
||||||
|
self.conversation_button.set_relief(gtk.RELIEF_NONE)
|
||||||
|
button_box.pack_start(self.conversation_button, expand=False)
|
||||||
|
self.conversation_button.connect("clicked", self.on_conversation_clicked)
|
||||||
|
|
||||||
reply_button = gtk.Button("Reply")
|
reply_button = gtk.Button("Reply")
|
||||||
reply_button.set_relief(gtk.RELIEF_HALF)
|
reply_button.set_relief(gtk.RELIEF_HALF)
|
||||||
button_box.pack_end(reply_button, expand=False)
|
button_box.pack_end(reply_button, expand=False)
|
||||||
|
@ -356,6 +368,7 @@ class TweetBox(gtk.HBox):
|
||||||
# If this is in reply to something, set appropriate label
|
# If this is in reply to something, set appropriate label
|
||||||
if self.in_reply_to_screen_name and self.in_reply_to_id:
|
if self.in_reply_to_screen_name and self.in_reply_to_id:
|
||||||
self.reply_to_button.set_label('in reply to ' + self.in_reply_to_screen_name)
|
self.reply_to_button.set_label('in reply to ' + self.in_reply_to_screen_name)
|
||||||
|
self.conversation_button.show()
|
||||||
|
|
||||||
|
|
||||||
def clear_status(self):
|
def clear_status(self):
|
||||||
|
@ -365,6 +378,7 @@ class TweetBox(gtk.HBox):
|
||||||
self.id = None
|
self.id = None
|
||||||
self.set_read(True)
|
self.set_read(True)
|
||||||
self.reply_to_button.set_label('')
|
self.reply_to_button.set_label('')
|
||||||
|
self.conversation_button.hide()
|
||||||
self.avatar.hide()
|
self.avatar.hide()
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,6 +403,10 @@ class TweetBox(gtk.HBox):
|
||||||
self.emit('in-reply-to', {'id': self.in_reply_to_id, 'name': self.in_reply_to_screen_name})
|
self.emit('in-reply-to', {'id': self.in_reply_to_id, 'name': self.in_reply_to_screen_name})
|
||||||
|
|
||||||
|
|
||||||
|
def on_conversation_clicked(self, widget):
|
||||||
|
self.emit('in-reply-to', {'id': self.in_reply_to_id, 'name': self.in_reply_to_screen_name})
|
||||||
|
|
||||||
|
|
||||||
def on_user_clicked(self, widget):
|
def on_user_clicked(self, widget):
|
||||||
self.emit('show-user', self.screen_name)
|
self.emit('show-user', self.screen_name)
|
||||||
|
|
||||||
|
@ -418,6 +436,9 @@ gobject.signal_new("retweet", TweetBox,
|
||||||
gobject.signal_new("in-reply-to", TweetBox,
|
gobject.signal_new("in-reply-to", TweetBox,
|
||||||
gobject.SIGNAL_RUN_LAST,
|
gobject.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
|
gobject.signal_new("conversation", TweetBox,
|
||||||
|
gobject.SIGNAL_RUN_LAST,
|
||||||
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
gobject.signal_new("show-user", TweetBox,
|
gobject.signal_new("show-user", TweetBox,
|
||||||
gobject.SIGNAL_RUN_LAST,
|
gobject.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||||
|
|
Reference in New Issue
Block a user