From 95f016c3069cd29aba31479c1ad79fbf82821f01 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 19 Jun 2023 11:34:55 +0100 Subject: [PATCH 1/3] tooltips in compound widgets --- CHANGELOG.md | 6 + src/textual/screen.py | 9 +- .../__snapshots__/test_snapshots.ambr | 158 ++++++++++++++++++ .../snapshot_tests/snapshot_apps/tooltips.py | 14 ++ tests/snapshot_tests/test_snapshots.py | 11 ++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/snapshot_apps/tooltips.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4228e04c3c..9bd1421c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Changed + +- Tooltips are now inherited, so will work with compound widgets + ## [0.28.0] - 2023-06-19 ### Added diff --git a/src/textual/screen.py b/src/textual/screen.py index 505ee34338..1ff2a4a4e5 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -768,7 +768,14 @@ def _handle_tooltip_timer(self, widget: Widget) -> None: except NoMatches: pass else: - tooltip_content = widget.tooltip + tooltip_content: RenderableType | None = None + for node in widget.ancestors_with_self: + if not isinstance(node, Widget): + break + if node.tooltip is not None: + tooltip_content = node.tooltip + break + if tooltip_content is None: tooltip.display = False else: diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index da22db70ba..f2a679280e 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -26255,6 +26255,164 @@ ''' # --- +# name: test_tooltips_in_compound_widgets + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TooltipApp + + + + + + + + + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━--%--:--:-- + + Hello, Tooltip! + + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_tree_example ''' diff --git a/tests/snapshot_tests/snapshot_apps/tooltips.py b/tests/snapshot_tests/snapshot_apps/tooltips.py new file mode 100644 index 0000000000..66940c5e2c --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/tooltips.py @@ -0,0 +1,14 @@ +from textual.app import App, ComposeResult +from textual.widgets import ProgressBar + + +class TooltipApp(App[None]): + def compose(self) -> ComposeResult: + progress_bar = ProgressBar() + progress_bar.tooltip = "Hello, Tooltip!" + yield progress_bar + + +if __name__ == "__main__": + app = TooltipApp() + app.run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 2d9229e179..8c47981d3c 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -213,9 +213,11 @@ def test_tabbed_content(snap_compare): def test_option_list_strings(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_strings.py") + def test_option_list_options(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_options.py") + def test_option_list_tables(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py") @@ -562,3 +564,12 @@ def test_blur_on_disabled(snap_compare): SNAPSHOT_APPS_DIR / "blur_on_disabled.py", press=[*"foo", "f3", *"this should not appear"], ) + + +def test_tooltips_in_compound_widgets(snap_compare): + # https://github.com/Textualize/textual/issues/2641 + async def run_before(pilot) -> None: + await pilot.hover("ProgressBar") + await pilot.pause(0.2) + + assert snap_compare(SNAPSHOT_APPS_DIR / "tooltips.py", run_before=run_before) From b5c67568a0dfaf4742ceb1fa2d0a39f3879affa8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 19 Jun 2023 11:48:53 +0100 Subject: [PATCH 2/3] snapshot tweak --- .../__snapshots__/test_snapshots.ambr | 115 +++++++++--------- .../snapshot_tests/snapshot_apps/tooltips.py | 3 +- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index f2a679280e..4c989a77b6 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -26278,134 +26278,133 @@ font-weight: 700; } - .terminal-3037637410-matrix { + .terminal-706577017-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-3037637410-title { + .terminal-706577017-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-3037637410-r1 { fill: #323232 } - .terminal-3037637410-r2 { fill: #b93c5b } - .terminal-3037637410-r3 { fill: #c5c8c6 } - .terminal-3037637410-r4 { fill: #e1e1e1 } - .terminal-3037637410-r5 { fill: #e2e3e3 } + .terminal-706577017-r1 { fill: #fea62b } + .terminal-706577017-r2 { fill: #323232 } + .terminal-706577017-r3 { fill: #c5c8c6 } + .terminal-706577017-r4 { fill: #e1e1e1 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - TooltipApp + TooltipApp - - - - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━--%--:--:-- - - Hello, Tooltip! - - - - - - - - - - - - - - - - - - - - + + + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━10%--:--:-- + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/snapshot_apps/tooltips.py b/tests/snapshot_tests/snapshot_apps/tooltips.py index 66940c5e2c..bc55542d71 100644 --- a/tests/snapshot_tests/snapshot_apps/tooltips.py +++ b/tests/snapshot_tests/snapshot_apps/tooltips.py @@ -4,7 +4,8 @@ class TooltipApp(App[None]): def compose(self) -> ComposeResult: - progress_bar = ProgressBar() + progress_bar = ProgressBar(100) + progress_bar.advance(10) progress_bar.tooltip = "Hello, Tooltip!" yield progress_bar From e40e0887a7c791cb16b885327cc96f24da063de3 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 19 Jun 2023 13:52:06 +0100 Subject: [PATCH 3/3] test fixes --- CHANGELOG.md | 2 +- .../__snapshots__/test_snapshots.ambr | 115 +++++++++--------- tests/snapshot_tests/test_snapshots.py | 3 +- 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd1421c88..fb0d40657c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `origin_visible` parameter to `Widget.scroll_to_region` - Added `origin_visible` parameter to `Widget.scroll_to_center` - Added `TabbedContent.tab_count` https://github.com/Textualize/textual/pull/2751 -- Added `TabbedContnet.add_pane` https://github.com/Textualize/textual/pull/2751 +- Added `TabbedContent.add_pane` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.remove_pane` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.clear_panes` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.Cleared` https://github.com/Textualize/textual/pull/2751 diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 4c989a77b6..0856df5f65 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -26278,133 +26278,134 @@ font-weight: 700; } - .terminal-706577017-matrix { + .terminal-3455460968-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-706577017-title { + .terminal-3455460968-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-706577017-r1 { fill: #fea62b } - .terminal-706577017-r2 { fill: #323232 } - .terminal-706577017-r3 { fill: #c5c8c6 } - .terminal-706577017-r4 { fill: #e1e1e1 } + .terminal-3455460968-r1 { fill: #fea62b } + .terminal-3455460968-r2 { fill: #323232 } + .terminal-3455460968-r3 { fill: #c5c8c6 } + .terminal-3455460968-r4 { fill: #e1e1e1 } + .terminal-3455460968-r5 { fill: #e2e3e3 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - TooltipApp + TooltipApp - - - - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━10%--:--:-- - - - - - - - - - - - - - - - - - - - - - - + + + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━10%--:--:-- + + Hello, Tooltip! + + + + + + + + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 8c47981d3c..c9c4c14ac6 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -570,6 +570,7 @@ def test_tooltips_in_compound_widgets(snap_compare): # https://github.com/Textualize/textual/issues/2641 async def run_before(pilot) -> None: await pilot.hover("ProgressBar") - await pilot.pause(0.2) + await pilot.pause(0.3) + await pilot.pause() assert snap_compare(SNAPSHOT_APPS_DIR / "tooltips.py", run_before=run_before)