From bb262a7970be2da924f6a6ee2ddf8a690e0f091d Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 12 Apr 2010 14:11:27 -0400 Subject: [PATCH] Started adding tabbed panes so multiple feeds / filters can be seen... currently, just managed to break everything --- default.glade | 62 +++++++++++++++++++-------- mytwitter.py | 116 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 129 insertions(+), 49 deletions(-) diff --git a/default.glade b/default.glade index 9be404f..99051d3 100644 --- a/default.glade +++ b/default.glade @@ -77,6 +77,14 @@ + + + + True + _View + True + + 0 @@ -86,32 +94,52 @@ - + True True - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT - + True + True + GTK_POS_TOP + True + True - + True - GTK_SHADOW_IN + False + 0 - - True - False - 0 - - - - - + + + False + True + + + + + + True + Home + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + diff --git a/mytwitter.py b/mytwitter.py index acc3282..e326f86 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -25,6 +25,7 @@ class MyTwitter(): if self.refresh_time < 10: self.refresh_time = 10 + self.tweet_panes = [] self.tweets = [] self.list = None self.reply_id = None @@ -45,20 +46,21 @@ class MyTwitter(): def init_widgets(self): + # Get widgets from glade self.list_select = self.widget_tree.get_widget('list_select') - self.tweet_box = self.widget_tree.get_widget('tweet_box') + self.tweet_notebook = self.widget_tree.get_widget('tweet_notebook') + self.view_menu = self.widget_tree.get_widget('view_menu') self.update_entry = self.widget_tree.get_widget('update_entry') self.update_count = self.widget_tree.get_widget('update_count') self.status_bar = self.widget_tree.get_widget('status_bar') self.context_id = self.status_bar.get_context_id('message') - # Build us some labels... - for i in range(0, self.num_entries): - self.tweets.append(TweetBox()) - self.tweet_box.pack_start(self.tweets[i]) - self.tweets[i].connect('reply', self.on_reply) - self.tweets[i].connect('retweet', self.on_retweet) - self.tweet_box.show_all() + self.tweet_notebook.remove_page(0) # kill the page that glade makes us have + + # Add the Home tab to the notebook + self.tweet_panes.append(TweetPane('Home', self)) + self.tweet_notebook.append_page(self.tweet_panes[0]) + self.tweet_notebook.set_tab_label_text(self.tweet_panes[0], 'Home') # Fill the ComboBox with entries self.list_select.append_text('@' + self.username) @@ -84,30 +86,7 @@ class MyTwitter(): else: statuses = self.api.GetListStatuses(self.list, per_page=self.num_entries) - # If this is our first load of this list, don't treat anything as new! - if self.last_tweet_read is None: - self.last_tweet_read = statuses[0].id - - # Keep count of the new tweets for posting a status message - num_new_tweets = 0 - - for i in range(0, self.num_entries): - read = True - if i < len(statuses): - if statuses[i].id > self.last_tweet_read: - num_new_tweets += 1 - read = False - self.tweets[i].set_status(statuses[i], read) - else: - self.tweets[i].clear_status() - - self.latest_tweet = statuses[0].id - self.status_bar.pop(self.context_id) - if num_new_tweets > 0: - status_text = str(num_new_tweets) + ' new tweet' - if num_new_tweets > 1: - status_text += 's' - self.status_bar.push(self.context_id, status_text) + self.tweet_panes[0].update_window(statuses) def update_window_callback(self, widget): @@ -165,9 +144,82 @@ class MyTwitter(): print 'debug: set_tweets_read()' self.last_tweet_read = self.latest_tweet + + def set_tweets_read_callback(self, event): + self.set_tweets_read() + ### end class MyTwitter +class TweetPane(gtk.ScrolledWindow): + ''' + Box that holds all the TweetBoxes for a given feed + + This box will not update itself, the parent should do that. + + It will connect num_entries listeners to its parent's on_reply() and on_retweet() + + It also gets some data from its parent, including num_entries + ''' + + def __init__(self, list_name, mytwitter): + gtk.ScrolledWindow.__init__(self) + + self.list_name = list_name + self.mytwitter = mytwitter + + # These handle determining which tweets are unread + self.last_tweet_read = None + self.latest_tweet = None + + self.tweets = [] + + self.init_widgets() + + + def init_widgets(self): + tweet_box = gtk.VBox() + viewport = gtk.Viewport() + + # Build us some labels... + for i in range(0, self.mytwitter.num_entries): + self.tweets.append(TweetBox()) + tweet_box.pack_start(self.tweets[i]) + self.tweets[i].connect('reply', self.mytwitter.on_reply) + self.tweets[i].connect('retweet', self.mytwitter.on_retweet) + tweet_box.show_all() + + viewport.add(tweet_box) + self.add(viewport) + self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) + + + def update_window(self, statuses): + # If this is our first load of this list, don't treat anything as new! + if self.last_tweet_read is None: + self.last_tweet_read = statuses[0].id + + # Keep count of the new tweets for posting a status message + num_new_tweets = 0 + + for i in range(0, self.mytwitter.num_entries): + read = True + if i < len(statuses): + if statuses[i].id > self.last_tweet_read: + num_new_tweets += 1 + read = False + self.tweets[i].set_status(statuses[i], read) + else: + self.tweets[i].clear_status() + + self.latest_tweet = statuses[0].id + + if num_new_tweets > 0: + pass # fixme: change the label here, or maybe in mytwitter? + +### end class TweetPane + + class TweetBox(gtk.VBox): '''