From c7dcaff025f98aa72d428ee0c3a7844e0498d001 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 May 2015 18:35:15 +0200 Subject: [PATCH 1/9] Add navigate option to scroll_page() So you can scroll down & navigate when you're at the bottom. To bind this to space: scroll-page 0 1 next Not sure if it's a good idea to bind this by default? May surprise some people... See #696 --- qutebrowser/browser/commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 0c01260d7..8c29ad317 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -643,14 +643,23 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window', count='count') - def scroll_page(self, x: {'type': float}, y: {'type': float}, count=1): + def scroll_page(self, x: {'type': float}, y: {'type': float}, + navigate=None, count=1): """Scroll the frame page-wise. Args: x: How many pages to scroll to the right. y: How many pages to scroll down. + navigate: :navigate to the next page on bottom count: multiplier """ + frame = self._current_widget().page().currentFrame() + if (navigate is not None and + frame.scrollPosition().y() >= + frame.scrollBarMaximum(Qt.Vertical)): + self.navigate(navigate) + return + mult_x = count * x mult_y = count * y if mult_y.is_integer(): @@ -663,7 +672,6 @@ class CommandDispatcher: mult_y = 0 if mult_x == 0 and mult_y == 0: return - frame = self._current_widget().page().currentFrame() size = frame.geometry() dx = mult_x * size.width() dy = mult_y * size.height() From 8c80f99a32363ebc2b139e7c0074e4c165d992b3 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 May 2015 21:18:44 +0200 Subject: [PATCH 2/9] Improve navigate option to scroll_page() --- qutebrowser/browser/commands.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8c29ad317..735deba47 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -643,21 +643,27 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window', count='count') - def scroll_page(self, x: {'type': float}, y: {'type': float}, - navigate=None, count=1): + def scroll_page(self, x: {'type': float}, y: {'type': float}, *, + top_navigate: {'type': ('prev', 'decrement')}=None, + bottom_navigate: {'type': ('next', 'increment')}=None, + count=1): """Scroll the frame page-wise. Args: x: How many pages to scroll to the right. y: How many pages to scroll down. - navigate: :navigate to the next page on bottom + bottom_navigate: :navigate to the next page on bottom + top_navigate: :navigate to the previous page on top count: multiplier """ frame = self._current_widget().page().currentFrame() - if (navigate is not None and + if (bottom_navigate is not None and frame.scrollPosition().y() >= frame.scrollBarMaximum(Qt.Vertical)): - self.navigate(navigate) + self.navigate(bottom_navigate) + return + elif top_navigate is not None and frame.scrollPosition().y() == 0: + self.navigate(top_navigate) return mult_x = count * x From 9c99c22f1b4edee2d43efe2365beca34a275fbd9 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 May 2015 23:49:48 +0200 Subject: [PATCH 3/9] Fix issue #701 --- qutebrowser/browser/commands.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 735deba47..337823122 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -657,6 +657,9 @@ class CommandDispatcher: count: multiplier """ frame = self._current_widget().page().currentFrame() + if not frame.url().isValid() == '': # Issue 701 + return + if (bottom_navigate is not None and frame.scrollPosition().y() >= frame.scrollBarMaximum(Qt.Vertical)): From 70956aaeca3df4bf0c9842fe443202370f683ff8 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 May 2015 23:57:57 +0200 Subject: [PATCH 4/9] oops --- qutebrowser/browser/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 337823122..5318bdc7d 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -657,7 +657,7 @@ class CommandDispatcher: count: multiplier """ frame = self._current_widget().page().currentFrame() - if not frame.url().isValid() == '': # Issue 701 + if not frame.url().isValid(): # Issue 701 return if (bottom_navigate is not None and From 11b258568d7d29a722ae9b57cefbcce2add11db8 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 31 May 2015 15:02:09 +0200 Subject: [PATCH 5/9] Improve docstring. --- qutebrowser/browser/commands.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 5318bdc7d..8f54ed76b 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -652,8 +652,10 @@ class CommandDispatcher: Args: x: How many pages to scroll to the right. y: How many pages to scroll down. - bottom_navigate: :navigate to the next page on bottom - top_navigate: :navigate to the previous page on top + bottom_navigate: :navigate action (next, increment) to run when + scrolling down at the bottom of the page. + top_navigate: :navigate action (prev, decrement) to run when + scrolling up at the top of the page. count: multiplier """ frame = self._current_widget().page().currentFrame() From cdde1d7dfcb8a07b6d289d932269437f53a4435a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 31 May 2015 15:10:12 +0200 Subject: [PATCH 6/9] command: Add support for custom metavar for docs. --- qutebrowser/commands/command.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 998c4a892..d55597d9d 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -61,7 +61,8 @@ class Command: """ AnnotationInfo = collections.namedtuple('AnnotationInfo', - ['kwargs', 'type', 'flag', 'hide']) + ['kwargs', 'type', 'flag', 'hide', + 'metavar']) def __init__(self, *, handler, name, instance=None, maxsplit=None, hide=False, completion=None, modes=None, not_modes=None, @@ -257,10 +258,10 @@ class Command: pass if isinstance(typ, tuple): - pass + kwargs['metavar'] = annotation_info.metavar or param.name elif utils.is_enum(typ): kwargs['choices'] = [e.name.replace('_', '-') for e in typ] - kwargs['metavar'] = param.name + kwargs['metavar'] = annotation_info.metavar or param.name elif typ is bool: kwargs['action'] = 'store_true' elif typ is not None: @@ -322,11 +323,12 @@ class Command: flag: The short name/flag if overridden. name: The long name if overridden. """ - info = {'kwargs': {}, 'type': None, 'flag': None, 'hide': False} + info = {'kwargs': {}, 'type': None, 'flag': None, 'hide': False, + 'metavar': None} if param.annotation is not inspect.Parameter.empty: log.commands.vdebug("Parsing annotation {}".format( param.annotation)) - for field in ('type', 'flag', 'name', 'hide'): + for field in ('type', 'flag', 'name', 'hide', 'metavar'): if field in param.annotation: info[field] = param.annotation[field] if 'nargs' in param.annotation: From 6b550defaee70d7817b4d58c2a864486856bfe3e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 31 May 2015 15:10:35 +0200 Subject: [PATCH 7/9] scroll-page: Add custom metavar for navigate-*. --- qutebrowser/browser/commands.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8f54ed76b..664cd752f 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -644,8 +644,10 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window', count='count') def scroll_page(self, x: {'type': float}, y: {'type': float}, *, - top_navigate: {'type': ('prev', 'decrement')}=None, - bottom_navigate: {'type': ('next', 'increment')}=None, + top_navigate: {'type': ('prev', 'decrement'), + 'metavar': 'ACTION'}=None, + bottom_navigate: {'type': ('next', 'increment'), + 'metavar': 'ACTION'}=None, count=1): """Scroll the frame page-wise. From 1814b672d7e6e2504a24eab0df3f091abec18a1e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 31 May 2015 15:11:04 +0200 Subject: [PATCH 8/9] Regenerate docs. --- README.asciidoc | 2 +- doc/help/commands.asciidoc | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index c651ffc33..437ab8734 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -141,10 +141,10 @@ Contributors, sorted by the number of commits in descending order: * Artur Shaik * ZDarian * Peter Vilim +* Martin Tournoij * John ShaggyTwoDope Jenkins * Jimmy * Zach-Button -* Martin Tournoij * rikn00 * Patric Schmitz * Martin Zimmermann diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index c33bccaaf..fa835f53a 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1009,7 +1009,7 @@ multiplier [[scroll-page]] === scroll-page -Syntax: +:scroll-page 'x' 'y'+ +Syntax: +:scroll-page [*--top-navigate* 'ACTION'] [*--bottom-navigate* 'ACTION'] 'x' 'y'+ Scroll the frame page-wise. @@ -1017,6 +1017,12 @@ Scroll the frame page-wise. * +'x'+: How many pages to scroll to the right. * +'y'+: How many pages to scroll down. +==== optional arguments +* +*-t*+, +*--top-navigate*+: :navigate action (prev, decrement) to run when scrolling up at the top of the page. + +* +*-b*+, +*--bottom-navigate*+: :navigate action (next, increment) to run when scrolling down at the bottom of the page. + + ==== count multiplier From 54c1cd7c05e5780460a117c83a9e8c9e77e71e7b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 31 May 2015 15:11:37 +0200 Subject: [PATCH 9/9] Add link to issue. --- qutebrowser/browser/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 664cd752f..2c008fd9e 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -661,7 +661,8 @@ class CommandDispatcher: count: multiplier """ frame = self._current_widget().page().currentFrame() - if not frame.url().isValid(): # Issue 701 + if not frame.url().isValid(): + # See https://github.com/The-Compiler/qutebrowser/issues/701 return if (bottom_navigate is not None and