Turned user names into clickable buttons that summon up a pane for that user
This commit is contained in:
parent
d4fc2faf78
commit
522edc30cb
29
mytwitter.py
29
mytwitter.py
|
@ -94,11 +94,11 @@ class MyTwitter():
|
|||
statuses = self.api.GetMentions(count=self.num_entries)
|
||||
elif re.match(r'user: ', list_name):
|
||||
statuses = self.api.GetUserTimeline(re.sub(r'^user: ', r'', list_name), count=self.num_entries)
|
||||
elif re.match(r'[#|@]', list_name):
|
||||
elif re.match(r'list: ', list_name):
|
||||
statuses = self.api.GetListStatuses(re.sub(r'^list: ', r'', list_name), per_page=self.num_entries)
|
||||
else:
|
||||
statuses = self.api.Search(list_name, rpp=self.num_entries)
|
||||
using_results = True
|
||||
else:
|
||||
statuses = self.api.GetListStatuses(list_name, per_page=self.num_entries)
|
||||
|
||||
pane.update_window(statuses, using_results=using_results)
|
||||
|
||||
|
@ -156,15 +156,17 @@ class MyTwitter():
|
|||
|
||||
|
||||
def on_view_selected(self, event, name):
|
||||
full_name = 'list: ' + name
|
||||
|
||||
# If it already exists, don't add it, just switch to it
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
pane = self.tweet_notebook.get_nth_page(i)
|
||||
if pane.get_list_name() == name:
|
||||
if pane.get_list_name() == full_name:
|
||||
self.tweet_notebook.set_current_page(i)
|
||||
return
|
||||
|
||||
# Now, add a new tab with this list
|
||||
self.add_to_notebook(name)
|
||||
self.add_to_notebook(full_name)
|
||||
|
||||
# And, to propagate it:
|
||||
self.update_windows()
|
||||
|
@ -192,6 +194,7 @@ class MyTwitter():
|
|||
new_pane.connect('tweet-reply', self.on_reply)
|
||||
new_pane.connect('tweet-retweet', self.on_retweet)
|
||||
new_pane.connect('tweet-in-reply-to', self.on_reply_to)
|
||||
new_pane.connect('show-user', self.show_user_callback)
|
||||
|
||||
# Special logic for single tweet pane
|
||||
if single_tweet is not None:
|
||||
|
@ -216,12 +219,7 @@ class MyTwitter():
|
|||
def on_search(self, event):
|
||||
search_string = self.search_entry.get_text()
|
||||
self.search_entry.set_text('')
|
||||
if re.match(r'[#|@]', search_string):
|
||||
self.add_to_notebook(search_string)
|
||||
else:
|
||||
# Assume this is a user name we want to lookup
|
||||
self.add_to_notebook('user: ' + search_string)
|
||||
|
||||
self.add_to_notebook(search_string)
|
||||
self.update_windows()
|
||||
|
||||
|
||||
|
@ -262,6 +260,15 @@ class MyTwitter():
|
|||
self.following_button.show()
|
||||
|
||||
|
||||
def show_user(self, name):
|
||||
self.add_to_notebook('user: ' + name)
|
||||
self.update_windows()
|
||||
|
||||
|
||||
def show_user_callback(self, widget, data):
|
||||
self.show_user(data)
|
||||
|
||||
|
||||
### end class MyTwitter
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ class TweetPane(gtk.ScrolledWindow):
|
|||
self.tweets[i].connect('reply', self.on_tweet_reply)
|
||||
self.tweets[i].connect('retweet', self.on_retweet)
|
||||
self.tweets[i].connect('in-reply-to', self.on_tweet_reply_to)
|
||||
self.tweets[i].connect('show-user', self.on_show_user)
|
||||
|
||||
viewport.add(tweet_box)
|
||||
|
||||
|
@ -144,6 +145,10 @@ class TweetPane(gtk.ScrolledWindow):
|
|||
self.emit('tweet-in-reply-to', data)
|
||||
|
||||
|
||||
def on_show_user(self, widget, data):
|
||||
self.emit('show-user', data)
|
||||
|
||||
|
||||
def get_following(self):
|
||||
return self.following
|
||||
|
||||
|
@ -193,6 +198,9 @@ gobject.signal_new("tweet-retweet", TweetPane,
|
|||
gobject.signal_new("tweet-in-reply-to", TweetPane,
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||
gobject.signal_new("show-user", TweetPane,
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||
|
||||
|
||||
|
||||
|
@ -217,7 +225,7 @@ class TweetBox(gtk.VBox):
|
|||
|
||||
def init_widgets(self):
|
||||
## Build the header
|
||||
self.header = gtk.Label()
|
||||
self.header = gtk.Button()
|
||||
label_eb = gtk.EventBox()
|
||||
label_eb.add(self.header)
|
||||
self.pack_start(label_eb)
|
||||
|
@ -225,9 +233,11 @@ class TweetBox(gtk.VBox):
|
|||
# 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)
|
||||
self.header.set_selectable(True)
|
||||
self.header.set_line_wrap(True)
|
||||
|
||||
# Handle the header being clicked
|
||||
self.header.connect('clicked', self.on_user_clicked)
|
||||
|
||||
## Build the text
|
||||
self.text = gtk.Label()
|
||||
|
@ -289,7 +299,7 @@ class TweetBox(gtk.VBox):
|
|||
timestring = timestamp.astimezone(timezone).strftime(time_format)
|
||||
|
||||
# Set the header
|
||||
self.header.set_markup(user.name + " (" + user.screen_name + ") " + timestring)
|
||||
self.header.set_label(user.name + " (" + user.screen_name + ") " + timestring)
|
||||
|
||||
# and the text
|
||||
new_text = status.text
|
||||
|
@ -305,7 +315,7 @@ class TweetBox(gtk.VBox):
|
|||
|
||||
|
||||
def clear_status(self):
|
||||
self.header.set_markup('')
|
||||
self.header.set_label('')
|
||||
self.text.set_markup('')
|
||||
self.screen_name = None
|
||||
self.id = None
|
||||
|
@ -333,6 +343,10 @@ class TweetBox(gtk.VBox):
|
|||
self.emit('in-reply-to', {'id': self.in_reply_to_id, 'name': self.in_reply_to_screen_name})
|
||||
|
||||
|
||||
def on_user_clicked(self, widget):
|
||||
self.emit('show-user', self.screen_name)
|
||||
|
||||
|
||||
def on_mouse_clicked(self, widget, event):
|
||||
if event.button == 1:
|
||||
self.set_read(True)
|
||||
|
@ -358,6 +372,9 @@ gobject.signal_new("retweet", TweetBox,
|
|||
gobject.signal_new("in-reply-to", TweetBox,
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||
gobject.signal_new("show-user", TweetBox,
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
|
||||
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user