From 48cce6a35370fc170910ba06cdab6ea560daa304 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 2 Jun 2010 13:53:03 -0400 Subject: [PATCH] Made some changes to the api threads and related callback so that we can save the members in each list into a data structure. This will help when building out some more List API functionality --- apithreads.py | 13 ++++++------- hrafn.py | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apithreads.py b/apithreads.py index 04768be..e8ca475 100644 --- a/apithreads.py +++ b/apithreads.py @@ -36,11 +36,7 @@ class CustomApi(OAuthApi): def on_lists_ready(self, widget, lists, ignored): - list_names = [] - for l in lists['lists']: - list_names.append(l.name) - list_names.sort() - self.sig_proxy.emit('lists-ready', self.username, list_names) + self.sig_proxy.emit('lists-ready', self.username, lists) # End class CustomApi @@ -260,14 +256,17 @@ class GetUserLists(ApiThread): def run(self): - lists = [] + lists = {} done = False while not done: done = True try: with self.api.lock: - lists = self.api.GetUserLists() + twitter_lists = self.api.GetUserLists() + for name in [l.name for l in twitter_lists['lists']]: + list_members = self.api.GetListMembers(name) + lists[name] = [u.name for u in list_members['users']] except (HTTPError, URLError) as exception: print 'debug: GetUserLists had error: ' + str(exception.code) sleep(30) diff --git a/hrafn.py b/hrafn.py index 196466d..6cced84 100755 --- a/hrafn.py +++ b/hrafn.py @@ -81,6 +81,8 @@ class Hrafn(): self.reply_id = None + self.lists = {} + # Load up all the programmatic GUI stuff self.init_widgets() @@ -489,20 +491,28 @@ class Hrafn(): apithreads.GetFollowing(api=self.api, pane=pane, user=user).start() - def on_lists_ready(self, widget, username, list_names): + def on_lists_ready(self, widget, username, list_data): + ''' This callback takes information from a child thread that grabs list info from the API, and stores that info for later use ''' + # Setup the new sub-menu 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) + # Save the member info in a data structure for later usage + self.lists[username] = list_data + + list_names = list_data.keys() + list_names.sort() + # Insert the default list items list_names.insert(0, 'Home') list_names.insert(1, '@' + username) list_names.insert(2, 'Direct Messages') - # Add the items to the submenu, connect handler for l in list_names: + # Add the item to the submenu, connect handler menu_item = gtk.MenuItem(l, False) new_menu.append(menu_item) menu_item.connect('activate', self.on_view_selected, username, l)