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:
parent
d2cf7c2ff5
commit
fe1b1cabf2
2
TODO
2
TODO
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
81
mytwitter.py
81
mytwitter.py
|
@ -140,49 +140,54 @@ 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)
|
||||
list_name = pane.get_list_name()
|
||||
|
||||
# Single tweets should never be updated here
|
||||
if pane.get_single_tweet() is not None:
|
||||
continue
|
||||
|
||||
# Determine username and appropriate account to use
|
||||
found = False
|
||||
|
||||
username = re.sub('/Home', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
username = re.sub('@', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
username = re.sub('/Direct Messages', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
account = self.api
|
||||
username = self.username
|
||||
|
||||
apithreads.GetTweets(api=account,
|
||||
list_name=list_name,
|
||||
pane=pane,
|
||||
num_entries=self.num_entries,
|
||||
username=username
|
||||
).start()
|
||||
self.update_single_window(pane)
|
||||
|
||||
# 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_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:
|
||||
return
|
||||
|
||||
# Determine username and appropriate account to use
|
||||
found = False
|
||||
|
||||
username = re.sub('/Home', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
username = re.sub('@', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
username = re.sub('/Direct Messages', '', list_name)
|
||||
if self.accounts.has_key(username):
|
||||
account = self.accounts[username]
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
account = self.api
|
||||
username = self.username
|
||||
|
||||
apithreads.GetTweets(api=account,
|
||||
list_name=list_name,
|
||||
pane=pane,
|
||||
num_entries=self.num_entries,
|
||||
username=username
|
||||
).start()
|
||||
|
||||
|
||||
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):
|
||||
|
|
Reference in New Issue
Block a user