From b959b5d4bd4be42b63c9e2a5219a3a2be9a15f80 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sat, 4 Aug 2018 01:03:16 -0400 Subject: [PATCH] Removing the gilded sorting option from the submission and search result pages --- .gitignore | 1 - CONTROLS.rst | 1 + rtv/docs.py | 6 +++++- rtv/page.py | 21 ++++++++++++++------- rtv/submission_page.py | 5 +---- rtv/subreddit_page.py | 20 ++++++++------------ rtv/subscription_page.py | 1 + 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 144fc1f..1035dd7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ !.gitignore !.gitattributes !.coveragerc -!CONTROLS.rst *~ *.pyc *.log diff --git a/CONTROLS.rst b/CONTROLS.rst index aecd96a..9b8a2ec 100644 --- a/CONTROLS.rst +++ b/CONTROLS.rst @@ -56,6 +56,7 @@ The ``/`` prompt accepts subreddits in the following formats * ``/r/python`` * ``/r/python/new`` * ``/r/python/controversial-year`` +# ``/r/python/gilded`` * ``/r/python+linux`` supports multireddits * ``/r/front`` will redirect to the front page * ``/u/me`` will display your submissions diff --git a/rtv/docs.py b/rtv/docs.py index 27e095a..886a552 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -90,10 +90,14 @@ https://github.com/michael-lazar/rtv - /domain/python.org (search by domain) """ -BANNER = """ +BANNER_SUBREDDIT = """ [1]hot [2]top [3]rising [4]new [5]controversial [6]gilded """ +BANNER_SUBMISSION = """ +[1]hot [2]top [3]rising [4]new [5]controversial +""" + BANNER_SEARCH = """ [1]relevance [2]top [3]comments [4]new """ diff --git a/rtv/page.py b/rtv/page.py index c9f24f9..393c000 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -39,6 +39,7 @@ class PageController(Controller): class Page(object): + BANNER = None FOOTER = None def __init__(self, reddit, term, config, oauth): @@ -353,7 +354,9 @@ class Page(object): continue def draw(self): - + """ + Clear the terminal screen and redraw all of the sub-windows + """ n_rows, n_cols = self.term.stdscr.getmaxyx() if n_rows < self.term.MIN_HEIGHT or n_cols < self.term.MIN_WIDTH: # TODO: Will crash when you try to navigate if the terminal is too @@ -369,7 +372,9 @@ class Page(object): self.term.stdscr.refresh() def _draw_header(self): - + """ + Draw the title bar at the top of the screen + """ n_rows, n_cols = self.term.stdscr.getmaxyx() # Note: 2 argument form of derwin breaks PDcurses on Windows 7! @@ -427,13 +432,15 @@ class Page(object): self._row += 1 def _draw_banner(self): - + """ + Draw the banner with sorting options at the top of the page + """ n_rows, n_cols = self.term.stdscr.getmaxyx() window = self.term.stdscr.derwin(1, n_cols, self._row, 0) window.erase() window.bkgd(str(' '), self.term.attr('OrderBar')) - banner = docs.BANNER_SEARCH if self.content.query else docs.BANNER + banner = docs.BANNER_SEARCH if self.content.query else self.BANNER items = banner.strip().split(' ') distance = (n_cols - sum(len(t) for t in items) - 1) / (len(items) - 1) @@ -452,7 +459,6 @@ class Page(object): """ Loop through submissions and fill up the content page. """ - n_rows, n_cols = self.term.stdscr.getmaxyx() window = self.term.stdscr.derwin(n_rows - self._row - 1, n_cols, self._row, 0) window.erase() @@ -525,7 +531,9 @@ class Page(object): self._row += win_n_rows def _draw_footer(self): - + """ + Draw the key binds help bar at the bottom of the screen + """ n_rows, n_cols = self.term.stdscr.getmaxyx() window = self.term.stdscr.derwin(1, n_cols, self._row, 0) window.erase() @@ -548,7 +556,6 @@ class Page(object): self.term.flash() def _prompt_period(self, order): - choices = { '\n': order, '1': '{0}-hour'.format(order), diff --git a/rtv/submission_page.py b/rtv/submission_page.py index 15480eb..72881ab 100644 --- a/rtv/submission_page.py +++ b/rtv/submission_page.py @@ -17,6 +17,7 @@ class SubmissionController(PageController): class SubmissionPage(Page): + BANNER = docs.BANNER_SUBMISSION FOOTER = docs.FOOTER_SUBMISSION def __init__(self, reddit, term, config, oauth, url=None, submission=None): @@ -48,10 +49,6 @@ class SubmissionPage(Page): def sort_content_rising(self): self.refresh_content(order='rising') - @SubmissionController.register(Command('SORT_GILDED')) - def sort_content_gilded(self): - self.refresh_content(order='gilded') - @SubmissionController.register(Command('SORT_NEW')) def sort_content_new(self): self.refresh_content(order='new') diff --git a/rtv/subreddit_page.py b/rtv/subreddit_page.py index 646a1be..6a857d9 100644 --- a/rtv/subreddit_page.py +++ b/rtv/subreddit_page.py @@ -19,6 +19,7 @@ class SubredditController(PageController): class SubredditPage(Page): + BANNER = docs.BANNER_SUBREDDIT FOOTER = docs.FOOTER_SUBREDDIT def __init__(self, reddit, term, config, oauth, name): @@ -66,7 +67,6 @@ class SubredditPage(Page): else: self.refresh_content(order='hot') - @SubredditController.register(Command('SORT_TOP')) def sort_content_top(self): order = self._prompt_period('top') @@ -86,17 +86,6 @@ class SubredditPage(Page): else: self.refresh_content(order='rising') - @SubredditController.register(Command('SORT_GILDED')) - def sort_content_gilded(self): - if self.content.query: - order = self._prompt_period('comments') - if order is None: - self.term.show_notification('Invalid option') - else: - self.refresh_content(order=order) - else: - self.refresh_content(order='gilded') - @SubredditController.register(Command('SORT_NEW')) def sort_content_new(self): self.refresh_content(order='new') @@ -112,6 +101,13 @@ class SubredditPage(Page): else: self.refresh_content(order=order) + @SubredditController.register(Command('SORT_GILDED')) + def sort_content_gilded(self): + if self.content.query: + self.term.flash() + else: + self.refresh_content(order='gilded') + @SubredditController.register(Command('SUBREDDIT_SEARCH')) def search_subreddit(self, name=None): """ diff --git a/rtv/subscription_page.py b/rtv/subscription_page.py index 5616728..d0f29aa 100644 --- a/rtv/subscription_page.py +++ b/rtv/subscription_page.py @@ -13,6 +13,7 @@ class SubscriptionController(PageController): class SubscriptionPage(Page): + BANNER = None FOOTER = docs.FOOTER_SUBSCRIPTION def __init__(self, reddit, term, config, oauth, content_type='subreddit'):