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
This commit is contained in:
parent
5a675ee8d9
commit
48cce6a353
|
@ -36,11 +36,7 @@ class CustomApi(OAuthApi):
|
||||||
|
|
||||||
|
|
||||||
def on_lists_ready(self, widget, lists, ignored):
|
def on_lists_ready(self, widget, lists, ignored):
|
||||||
list_names = []
|
self.sig_proxy.emit('lists-ready', self.username, lists)
|
||||||
for l in lists['lists']:
|
|
||||||
list_names.append(l.name)
|
|
||||||
list_names.sort()
|
|
||||||
self.sig_proxy.emit('lists-ready', self.username, list_names)
|
|
||||||
|
|
||||||
# End class CustomApi
|
# End class CustomApi
|
||||||
|
|
||||||
|
@ -260,14 +256,17 @@ class GetUserLists(ApiThread):
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
lists = []
|
lists = {}
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
while not done:
|
while not done:
|
||||||
done = True
|
done = True
|
||||||
try:
|
try:
|
||||||
with self.api.lock:
|
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:
|
except (HTTPError, URLError) as exception:
|
||||||
print 'debug: GetUserLists had error: ' + str(exception.code)
|
print 'debug: GetUserLists had error: ' + str(exception.code)
|
||||||
sleep(30)
|
sleep(30)
|
||||||
|
|
14
hrafn.py
14
hrafn.py
|
@ -81,6 +81,8 @@ class Hrafn():
|
||||||
|
|
||||||
self.reply_id = None
|
self.reply_id = None
|
||||||
|
|
||||||
|
self.lists = {}
|
||||||
|
|
||||||
# Load up all the programmatic GUI stuff
|
# Load up all the programmatic GUI stuff
|
||||||
self.init_widgets()
|
self.init_widgets()
|
||||||
|
|
||||||
|
@ -489,20 +491,28 @@ class Hrafn():
|
||||||
apithreads.GetFollowing(api=self.api, pane=pane, user=user).start()
|
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
|
# Setup the new sub-menu
|
||||||
outer_menu_item = gtk.MenuItem(username, False)
|
outer_menu_item = gtk.MenuItem(username, False)
|
||||||
self.view_menu.append(outer_menu_item)
|
self.view_menu.append(outer_menu_item)
|
||||||
new_menu = gtk.Menu()
|
new_menu = gtk.Menu()
|
||||||
outer_menu_item.set_submenu(new_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
|
# Insert the default list items
|
||||||
list_names.insert(0, 'Home')
|
list_names.insert(0, 'Home')
|
||||||
list_names.insert(1, '@' + username)
|
list_names.insert(1, '@' + username)
|
||||||
list_names.insert(2, 'Direct Messages')
|
list_names.insert(2, 'Direct Messages')
|
||||||
|
|
||||||
# Add the items to the submenu, connect handler
|
|
||||||
for l in list_names:
|
for l in list_names:
|
||||||
|
# Add the item to the submenu, connect handler
|
||||||
menu_item = gtk.MenuItem(l, False)
|
menu_item = gtk.MenuItem(l, False)
|
||||||
new_menu.append(menu_item)
|
new_menu.append(menu_item)
|
||||||
menu_item.connect('activate', self.on_view_selected, username, l)
|
menu_item.connect('activate', self.on_view_selected, username, l)
|
||||||
|
|
Reference in New Issue
Block a user