diff --git a/twitterwidgets.py b/twitterwidgets.py index 6e26038..d173fa3 100644 --- a/twitterwidgets.py +++ b/twitterwidgets.py @@ -3,6 +3,7 @@ import datetime, dateutil.tz import gtk, gobject from threading import RLock from avcache import AvCache +import webbrowser class TweetPane(gtk.ScrolledWindow): @@ -248,6 +249,7 @@ class TweetBox(gtk.HBox): self.id = None self.in_reply_to_id = None self.in_reply_to_screen_name = None + self.app_url = None # Lets the tweetbox know if it is part of a conversation or not self.conversation = conversation @@ -271,22 +273,37 @@ class TweetBox(gtk.HBox): self.pack_start(text_box) ## Build the header + self.user_button = gtk.Button() + self.time_label = gtk.Label() + self.app_button = gtk.Button() + via_label = gtk.Label(' via ') self.header = gtk.Button() - label_eb = gtk.EventBox() - label_eb.add(self.header) - text_box.pack_start(label_eb) + label_box = gtk.HBox() + label_box.pack_start(self.user_button, expand=False) + label_box.pack_start(self.time_label, expand=False) + label_box.pack_start(via_label, expand=False) + label_box.pack_start(self.app_button, expand=False) + text_box.pack_start(label_box) # Set the header's properties - label_eb.modify_text(gtk.STATE_NORMAL,gtk.gdk.color_parse("#ffffff")) - label_eb.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#8888ff")) - self.header.set_relief(gtk.RELIEF_NONE) - self.header.set_alignment(0.0, 0.0) + label_box.modify_text(gtk.STATE_NORMAL,gtk.gdk.color_parse("#ffffff")) + label_box.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#8888ff")) + self.user_button.set_relief(gtk.RELIEF_NONE) + self.user_button.set_alignment(0.0, 0.0) - # Handle the header being clicked + self.time_label.set_alignment(0.0, 0.0) + via_label.set_alignment(0.0, 0.0) + + self.app_button.set_relief(gtk.RELIEF_NONE) + self.app_button.set_alignment(0.0, 0.0) + + # Handle the header buttons being clicked if self.is_user: - self.header.set_sensitive(False) + self.user_button.set_sensitive(False) else: - self.header.connect('clicked', self.on_user_clicked) + self.user_button.connect('clicked', self.on_user_clicked) + + self.app_button.connect('clicked', self.on_app_button_clicked) ## Build the text self.text = gtk.Label() @@ -366,11 +383,22 @@ class TweetBox(gtk.HBox): timestring = timestamp.astimezone(timezone).strftime(time_format) # Set the header - if self.is_user: - header_text = timestring + self.app_url = re.sub(r'.*(.*).*', r'\1', status.source) + self.app_button.set_label(app_name) + + if self.app_url: + self.app_button.set_sensitive(True) else: - header_text = user.name + " (" + user.screen_name + ") " + timestring - self.header.set_label(header_text) + self.app_button.set_sensitive(False) + + self.time_label.set_label(timestring) + + if self.is_user: + self.user_button.set_label('') + else: + self.user_button.set_label(user.name + " (" + user.screen_name + ") ") + # and the text new_text = status.text @@ -388,7 +416,10 @@ class TweetBox(gtk.HBox): def clear_status(self): - self.header.set_label('') + self.user_button.set_label('') + self.time_label.set_label('') + self.app_button.set_label('') + self.text.set_markup('') self.screen_name = None self.id = None @@ -439,6 +470,12 @@ class TweetBox(gtk.HBox): self.emit('tweet-read') + def on_app_button_clicked(self, widget): + self.set_read() + if self.app_url: + webbrowser.open(self.app_url) + + def on_mouse_clicked(self, widget, event): if event.button == 1: self.set_read(True)