Began improving headers to have separate clickable sections

This commit is contained in:
Anna 2010-05-22 18:04:12 -04:00
parent 679e03da6a
commit e8af16a8e7

View File

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