Initial work on remembering active page between sessions - remembers the page num correctly, but doesn't seem to set it properly
This commit is contained in:
parent
e213313b58
commit
3bda037e2a
34
mytwitter.py
34
mytwitter.py
|
@ -32,8 +32,11 @@ class MyTwitter():
|
|||
db_file = os.path.expanduser(config.get('global', 'dbfile'))
|
||||
self.db = shelve.open(db_file)
|
||||
|
||||
if not self.db.has_key('active_page'):
|
||||
self.db['active_page'] = 0
|
||||
|
||||
if not self.db.has_key('open_tabs'):
|
||||
self.db['open_tabs'] = [self.username + '/Home', '@' + self.username, self.username + '/Direct Messages']
|
||||
self.db['open_tabs'] = [(self.username + '/Home', None), ('@' + self.username, None), (self.username + '/Direct Messages', None)]
|
||||
|
||||
if self.refresh_time < 10:
|
||||
self.refresh_time = 10
|
||||
|
@ -75,8 +78,11 @@ class MyTwitter():
|
|||
self.account_select.set_active(0)
|
||||
|
||||
# Add the tabs from last session to the notebook
|
||||
for tab in self.db['open_tabs']:
|
||||
self.add_to_notebook(tab)
|
||||
for tab, single_tweet in self.db['open_tabs']:
|
||||
self.add_to_notebook(tab, single_tweet)
|
||||
|
||||
# Switch to the correct page from the last session
|
||||
self.tweet_notebook.set_current_page(self.db['active_page'])
|
||||
|
||||
# Put Home, @user, Direct Messages, and lists in the View menu for
|
||||
# each user
|
||||
|
@ -219,9 +225,9 @@ class MyTwitter():
|
|||
# Remove one of the views from the tweet notebook.
|
||||
# Called when the close button is clicked on one of the views
|
||||
# or Ctrl + W is pressed while the view is active
|
||||
def remove_view(self, name):
|
||||
def remove_view(self, name, single_tweet):
|
||||
ot = self.db['open_tabs']
|
||||
ot.remove(name)
|
||||
ot.remove((name,single_tweet))
|
||||
self.db['open_tabs'] = ot
|
||||
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
|
@ -231,8 +237,8 @@ class MyTwitter():
|
|||
return
|
||||
|
||||
|
||||
def remove_view_callback(self, event, name):
|
||||
self.remove_view(name)
|
||||
def remove_view_callback(self, event, name, single_tweet):
|
||||
self.remove_view(name, single_tweet)
|
||||
|
||||
|
||||
def add_to_notebook(self, name, single_tweet=None):
|
||||
|
@ -252,9 +258,9 @@ class MyTwitter():
|
|||
|
||||
# We check for the name so that the special case of
|
||||
# the first run is handled...
|
||||
if single_tweet is None and name not in self.db['open_tabs']:
|
||||
if (name, single_tweet) not in self.db['open_tabs']:
|
||||
ot = self.db['open_tabs']
|
||||
ot.append(name)
|
||||
ot.append((name,single_tweet))
|
||||
self.db['open_tabs'] = ot
|
||||
|
||||
is_user = False
|
||||
|
@ -267,7 +273,7 @@ class MyTwitter():
|
|||
new_pane = TweetPane(name, num_entries=self.num_entries, single_tweet=single_tweet, is_user=is_user, following=following, verified=verified)
|
||||
self.tweet_notebook.append_page_menu(new_pane, new_pane.get_tab_label(), gtk.Label(name))
|
||||
self.tweet_notebook.set_tab_reorderable(new_pane, True)
|
||||
new_pane.get_tab_label().connect('close-clicked', self.remove_view_callback, name)
|
||||
new_pane.get_tab_label().connect('close-clicked', self.remove_view_callback, name, single_tweet)
|
||||
new_pane.connect('tweet-reply', self.on_reply)
|
||||
new_pane.connect('tweet-retweet', self.on_retweet)
|
||||
new_pane.connect('tweet-in-reply-to', self.on_reply_to)
|
||||
|
@ -289,6 +295,7 @@ class MyTwitter():
|
|||
|
||||
|
||||
def on_tab_change(self, event, page, page_num):
|
||||
self.db['active_page'] = page_num
|
||||
pane = self.tweet_notebook.get_nth_page(page_num)
|
||||
pane.set_tweets_read()
|
||||
self.update_follow_button(pane)
|
||||
|
@ -303,12 +310,15 @@ class MyTwitter():
|
|||
|
||||
|
||||
def on_tabs_reordered(self, widget, child, page_num):
|
||||
self.db['active_page'] = page_num
|
||||
|
||||
# Clear the persistent tabs list, and recreate it
|
||||
# from scratch
|
||||
tab_names = []
|
||||
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
tab_names.append(self.tweet_notebook.get_nth_page(i).get_list_name())
|
||||
pane = self.tweet_notebook.get_nth_page(i)
|
||||
tab_names.append((pane.get_list_name(), pane.get_single_tweet()))
|
||||
|
||||
self.db['open_tabs'] = tab_names
|
||||
|
||||
|
@ -391,7 +401,7 @@ class MyTwitter():
|
|||
|
||||
def close_current_tab(self):
|
||||
current_pane = self.tweet_notebook.get_nth_page(self.tweet_notebook.get_current_page())
|
||||
self.remove_view(current_pane.get_list_name())
|
||||
self.remove_view(current_pane.get_list_name(), current_pane.get_single_tweet())
|
||||
|
||||
|
||||
def on_account_changed(self, widget):
|
||||
|
|
Reference in New Issue
Block a user