diff --git a/hrafn.py b/hrafn.py
index 8007b2d..196466d 100755
--- a/hrafn.py
+++ b/hrafn.py
@@ -346,6 +346,7 @@ class Hrafn():
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-hashtag', self.show_hashtag)
# Special logic for single tweet pane
if single_tweet is not None:
@@ -419,6 +420,10 @@ class Hrafn():
self.show_user(data)
+ def show_hashtag(self, widget, data):
+ self.add_to_notebook('#' + data)
+
+
def on_at_button_clicked(self, widget, user_name):
self.add_to_notebook('@' + user_name)
diff --git a/twitterwidgets.py b/twitterwidgets.py
index 0caa9da..35a1442 100644
--- a/twitterwidgets.py
+++ b/twitterwidgets.py
@@ -74,6 +74,7 @@ class TweetPane(gtk.ScrolledWindow):
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-hashtag', self.on_show_hashtag)
self.tweets[i].connect('tweet-read', self.set_tweets_read_callback)
viewport.add(tweet_box)
@@ -209,6 +210,10 @@ class TweetPane(gtk.ScrolledWindow):
self.emit('show-user', data)
+ def on_show_hashtag(self, widget, data):
+ self.emit('show-hashtag', data)
+
+
def get_is_user(self):
return self.is_user
@@ -239,6 +244,9 @@ gobject.signal_new("tweet-conversation", TweetPane,
gobject.signal_new("show-user", TweetPane,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
+gobject.signal_new("show-hashtag", TweetPane,
+ gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("follow-clicked", TweetPane,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
@@ -462,8 +470,11 @@ class TweetBox(gtk.HBox):
new_text = re.sub(r'&([^;]*?)( |$)', r'&\1\2', new_text)
new_text = re.sub(r'"([^;]*?)( |$)', r'"\1\2', new_text)
if gtk.gtk_version[0] > 2 or (gtk.gtk_version[0] == 2 and gtk.gtk_version[1] >= 18):
+ # Make URLs into links
new_text = re.sub(r"(http://.*?)([^0-9a-zA-Z.~/-_]|$)", r'\1\2', new_text)
+ # Make @ or # refs into links, to be used internally
new_text = re.sub(r'@(.*?)([^0-9a-zA-Z_]|$)', self._make_user_link, new_text)
+ new_text = re.sub(r'#(.*?)([^0-9a-zA-Z_-]|$)', self._make_hashtag_link, new_text)
self.text.set_markup(new_text)
# If this is in reply to something, set appropriate label
@@ -546,7 +557,10 @@ class TweetBox(gtk.HBox):
if re.match(r'@', uri):
self.emit('show-user', re.sub(r'@', '', uri))
return True
-
+ if re.match(r'#', uri):
+ self.emit('show-hashtag', re.sub(r'#', '', uri))
+ return True
+
def _make_user_link(self, matchobj):
name = matchobj.group(1)
@@ -555,6 +569,13 @@ class TweetBox(gtk.HBox):
else:
return '@' + name + '' + matchobj.group(2)
+ def _make_hashtag_link(self, matchobj):
+ name = matchobj.group(1)
+ if name == '':
+ return '#' + matchobj.group(2)
+ else:
+ return '#' + name + '' + matchobj.group(2)
+
# end class TweetBox
# signals for TweetBox
@@ -576,6 +597,9 @@ gobject.signal_new("conversation", TweetBox,
gobject.signal_new("show-user", TweetBox,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
+gobject.signal_new("show-hashtag", TweetBox,
+ gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))