Ability to open highlighted subreddit and go back

This commit is contained in:
Théo Piboubès
2015-08-10 00:33:48 +02:00
parent 77db8f6c5c
commit 0da69a1935
2 changed files with 17 additions and 11 deletions

View File

@@ -169,7 +169,6 @@ class SubredditPage(BasePage):
page = SubscriptionPage(self.stdscr, self.reddit) page = SubscriptionPage(self.stdscr, self.reddit)
page.loop() page.loop()
self.refresh_content()
@staticmethod @staticmethod
def draw_item(win, data, inverted=False): def draw_item(win, data, inverted=False):

View File

@@ -37,17 +37,24 @@ class SubscriptionPage(BasePage):
def refresh_content(self): def refresh_content(self):
"Re-download all subscriptions and reset the page index" "Re-download all subscriptions and reset the page index"
try:
self.content = SubscriptionContent.get_list(self.reddit, self.loader) self.content = SubscriptionContent.get_list(self.reddit, self.loader)
except AccountError:
show_notification(self.stdscr, ['Not logged in'])
except SubredditError:
show_notification(self.stdscr, ['Invalid subreddit'])
except requests.HTTPError:
show_notification(self.stdscr, ['Could not reach subreddit'])
else:
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
@SubscriptionController.register(curses.KEY_ENTER, 10)
def open_selected_subreddit(self):
"Open the selected subreddit"
from .subreddit import SubredditPage
data = self.content.get(self.nav.absolute_index)
page = SubredditPage(self.stdscr, self.reddit, data['name'][2:]) # Strip the leading /r
page.loop()
@SubscriptionController.register(curses.KEY_LEFT)
def close_subscriptions(self):
"Close subscriptions and return to the subreddit page"
self.active = False
@staticmethod @staticmethod
def draw_item(win, data, inverted=False): def draw_item(win, data, inverted=False):
n_rows, n_cols = win.getmaxyx() n_rows, n_cols = win.getmaxyx()