From 88a8bd5d889f16a102b75a89b06f43d577d92389 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 11:43:03 +0100 Subject: [PATCH 1/6] prevent error in constructor --- src/textual/widgets/_text_area.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index 283623d4c1..970e5f5feb 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -464,9 +464,6 @@ def __init__( self.tab_behavior = tab_behavior - # When `app.dark` is toggled, reset the theme (since it caches values). - self.watch(self.app, "dark", self._app_dark_toggled, init=False) - if tooltip is not None: self.tooltip = tooltip @@ -610,6 +607,10 @@ def _watch_selection( ) -> None: """When the cursor moves, scroll it into view.""" # Find the visual offset of the cursor in the document + + if not self.is_mounted: + return + cursor_location = selection.end self.scroll_cursor_visible() @@ -1519,6 +1520,9 @@ def gutter_width(self) -> int: return gutter_width def _on_mount(self, event: events.Mount) -> None: + # When `app.dark` is toggled, reset the theme (since it caches values). + self.watch(self.app, "dark", self._app_dark_toggled, init=False) + self.blink_timer = self.set_interval( 0.5, self._toggle_cursor_blink_visible, From 69e259fb16e55ce6e24586efc51c01905044dba1 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 11:50:36 +0100 Subject: [PATCH 2/6] add tests --- CHANGELOG.md | 1 + tests/test_widget.py | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 556c442ea8..470dc660b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed crash when exiting the app prematurely https://github.com/Textualize/textual/pull/5039 +- Fixed exception constructing TextArea outside of App ## [0.80.0] - 2024-09-23 diff --git a/tests/test_widget.py b/tests/test_widget.py index 6643916bbb..1bc1f90a89 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -12,7 +12,46 @@ from textual.geometry import Offset, Size from textual.message import Message from textual.widget import BadWidgetName, MountError, PseudoClasses, Widget -from textual.widgets import Label, LoadingIndicator +from textual.widgets import ( + Button, + DataTable, + Footer, + Header, + Input, + Label, + LoadingIndicator, + Log, + OptionList, + RichLog, + Switch, + TextArea, +) + + +async def test_widget_construct(): + """Regression test for https://github.com/Textualize/textual/issues/5042""" + + # Check that constructing the widget outside of the app, doesn't invoke code that + # expects an active app. + class MyApp(App): + def __init__(self) -> None: + super().__init__() + self.button = Button() + self.data_table = DataTable() + self.footer = Footer() + self.header = Header() + self.input = Input() + self.label = Label() + self.loading_indicator = LoadingIndicator() + self.log = Log() + self.option_list = OptionList() + self.rich_log = RichLog() + self.switch = Switch() + self.text_area = TextArea(language="python") + + app = MyApp() + async with app.run_test(): + pass @pytest.mark.parametrize( From a91814b26a898718406adb101e0fae1e4d1fb368 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 11:52:22 +0100 Subject: [PATCH 3/6] bump --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 470dc660b5..9ad9d2d0da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -### Fixed +### [0.80.1] - 2024-09-24 - Fixed crash when exiting the app prematurely https://github.com/Textualize/textual/pull/5039 -- Fixed exception constructing TextArea outside of App +- Fixed exception constructing TextArea outside of App https://github.com/Textualize/textual/pull/5045 ## [0.80.0] - 2024-09-23 @@ -2388,6 +2388,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040 - New handler system for messages that doesn't require inheritance - Improved traceback handling +[0.80.1]: https://github.com/Textualize/textual/compare/v0.80.0...v0.80.1 [0.80.0]: https://github.com/Textualize/textual/compare/v0.79.0...v0.80.0 [0.79.0]: https://github.com/Textualize/textual/compare/v0.78.0...v0.79.0 [0.78.0]: https://github.com/Textualize/textual/compare/v0.77.0...v0.78.0 From 6939ce3b99db50a0810de3c0471d63015cf1fce3 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 11:52:35 +0100 Subject: [PATCH 4/6] version bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index feced1d81d..b96e9c75e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual" -version = "0.80.0" +version = "0.80.1" homepage = "https://github.com/Textualize/textual" repository = "https://github.com/Textualize/textual" documentation = "https://textual.textualize.io/" From bdfa44c8d88c8278ce5fe10442723c4df60ea013 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 11:55:34 +0100 Subject: [PATCH 5/6] fix changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ad9d2d0da..a4b991648b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ 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 +## [0.80.1] - 2024-09-24 -### [0.80.1] - 2024-09-24 +### Fixed - Fixed crash when exiting the app prematurely https://github.com/Textualize/textual/pull/5039 - Fixed exception constructing TextArea outside of App https://github.com/Textualize/textual/pull/5045 From 9dce34c2d7b3ad90a4caaba970416c936d837951 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Sep 2024 12:05:36 +0100 Subject: [PATCH 6/6] fix test --- tests/test_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_widget.py b/tests/test_widget.py index 1bc1f90a89..146e4fbe96 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -43,7 +43,7 @@ def __init__(self) -> None: self.input = Input() self.label = Label() self.loading_indicator = LoadingIndicator() - self.log = Log() + self.log_ = Log() self.option_list = OptionList() self.rich_log = RichLog() self.switch = Switch()