From 8fcd2212a417d34b7ded3d153362fab61a94f944 Mon Sep 17 00:00:00 2001 From: ysakamoto Date: Sat, 11 Apr 2015 17:47:35 -0500 Subject: [PATCH 1/4] page up/down implemented --- rtv/page.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index d55b511..726e83e 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -188,6 +188,16 @@ class BasePage(object): self._move_cursor(1) self.clear_input_queue() + @BaseController.register('m') + def move_cursor_page_down(self): + self._move_cursor(1, page_ud=True) + self.clear_input_queue() + + @BaseController.register('n') + def move_cursor_page_up(self): + self._move_cursor(-1, page_ud=True) + self.clear_input_queue() + def clear_input_queue(self): "Clear excessive input caused by the scroll wheel or holding down a key" @@ -369,11 +379,37 @@ class BasePage(object): def _remove_cursor(self): self._edit_cursor(curses.A_NORMAL) - def _move_cursor(self, direction): + def _move_cursor(self, direction, page_ud=False): self._remove_cursor() - valid, redraw = self.nav.move(direction, len(self._subwindows)) + if page_ud: + + # top of submission page: act as normal move + if self.nav.absolute_index < 0: + valid, redraw = self.nav.move(direction, len(self._subwindows)) + # top of submission comment: go back to the title + elif self.nav.absolute_index == 0 and direction < 0: + valid, redraw = self.nav.move(direction, len(self._subwindows)) + else: + # first page: goes up to the top + if self.nav.absolute_index < len(self._subwindows)\ + and direction < 0: + self.nav.page_index = 0 + self.nav.cursor_index = 0 + self.nav.inverted = False + valid = True + else: + self.nav.page_index += len(self._subwindows)*direction + valid = self.nav._is_valid(self.nav.absolute_index) + if not valid: + self.nav.page_index -= len(self._subwindows)*direction + + redraw = True + + else: + valid, redraw = self.nav.move(direction, len(self._subwindows)) + if not valid: curses.flash() @@ -396,4 +432,4 @@ class BasePage(object): for row in range(n_rows): window.chgat(row, 0, 1, attribute) - window.refresh() \ No newline at end of file + window.refresh() From 0fae751d4482d4d4fa88a69bbf1615a1329fa22c Mon Sep 17 00:00:00 2001 From: ysakamoto Date: Sat, 11 Apr 2015 17:58:12 -0500 Subject: [PATCH 2/4] submission mode behavior change --- rtv/page.py | 54 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 726e83e..11a7274 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -84,6 +84,35 @@ class Navigator(object): return valid, redraw + def move_page(self, direction, n_windows): + """Move the page and cursor down (positive direction) or up (negative + direction)""" + + # top of submission page: act as normal move + if self.absolute_index < 0: + valid, redraw = self.move(direction, n_windows) + else: + # first page + if self.absolute_index < n_windows and direction < 0: + self.page_index = -1 + self.cursor_index = 0 + self.inverted = False + + # not submission mode: starting index is 0 + if not self._is_valid(self.absolute_index): + self.page_index = 0 + + valid = True + else: + self.page_index += n_windows*direction + valid = self._is_valid(self.absolute_index) + if not valid: + self.page_index -= n_windows*direction + + redraw = True + + return valid, redraw + def flip(self, n_windows): "Flip the orientation of the page" @@ -384,29 +413,8 @@ class BasePage(object): self._remove_cursor() if page_ud: - - # top of submission page: act as normal move - if self.nav.absolute_index < 0: - valid, redraw = self.nav.move(direction, len(self._subwindows)) - # top of submission comment: go back to the title - elif self.nav.absolute_index == 0 and direction < 0: - valid, redraw = self.nav.move(direction, len(self._subwindows)) - else: - # first page: goes up to the top - if self.nav.absolute_index < len(self._subwindows)\ - and direction < 0: - self.nav.page_index = 0 - self.nav.cursor_index = 0 - self.nav.inverted = False - valid = True - else: - self.nav.page_index += len(self._subwindows)*direction - valid = self.nav._is_valid(self.nav.absolute_index) - if not valid: - self.nav.page_index -= len(self._subwindows)*direction - - redraw = True - + valid, redraw = self.nav.move_page(direction, + len(self._subwindows)) else: valid, redraw = self.nav.move(direction, len(self._subwindows)) From 294f54d9afcceb384725610559c452d70cf71dec Mon Sep 17 00:00:00 2001 From: ysakamoto Date: Sun, 12 Apr 2015 18:03:16 -0500 Subject: [PATCH 3/4] fixed cursor position going over the number of windows --- rtv/page.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 11a7274..8ba4276 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -85,7 +85,7 @@ class Navigator(object): return valid, redraw def move_page(self, direction, n_windows): - """Move the page and cursor down (positive direction) or up (negative + """Move the page down (positive direction) or up (negative direction)""" # top of submission page: act as normal move @@ -101,18 +101,26 @@ class Navigator(object): # not submission mode: starting index is 0 if not self._is_valid(self.absolute_index): self.page_index = 0 - valid = True else: - self.page_index += n_windows*direction - valid = self._is_valid(self.absolute_index) - if not valid: - self.page_index -= n_windows*direction + valid = False + adj = 0 + # check if reached the bottom + while not valid: + n_move = n_windows-adj + if n_move == 0: + break + + self.page_index += n_move*direction + valid = self._is_valid(self.absolute_index) + if not valid: + self.page_index -= n_move*direction + adj += 1 redraw = True return valid, redraw - + def flip(self, n_windows): "Flip the orientation of the page" @@ -432,6 +440,10 @@ class BasePage(object): if self.nav.absolute_index < 0: return + # Don't allow the cursor to go over the subwindow number + if self.nav.cursor_index >= len(self._subwindows): + self.nav.cursor_index = len(self._subwindows)-1 + window, attr = self._subwindows[self.nav.cursor_index] if attr is not None: attribute |= attr From f31242dfbdd04bdee19bfd8bd651254f8e9b5390 Mon Sep 17 00:00:00 2001 From: ysakamoto Date: Sun, 12 Apr 2015 18:06:20 -0500 Subject: [PATCH 4/4] key change. m: pageup, n: pagedown --- rtv/page.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 8ba4276..1551492 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -225,12 +225,12 @@ class BasePage(object): self._move_cursor(1) self.clear_input_queue() - @BaseController.register('m') + @BaseController.register('n') def move_cursor_page_down(self): self._move_cursor(1, page_ud=True) self.clear_input_queue() - @BaseController.register('n') + @BaseController.register('m') def move_cursor_page_up(self): self._move_cursor(-1, page_ud=True) self.clear_input_queue()