From b585f25d7beb8a0c85204e86c19c8698c95ed87f Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 12:36:49 +0100 Subject: [PATCH 01/11] scroll sensitivity --- CHANGELOG.md | 2 ++ src/textual/app.py | 2 ++ src/textual/widget.py | 36 +++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a53611dc..429ae1f8e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added the coroutines `Animator.wait_until_complete` and `pilot.wait_for_scheduled_animations` that allow waiting for all current and scheduled animations https://github.com/Textualize/textual/issues/1658 - Added the method `Animator.is_being_animated` that checks if an attribute of an object is being animated or is scheduled for animation +- Added App.scroll_sensitivity to adjust how many lines the scroll wheel moves the scroll position https://github.com/orgs/Textualize/projects/5?pane=issue&itemId=12998591 +- Added Shift+scroll wheel and ctrl+scroll wheen to scroll horizontally ### Changed diff --git a/src/textual/app.py b/src/textual/app.py index 8712353e1e..b43960396d 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -369,6 +369,8 @@ def __init__( self.css_path = css_paths self._registry: WeakSet[DOMNode] = WeakSet() + self.scroll_sensitivity: float = 3 + self._installed_screens: WeakValueDictionary[ str, Screen | Callable[[], Screen] ] = WeakValueDictionary() diff --git a/src/textual/widget.py b/src/textual/widget.py index ca34cd05bb..5936602616 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -1575,7 +1575,7 @@ def scroll_left( """ return self.scroll_to( - x=self.scroll_target_x - 1, + x=self.scroll_target_x - self.app.scroll_sensitivity, animate=animate, speed=speed, duration=duration, @@ -1607,7 +1607,7 @@ def scroll_right( """ return self.scroll_to( - x=self.scroll_target_x + 1, + x=self.scroll_target_x + self.app.scroll_sensitivity, animate=animate, speed=speed, duration=duration, @@ -1639,7 +1639,7 @@ def scroll_down( """ return self.scroll_to( - y=self.scroll_target_y + 1, + y=self.scroll_target_y + self.app.scroll_sensitivity, animate=animate, speed=speed, duration=duration, @@ -1671,7 +1671,7 @@ def scroll_up( """ return self.scroll_to( - y=self.scroll_target_y - 1, + y=self.scroll_target_y - +self.app.scroll_sensitivity, animate=animate, speed=speed, duration=duration, @@ -2478,15 +2478,25 @@ def _on_descendant_focus(self, event: events.DescendantBlur) -> None: if self._has_focus_within: self.app.update_styles(self) - def _on_mouse_scroll_down(self, event) -> None: - if self.allow_vertical_scroll: - if self.scroll_down(animate=False): - event.stop() - - def _on_mouse_scroll_up(self, event) -> None: - if self.allow_vertical_scroll: - if self.scroll_up(animate=False): - event.stop() + def _on_mouse_scroll_down(self, event: events.MouseScrollDown) -> None: + if event.ctrl or event.shift: + if self.allow_horizontal_scroll: + if self.scroll_right(animate=False): + event.stop() + else: + if self.allow_vertical_scroll: + if self.scroll_down(animate=False): + event.stop() + + def _on_mouse_scroll_up(self, event: events.MouseScrollUp) -> None: + if event.ctrl or event.shift: + if self.allow_horizontal_scroll: + if self.scroll_left(animate=False): + event.stop() + else: + if self.allow_vertical_scroll: + if self.scroll_up(animate=False): + event.stop() def _on_scroll_to(self, message: ScrollTo) -> None: if self._allow_scroll: From ea6afc957f4dfc7f91d35d47b84d2dc593304213 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 12:44:58 +0100 Subject: [PATCH 02/11] separate scroll sensitivity --- src/textual/app.py | 3 ++- src/textual/widget.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index b43960396d..142a51460e 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -369,7 +369,8 @@ def __init__( self.css_path = css_paths self._registry: WeakSet[DOMNode] = WeakSet() - self.scroll_sensitivity: float = 3 + self.scroll_sensitivity_x: float = 4 + self.scroll_sensitivity_y: float = 2 self._installed_screens: WeakValueDictionary[ str, Screen | Callable[[], Screen] diff --git a/src/textual/widget.py b/src/textual/widget.py index 5936602616..d2d78c14bb 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -1575,7 +1575,7 @@ def scroll_left( """ return self.scroll_to( - x=self.scroll_target_x - self.app.scroll_sensitivity, + x=self.scroll_target_x - self.app.scroll_sensitivity_x, animate=animate, speed=speed, duration=duration, @@ -1607,7 +1607,7 @@ def scroll_right( """ return self.scroll_to( - x=self.scroll_target_x + self.app.scroll_sensitivity, + x=self.scroll_target_x + self.app.scroll_sensitivity_x, animate=animate, speed=speed, duration=duration, @@ -1639,7 +1639,7 @@ def scroll_down( """ return self.scroll_to( - y=self.scroll_target_y + self.app.scroll_sensitivity, + y=self.scroll_target_y + self.app.scroll_sensitivity_y, animate=animate, speed=speed, duration=duration, @@ -1671,7 +1671,7 @@ def scroll_up( """ return self.scroll_to( - y=self.scroll_target_y - +self.app.scroll_sensitivity, + y=self.scroll_target_y - +self.app.scroll_sensitivity_y, animate=animate, speed=speed, duration=duration, From 52ae868ddf3e9a33e6f25d73b54d806149c73d23 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 12:46:50 +0100 Subject: [PATCH 03/11] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 429ae1f8e1..78857f76cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added the coroutines `Animator.wait_until_complete` and `pilot.wait_for_scheduled_animations` that allow waiting for all current and scheduled animations https://github.com/Textualize/textual/issues/1658 - Added the method `Animator.is_being_animated` that checks if an attribute of an object is being animated or is scheduled for animation -- Added App.scroll_sensitivity to adjust how many lines the scroll wheel moves the scroll position https://github.com/orgs/Textualize/projects/5?pane=issue&itemId=12998591 +- Added App.scroll_sensitivity_x and App.scroll_sensitivity_y to adjust how many lines the scroll wheel moves the scroll position https://github.com/orgs/Textualize/projects/5?pane=issue&itemId=12998591 - Added Shift+scroll wheel and ctrl+scroll wheen to scroll horizontally ### Changed From 18946eaa09cfb0245c900631105e7b391e57f431 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 12:53:45 +0100 Subject: [PATCH 04/11] doc attributes --- src/textual/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/textual/app.py b/src/textual/app.py index 142a51460e..286278b040 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -370,7 +370,9 @@ def __init__( self._registry: WeakSet[DOMNode] = WeakSet() self.scroll_sensitivity_x: float = 4 + """Number of lines to scroll in the X direction with wheel or trackpad.""" self.scroll_sensitivity_y: float = 2 + """Number of lines to scroll in the Y direction with wheel or trackpad.""" self._installed_screens: WeakValueDictionary[ str, Screen | Callable[[], Screen] From 7523c6d680687ac0c252d6675e7622e23e0077b8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 12:56:21 +0100 Subject: [PATCH 05/11] use floats --- src/textual/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index 286278b040..70554beec2 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -369,9 +369,9 @@ def __init__( self.css_path = css_paths self._registry: WeakSet[DOMNode] = WeakSet() - self.scroll_sensitivity_x: float = 4 + self.scroll_sensitivity_x: float = 4.0 """Number of lines to scroll in the X direction with wheel or trackpad.""" - self.scroll_sensitivity_y: float = 2 + self.scroll_sensitivity_y: float = 2.0 """Number of lines to scroll in the Y direction with wheel or trackpad.""" self._installed_screens: WeakValueDictionary[ From eb91fc05795526d43df3f83efad381fc56604e81 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 13:01:44 +0100 Subject: [PATCH 06/11] snapshot fix --- .../__snapshots__/test_snapshots.ambr | 162 +++++++++--------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 52b617982e..1883f87a24 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -10487,169 +10487,169 @@ font-weight: 700; } - .terminal-832370059-matrix { + .terminal-3394521078-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-832370059-title { + .terminal-3394521078-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-832370059-r1 { fill: #c5c8c6 } - .terminal-832370059-r2 { fill: #e3e3e3 } - .terminal-832370059-r3 { fill: #e1e1e1 } - .terminal-832370059-r4 { fill: #23568b } - .terminal-832370059-r5 { fill: #e2e2e2 } - .terminal-832370059-r6 { fill: #004578 } - .terminal-832370059-r7 { fill: #14191f } - .terminal-832370059-r8 { fill: #262626 } - .terminal-832370059-r9 { fill: #e2e2e2;font-weight: bold;text-decoration: underline; } - .terminal-832370059-r10 { fill: #e2e2e2;font-weight: bold } - .terminal-832370059-r11 { fill: #7ae998 } - .terminal-832370059-r12 { fill: #4ebf71;font-weight: bold } - .terminal-832370059-r13 { fill: #008139 } - .terminal-832370059-r14 { fill: #dde8f3;font-weight: bold } - .terminal-832370059-r15 { fill: #ddedf9 } + .terminal-3394521078-r1 { fill: #c5c8c6 } + .terminal-3394521078-r2 { fill: #e3e3e3 } + .terminal-3394521078-r3 { fill: #e1e1e1 } + .terminal-3394521078-r4 { fill: #23568b } + .terminal-3394521078-r5 { fill: #004578 } + .terminal-3394521078-r6 { fill: #e2e2e2 } + .terminal-3394521078-r7 { fill: #262626 } + .terminal-3394521078-r8 { fill: #e2e2e2;font-weight: bold;text-decoration: underline; } + .terminal-3394521078-r9 { fill: #14191f } + .terminal-3394521078-r10 { fill: #e2e2e2;font-weight: bold } + .terminal-3394521078-r11 { fill: #7ae998 } + .terminal-3394521078-r12 { fill: #4ebf71;font-weight: bold } + .terminal-3394521078-r13 { fill: #008139 } + .terminal-3394521078-r14 { fill: #dde8f3;font-weight: bold } + .terminal-3394521078-r15 { fill: #ddedf9 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - Textual Demo + Textual Demo - - - - Textual Demo - ▅▅ - - TOP - - ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▃ - - Widgets - Textual Demo - - Welcome! Textual is a framework for creating sophisticated - Rich contentapplications with the terminal. - - ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ - Start - CSS▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ - - ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ - - - - - - - - - - -                           Widgets                            -  CTRL+C  Quit  CTRL+B  Sidebar  CTRL+T  Toggle Dark mode  CTRL+S  Screenshot  F1  Notes  + + + + Textual Demo + ▁▁ + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + TOP + + Textual Demo + ▇▇ + WidgetsWelcome! Textual is a framework for creating sophisticated + applications with the terminal. + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + Rich contentStart + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + CSS + + + + + + + + + +                           Widgets                            + + + Textual widgets are powerful interactive components. +  CTRL+C  Quit  CTRL+B  Sidebar  CTRL+T  Toggle Dark mode  CTRL+S  Screenshot  F1  Notes  From 144be3242911d1a84c8585690238c24b43d12e99 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 13:10:07 +0100 Subject: [PATCH 07/11] update docstring [skip CI] --- src/textual/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/app.py b/src/textual/app.py index 70554beec2..41a66b20cf 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -370,7 +370,7 @@ def __init__( self._registry: WeakSet[DOMNode] = WeakSet() self.scroll_sensitivity_x: float = 4.0 - """Number of lines to scroll in the X direction with wheel or trackpad.""" + """Number of columns to scroll in the X direction with wheel or trackpad.""" self.scroll_sensitivity_y: float = 2.0 """Number of lines to scroll in the Y direction with wheel or trackpad.""" From 5116fcaa029ee41bf2c7b09129443a26c6f70be2 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 13:19:25 +0100 Subject: [PATCH 08/11] merge and annotations --- src/textual/render.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/textual/render.py b/src/textual/render.py index 6d5dbc326f..8911c42638 100644 --- a/src/textual/render.py +++ b/src/textual/render.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from rich.console import Console, RenderableType from rich.protocol import rich_cast @@ -7,7 +9,7 @@ def measure( renderable: RenderableType, default: int, *, - container_width: int | None = None + container_width: int | None = None, ) -> int: """Measure a rich renderable. From b8d15c6d614f0434b716a512a66e96ebf6de02d7 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 16:00:57 +0100 Subject: [PATCH 09/11] comment --- src/textual/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/textual/app.py b/src/textual/app.py index ad66cf5f26..46ac679038 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -370,6 +370,8 @@ def __init__( self.css_path = css_paths self._registry: WeakSet[DOMNode] = WeakSet() + # Sensitivity on X is double the sensitivity on Y to account for + # cells being twice as tall as wide self.scroll_sensitivity_x: float = 4.0 """Number of columns to scroll in the X direction with wheel or trackpad.""" self.scroll_sensitivity_y: float = 2.0 From 44b1888e61f836071708f7c95346a54b59cd14c8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 16:07:15 +0100 Subject: [PATCH 10/11] fixed URL --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 570b5be1c5..8a542d34fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added the coroutines `Animator.wait_until_complete` and `pilot.wait_for_scheduled_animations` that allow waiting for all current and scheduled animations https://github.com/Textualize/textual/issues/1658 - Added the method `Animator.is_being_animated` that checks if an attribute of an object is being animated or is scheduled for animation -- Added App.scroll_sensitivity_x and App.scroll_sensitivity_y to adjust how many lines the scroll wheel moves the scroll position https://github.com/orgs/Textualize/projects/5?pane=issue&itemId=12998591 +- Added App.scroll_sensitivity_x and App.scroll_sensitivity_y to adjust how many lines the scroll wheel moves the scroll position https://github.com/Textualize/textual/issues/928 - Added Shift+scroll wheel and ctrl+scroll wheen to scroll horizontally ### Changed From 081110ff962e70a4bbda858c90518b4b98d2fd60 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 30 Jan 2023 16:13:53 +0100 Subject: [PATCH 11/11] fix typo [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a542d34fe..2bda200751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added the coroutines `Animator.wait_until_complete` and `pilot.wait_for_scheduled_animations` that allow waiting for all current and scheduled animations https://github.com/Textualize/textual/issues/1658 - Added the method `Animator.is_being_animated` that checks if an attribute of an object is being animated or is scheduled for animation - Added App.scroll_sensitivity_x and App.scroll_sensitivity_y to adjust how many lines the scroll wheel moves the scroll position https://github.com/Textualize/textual/issues/928 -- Added Shift+scroll wheel and ctrl+scroll wheen to scroll horizontally +- Added Shift+scroll wheel and ctrl+scroll wheel to scroll horizontally ### Changed