diff --git a/hrafn.py b/hrafn.py index 1158be5..6917184 100755 --- a/hrafn.py +++ b/hrafn.py @@ -238,7 +238,18 @@ class Hrafn(): def on_reply(self, widget, data): self.update_entry.set_text('@' + data['screen_name'] + ' ') self.reply_id = data['id'] + self.focus_on_entry() + + + def on_reply_dm(self, widget, data): + self.update_entry.set_text('D ' + data + ' ') + self.focus_on_entry() + + + def focus_on_entry(self): self.update_entry.grab_focus() + self.update_entry.select_region(0,0) + self.update_entry.set_position(-1) def on_retweet(self, widget, data): @@ -317,11 +328,15 @@ class Hrafn(): if re.match('user:', name): is_user = True + is_dm = False + if re.search('Direct Messages', name): + is_dm = True + entries=self.num_entries if single_tweet and not conversation: entries=1 - new_pane = TweetPane(name, username=self.username, num_entries=entries, single_tweet=single_tweet, is_user=is_user, conversation=conversation) + new_pane = TweetPane(name, username=self.username, num_entries=entries, single_tweet=single_tweet, is_user=is_user, conversation=conversation, is_dm=is_dm) new_pane.connect('new-tweets', self.on_read_tweets_changed) new_pane.connect('tweets-read', self.on_read_tweets_changed) @@ -354,6 +369,7 @@ class Hrafn(): self.tweet_notebook.set_tab_reorderable(new_pane, True) new_pane.get_tab_label().connect('close-clicked', self.remove_view_callback, name, single_tweet, conversation) new_pane.connect('tweet-reply', self.on_reply) + new_pane.connect('tweet-reply-dm', self.on_reply_dm) new_pane.connect('tweet-retweet', self.on_retweet) new_pane.connect('tweet-in-reply-to', self.on_reply_to) new_pane.connect('tweet-conversation', self.on_conversation) diff --git a/twitterwidgets.py b/twitterwidgets.py index b5f6f65..7fb615d 100644 --- a/twitterwidgets.py +++ b/twitterwidgets.py @@ -18,7 +18,7 @@ class TweetPane(gtk.ScrolledWindow): It also gets some data from its parent, including num_entries ''' - def __init__(self, list_name, username, num_entries=20, single_tweet=None, is_user=False, conversation=False): + def __init__(self, list_name, username, num_entries=20, single_tweet=None, is_user=False, conversation=False, is_dm=False): gtk.ScrolledWindow.__init__(self) # If the username is encoded in the tweet pane's name, we really want @@ -37,6 +37,7 @@ class TweetPane(gtk.ScrolledWindow): self.is_user = is_user self.following = False self.verified = False + self.is_dm = is_dm self.tab_label = CloseTabLabel(self.list_name) @@ -66,7 +67,7 @@ class TweetPane(gtk.ScrolledWindow): # Build us some labels... for i in range(0, self.num_entries): - self.tweets.append(TweetBox(self.conversation, self.is_user)) + self.tweets.append(TweetBox(self.conversation, self.is_user, self.is_dm)) tweet_box.pack_start(self.tweets[i], expand=False) self.tweets[i].connect('reply', self.on_tweet_reply) self.tweets[i].connect('retweet', self.on_retweet) @@ -193,7 +194,10 @@ class TweetPane(gtk.ScrolledWindow): def on_tweet_reply(self, widget): - self.emit('tweet-reply', {'screen_name': widget.screen_name, 'id': widget.id}) + if self.is_dm: + self.emit('tweet-reply-dm', widget.screen_name) + else: + self.emit('tweet-reply', {'screen_name': widget.screen_name, 'id': widget.id}) def on_retweet(self, widget): @@ -233,6 +237,9 @@ class TweetPane(gtk.ScrolledWindow): gobject.signal_new("tweet-reply", TweetPane, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)) +gobject.signal_new("tweet-reply-dm", TweetPane, + gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)) gobject.signal_new("tweet-retweet", TweetPane, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)) @@ -265,7 +272,7 @@ class TweetBox(gtk.HBox): Also stores the data necessary for replying or retweeting (id, screen name) ''' - def __init__(self, conversation=False, is_user=False): + def __init__(self, conversation=False, is_user=False, is_dm=False): gtk.HBox.__init__(self) self.screen_name = None @@ -278,6 +285,7 @@ class TweetBox(gtk.HBox): self.conversation = conversation self.is_user = is_user + self.is_dm = is_dm self.init_widgets() @@ -386,10 +394,11 @@ class TweetBox(gtk.HBox): button_box.pack_end(reply_button, expand=False) reply_button.connect("clicked", self.on_reply_clicked) - retweet_button = gtk.Button("Retweet") - retweet_button.set_relief(gtk.RELIEF_HALF) - button_box.pack_end(retweet_button, expand=False) - retweet_button.connect("clicked", self.on_retweet_clicked) + if not self.is_dm: + retweet_button = gtk.Button("Retweet") + retweet_button.set_relief(gtk.RELIEF_HALF) + button_box.pack_end(retweet_button, expand=False) + retweet_button.connect("clicked", self.on_retweet_clicked) def set_status(self, status, read=True):