Reworked how adding lists is handled (so the child thread does the actual work and we can employ a Condition object to allow the add_to_notebook function to have the list information available) and put in code that should list the lists a user is in. Currently seems to not function as expected, however.

This commit is contained in:
Anna 2010-06-02 17:00:11 -04:00
parent 48cce6a353
commit 8fac5ad7c2
3 changed files with 74 additions and 23 deletions

View file

@ -6,7 +6,7 @@ import sys, ConfigParser, os, re, optparse, shelve
import gtk, gtk.glade, gobject
from urllib2 import HTTPError,URLError
from twitterwidgets import TweetPane
from threading import enumerate
from threading import enumerate,Condition
import apithreads
@ -61,7 +61,7 @@ class Hrafn():
# Now set up the accounts and their corresponding APIs
self.accounts = {}
for token in self.db['tokens']:
api = apithreads.CustomApi(token)
api = apithreads.CustomApi(token, self)
self.add_account(api)
self.username = self.db['active_user']
@ -82,6 +82,7 @@ class Hrafn():
self.reply_id = None
self.lists = {}
self.lists_cond = Condition()
# Load up all the programmatic GUI stuff
self.init_widgets()
@ -335,6 +336,29 @@ class Hrafn():
new_pane.connect('tweets-read', self.on_read_tweets_changed)
if is_user:
# Find the lists this user is currently in, and pass those
# to the pane
found_lists = []
username = re.sub('user: ', '', name)
# We're not going to change the data, just access it.
# This condition only exists to let us know when the lists are
# ready
# Ergo, we can release it right after we get out of the conditional
self.lists_cond.acquire()
while not self.lists.has_key(self.username):
self.lists_cond.wait()
self.lists_cond.release()
for list_name in self.lists[self.username].keys():
try:
i = self.lists[self.username][list_name].index(username)
found_lists.append(list_name)
except:
pass
new_pane.set_lists(found_lists)
new_pane.connect('at-clicked', self.on_at_button_clicked)
new_pane.connect('follow-clicked', self.on_follow_button_clicked)
apithreads.GetFollowing(api=self.api, pane=new_pane, user=name).start()
@ -491,18 +515,27 @@ class Hrafn():
apithreads.GetFollowing(api=self.api, pane=pane, user=user).start()
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 '''
def add_lists(self, username, list_data):
'''
This function is called by a child thread.
It takes list info from the API, stores it for later use, and uses
the data to populate the Views menu
'''
# 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)
self.lists_cond.acquire()
# Save the member info in a data structure for later usage
self.lists[username] = list_data
self.lists_cond.notify()
self.lists_cond.release()
list_names = list_data.keys()
list_names.sort()
@ -557,7 +590,7 @@ class Hrafn():
if token is None:
return
api = apithreads.CustomApi(token)
api = apithreads.CustomApi(token, self)
if not self.accounts.has_key(api.username):
tokens = self.db['tokens']
@ -569,7 +602,6 @@ class Hrafn():
def add_account(self, api):
username = api.username
self.accounts[username] = api
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
# Add account's menu item
menu_item = gtk.RadioMenuItem(self.first_account_item, label=username, use_underline=False)