From 5b74eed1e0340f6bffc46c947dcdeece00a65b30 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 19 May 2010 14:36:03 -0400 Subject: [PATCH] Moved active account choice to a menu, and indicate it with a label beside the tweet update field. Temporarily broke ability to actually change accounts, though --- default.glade | 52 +++++++++++++++++---------------------------------- mytwitter.py | 48 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/default.glade b/default.glade index 1bb187b..32549ea 100644 --- a/default.glade +++ b/default.glade @@ -61,7 +61,7 @@ True - _View + _Views True @@ -71,6 +71,19 @@ + + + True + _Accounts + True + + + + + + + + True @@ -299,32 +312,15 @@ - + True False 0 - - - True - null - False - True - True - - - - 0 - False - True - GTK_PACK_END - - - True - Active Account: + False False GTK_JUSTIFY_LEFT @@ -340,25 +336,11 @@ 0 - 2 + 0 False False - GTK_PACK_END - - - 1 - False - True - - - - - - True - False - 0 diff --git a/mytwitter.py b/mytwitter.py index 0792ca6..6bd3df9 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -91,6 +91,7 @@ class MyTwitter(): self.window = self.widget_tree.get_widget('window') self.tweet_notebook = self.widget_tree.get_widget('tweet_notebook') self.view_menu = self.widget_tree.get_widget('view_menu') + self.accounts_menu = self.widget_tree.get_widget('accounts_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') @@ -98,7 +99,7 @@ class MyTwitter(): self.following_button = self.widget_tree.get_widget('following_button') self.at_button = self.widget_tree.get_widget('at_button') self.verified_label = self.widget_tree.get_widget('verified_label') - self.account_select = self.widget_tree.get_widget('account_select') + self.account_label = self.widget_tree.get_widget('account_label') def init_widgets(self): @@ -108,14 +109,30 @@ class MyTwitter(): self.context_id = self.status_bar.get_context_id('message') + # Add the accounts to the accounts menu + # Setup the new sub-menu + first_item = None + keys =self.accounts.keys() + keys.sort() + for name in keys: + print 'adding: ' + name + menu_item = gtk.RadioMenuItem(first_item, label=name, use_underline=False) + menu_item.set_draw_as_radio(False) + if name == self.username: + menu_item.set_active(True) + + if first_item is None: + first_item = menu_item + + menu_item.connect('group-changed', self.on_account_changed, name) + self.accounts_menu.append(menu_item) + menu_item.show() + + # Set the account label + self.update_account_label() + # Manual tweaks to the glade UI, to overcome its limitations self.tweet_notebook.remove_page(0) - self.account_select.remove_text(0) - - # Add entries to the account select box, set the default entry - for username in self.accounts.keys(): - self.account_select.append_text(username) - self.account_select.set_active(0) # Add the tabs from last session to the notebook page_num = self.db['active_page'] @@ -129,6 +146,10 @@ class MyTwitter(): gobject.timeout_add(self.refresh_time * 1000, self.update_windows) + def update_account_label(self): + self.account_label.set_text(self.username + ': ') + + # Spawns a thread for each pane, which updates that pane. def update_windows(self): for i in range(0, self.tweet_notebook.get_n_pages()): @@ -480,16 +501,17 @@ class MyTwitter(): self.remove_view(current_pane.get_list_name(), current_pane.get_single_tweet(), current_pane.get_conversation()) - def on_account_changed(self, widget): - new_user = self.account_select.get_active_text() - if self.accounts.has_key(new_user): - self.username = new_user + def on_account_changed(self, widget, new_account): + print 'debug: on_account_changed()' + if self.accounts.has_key(new_account): + self.username = new_account self.api = self.accounts[self.username] + self.update_account_label() def on_lists_ready(self, widget, username, list_names): # Setup the new sub-menu - outer_menu_item = gtk.MenuItem(username) + outer_menu_item = gtk.MenuItem(username, False) self.view_menu.append(outer_menu_item) new_menu = gtk.Menu() outer_menu_item.set_submenu(new_menu) @@ -501,7 +523,7 @@ class MyTwitter(): # Add the items to the submenu, connect handler for l in list_names: - menu_item = gtk.MenuItem(l) + menu_item = gtk.MenuItem(l, False) new_menu.append(menu_item) menu_item.connect('activate', self.on_view_selected, username, l) menu_item.show()