Did some ApiThread refactoring, made the refresh button only refresh the current pane, and helped child threads die on exit

This commit is contained in:
Anna 2010-05-06 13:18:02 -04:00
parent d2cf7c2ff5
commit fe1b1cabf2
4 changed files with 67 additions and 57 deletions

2
TODO
View File

@ -16,4 +16,4 @@ bugs:
* Direct Messages have no names, only screen names (may not be fixable without
considerable tweaks to python-twitter)
* Can't always kill tabs - open tab list not always correctly populated?
* Can't always kill application
* Follow/Unfollow and Verified don't get set on current tab when it first appears... need a signal to come back from the TweetPane.

View File

@ -17,10 +17,19 @@ class SafeApi(Api):
class GetTweets(Thread):
def __init__(self, api, list_name, pane, num_entries, username):
class ApiThread(Thread):
def __init__(self, api):
Thread.__init__(self)
self.api = api
self.setDaemon(True)
# End class ApiThread
class GetTweets(ApiThread):
def __init__(self, api, list_name, pane, num_entries, username):
ApiThread.__init__(self, api)
self.list_name = list_name
self.pane = pane
self.num_entries = num_entries
@ -58,7 +67,7 @@ class GetTweets(Thread):
else:
statuses = results_to_statuses(self.api.Search(self.list_name, rpp=self.num_entries))
except HTTPError,URLError:
except (HTTPError, URLError):
statuses = None
gtk.gdk.threads_enter()
@ -72,10 +81,9 @@ class GetTweets(Thread):
class GetSingleTweet(Thread):
def __init__(self, api, pane, single_tweet):
Thread.__init__(self)
self.api = api
class GetSingleTweet(ApiThread):
def __init__(self, pane, single_tweet):
ApiThread.__init__(self, api)
self.pane = pane
self.single_tweet = single_tweet
@ -85,7 +93,7 @@ class GetSingleTweet(Thread):
with self.api.lock:
try:
statuses.append(self.api.GetStatus(self.single_tweet))
except HTTPError,URLError:
except (HTTPError, URLError):
statuses = None
gtk.gdk.threads_enter()
@ -99,10 +107,9 @@ class GetSingleTweet(Thread):
class GetFollowing(Thread):
class GetFollowing(ApiThread):
def __init__(self, api, pane, user):
Thread.__init__(self)
self.api = api
ApiThread.__init__(self, api)
self.pane = pane
self.user = user
@ -114,7 +121,7 @@ class GetFollowing(Thread):
with self.api.lock:
relationship = self.api.ShowFriendships(target_screen_name=screen_name)
following = relationship.source.following
except HTTPError,URLError:
except (HTTPError, URLError):
following = false
self.pane.set_following(following)
@ -123,10 +130,9 @@ class GetFollowing(Thread):
class GetVerified(Thread):
class GetVerified(ApiThread):
def __init__(self, api, pane, user):
Thread.__init__(self)
self.api = api
ApiThread.__init__(self, api)
self.pane = pane
self.user = user
@ -138,12 +144,11 @@ class GetVerified(Thread):
with self.api.lock:
user = self.api.GetUser(screen_name)
verified = user.verified
except HTTPError,URLError:
except (HTTPError, URLError):
verified = false
self.pane.set_verified(verified)
### End class GetVerified

View File

@ -221,7 +221,7 @@
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="update_windows_callback" last_modification_time="Mon, 12 Apr 2010 18:33:51 GMT"/>
<signal name="clicked" handler="update_window_callback" last_modification_time="Thu, 06 May 2010 15:25:15 GMT"/>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -140,11 +140,18 @@ class MyTwitter():
def update_windows(self):
for i in range(0, self.tweet_notebook.get_n_pages()):
pane = self.tweet_notebook.get_nth_page(i)
self.update_single_window(pane)
# We have to return true, so the timeout_add event will keep happening
return True
def update_single_window(self, pane):
list_name = pane.get_list_name()
# Single tweets should never be updated here
if pane.get_single_tweet() is not None:
continue
return
# Determine username and appropriate account to use
found = False
@ -177,12 +184,10 @@ class MyTwitter():
username=username
).start()
# We have to return true, so the timeout_add event will keep happening
return True
def update_windows_callback(self, widget):
self.update_windows()
def update_window_callback(self, widget):
pane = self.tweet_notebook.get_nth_page(self.tweet_notebook.get_current_page())
self.update_single_window(pane)
def update_status(self):