From 7dfc3e57a1f042fd78ef1b72188105c973e6c0c9 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 3 May 2023 20:54:54 +0100 Subject: [PATCH 1/4] Fix a crash when DirectoryTree starts out anywhere other than . A hangover from the previous DirectoryTree, where setting the path didn't matter. This now sets it *after* calling Tree's __init__, thus ensuring the line cache and other related things have been created. --- CHANGELOG.md | 4 ++++ src/textual/widgets/_directory_tree.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56b6aff24..798fb051d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed + +- Fixed crash when creating a `DirectoryTree` starting anywhere other than `.` + ### Changed - The DataTable cursor is now scrolled into view when the cursor coordinate is changed programmatically https://github.com/Textualize/textual/issues/2459 diff --git a/src/textual/widgets/_directory_tree.py b/src/textual/widgets/_directory_tree.py index 0090717d7..b2a8ab692 100644 --- a/src/textual/widgets/_directory_tree.py +++ b/src/textual/widgets/_directory_tree.py @@ -103,7 +103,6 @@ class DirectoryTree(Tree[DirEntry]): classes: A space-separated list of classes, or None for no classes. disabled: Whether the directory tree is disabled or not. """ - self.path = path super().__init__( str(path), data=DirEntry(Path(path)), @@ -112,6 +111,7 @@ class DirectoryTree(Tree[DirEntry]): classes=classes, disabled=disabled, ) + self.path = path def reload(self) -> None: """Reload the `DirectoryTree` contents.""" From 38592c34bda68baeeb840bc61f77cdabe2ccf0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Thu, 4 May 2023 10:35:39 +0100 Subject: [PATCH 2/4] Add FAQ about DataTable scrolling. (#2466) Related issues: #2458 --- FAQ.md | 45 ++++++++++++++++++- questions/README.md | 4 +- questions/datatable-doesnt-scroll.question.md | 45 +++++++++++++++++++ questions/images.question.md | 3 +- 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 questions/datatable-doesnt-scroll.question.md diff --git a/FAQ.md b/FAQ.md index ffb91b1d7..72879e9d2 100644 --- a/FAQ.md +++ b/FAQ.md @@ -11,11 +11,12 @@ - [Why do some key combinations never make it to my app?](#why-do-some-key-combinations-never-make-it-to-my-app) - [Why doesn't Textual look good on macOS?](#why-doesn't-textual-look-good-on-macos) - [Why doesn't Textual support ANSI themes?](#why-doesn't-textual-support-ansi-themes) +- [Why doesn't the `DataTable` scroll programmatically?](#why-doesn't-the-`datatable`-scroll-programmatically) ## Does Textual support images? -Textual doesn't have built in support for images yet, but it is on the [Roadmap](https://textual.textualize.io/roadmap/). +Textual doesn't have built-in support for images yet, but it is on the [Roadmap](https://textual.textualize.io/roadmap/). See also the [rich-pixels](https://github.com/darrenburns/rich-pixels) project for a Rich renderable for images that works with Textual. @@ -231,6 +232,48 @@ Textual has a design system which guarantees apps will be readable on all platfo There is currently a light and dark version of the design system, but more are planned. It will also be possible for users to customize the source colors on a per-app or per-system basis. This means that in the future you will be able to modify the core colors to blend in with your chosen terminal theme. + +## Why doesn't the `DataTable` scroll programmatically? + +If it looks like the scrolling in your `DataTable` is broken, it may be because your `DataTable` does not have its height set, which means it is using the default value of `height: auto`. +In turn, this means that the `DataTable` itself does not have a scrollbar and, hence, it cannot scroll. + +If it looks like your `DataTable` has scrollbars, those might belong to the container(s) of the `DataTable`, which in turn makes it look like the scrolling of the `DataTable` is broken. + +To see the difference, try running the app below with and without the comment in the attribute `TableApp.CSS`. +Press E to scroll the `DataTable` to the end. +If the `CSS` is commented out, the `DataTable` does not have a scrollbar and, therefore, there is nothing to scroll. + +
+Example app. + +```py +from textual.app import App, ComposeResult +from textual.widgets import DataTable + + +class TableApp(App): + # CSS = "DataTable { height: 100% }" + + def compose(self) -> ComposeResult: + yield DataTable() + + def on_mount(self) -> None: + table = self.query_one(DataTable) + table.add_column("n") + table.add_rows([(n,) for n in range(300)]) + + def key_e(self) -> None: + self.query_one(DataTable).action_scroll_end() + + +app = TableApp() +if __name__ == "__main__": + app.run() +``` + +
+
Generated by [FAQtory](https://github.com/willmcgugan/faqtory) diff --git a/questions/README.md b/questions/README.md index bb201b128..f4b1f622d 100644 --- a/questions/README.md +++ b/questions/README.md @@ -5,13 +5,13 @@ Your questions should go in this directory. Question files should be named with the extension ".question.md". -To build the faq, install [faqtory](https://github.com/willmcgugan/faqtory) if you haven't already: +To build the FAQ, install [faqtory](https://github.com/willmcgugan/faqtory) if you haven't already: ``` pip install faqtory ``` -The run the following from the top of the repository: +Then run the following from the top of the repository: ``` faqtory build diff --git a/questions/datatable-doesnt-scroll.question.md b/questions/datatable-doesnt-scroll.question.md new file mode 100644 index 000000000..868d04c20 --- /dev/null +++ b/questions/datatable-doesnt-scroll.question.md @@ -0,0 +1,45 @@ +--- +title: "Why doesn't the `DataTable` scroll programmatically?" +alt_titles: + - "Scroll bindings from `DataTable` not working." + - "Datatable cursor goes off screen and doesn't scroll." +--- + +If it looks like the scrolling in your `DataTable` is broken, it may be because your `DataTable` does not have its height set, which means it is using the default value of `height: auto`. +In turn, this means that the `DataTable` itself does not have a scrollbar and, hence, it cannot scroll. + +If it looks like your `DataTable` has scrollbars, those might belong to the container(s) of the `DataTable`, which in turn makes it look like the scrolling of the `DataTable` is broken. + +To see the difference, try running the app below with and without the comment in the attribute `TableApp.CSS`. +Press E to scroll the `DataTable` to the end. +If the `CSS` is commented out, the `DataTable` does not have a scrollbar and, therefore, there is nothing to scroll. + +
+Example app. + +```py +from textual.app import App, ComposeResult +from textual.widgets import DataTable + + +class TableApp(App): + # CSS = "DataTable { height: 100% }" + + def compose(self) -> ComposeResult: + yield DataTable() + + def on_mount(self) -> None: + table = self.query_one(DataTable) + table.add_column("n") + table.add_rows([(n,) for n in range(300)]) + + def key_e(self) -> None: + self.query_one(DataTable).action_scroll_end() + + +app = TableApp() +if __name__ == "__main__": + app.run() +``` + +
diff --git a/questions/images.question.md b/questions/images.question.md index 6d86ea2f5..c6a1e3dc8 100644 --- a/questions/images.question.md +++ b/questions/images.question.md @@ -3,9 +3,8 @@ title: "Does Textual support images?" alt_titles: - "Can Textual display PNG / SVG files?" - "Render images" - --- -Textual doesn't have built in support for images yet, but it is on the [Roadmap](https://textual.textualize.io/roadmap/). +Textual doesn't have built-in support for images yet, but it is on the [Roadmap](https://textual.textualize.io/roadmap/). See also the [rich-pixels](https://github.com/darrenburns/rich-pixels) project for a Rich renderable for images that works with Textual. From cbd68b20dfd8da4c50ad54573609070e0957d9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Thu, 4 May 2023 11:42:19 +0100 Subject: [PATCH 3/4] Datatable scrolling faq (#2477) * Add FAQ about DataTable scrolling. Related issues: #2458 * Write concisely. * Update questions/datatable-doesnt-scroll.question.md Co-authored-by: Will McGugan * Remove example. * Add recommendation. --------- Co-authored-by: Will McGugan --- FAQ.md | 62 +++++-------------- questions/datatable-doesnt-scroll.question.md | 41 +----------- 2 files changed, 17 insertions(+), 86 deletions(-) diff --git a/FAQ.md b/FAQ.md index 72879e9d2..c2b268c85 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2,16 +2,17 @@ # Frequently Asked Questions -- [Does Textual support images?](#does-textual-support-images) -- [How can I fix ImportError cannot import name ComposeResult from textual.app ?](#how-can-i-fix-importerror-cannot-import-name-composeresult-from-textualapp-) -- [How can I select and copy text in a Textual app?](#how-can-i-select-and-copy-text-in-a-textual-app) -- [How can I set a translucent app background?](#how-can-i-set-a-translucent-app-background) -- [How do I center a widget in a screen?](#how-do-i-center-a-widget-in-a-screen) -- [How do I pass arguments to an app?](#how-do-i-pass-arguments-to-an-app) -- [Why do some key combinations never make it to my app?](#why-do-some-key-combinations-never-make-it-to-my-app) -- [Why doesn't Textual look good on macOS?](#why-doesn't-textual-look-good-on-macos) -- [Why doesn't Textual support ANSI themes?](#why-doesn't-textual-support-ansi-themes) -- [Why doesn't the `DataTable` scroll programmatically?](#why-doesn't-the-`datatable`-scroll-programmatically) +- [Frequently Asked Questions](#frequently-asked-questions) + - [Does Textual support images?](#does-textual-support-images) + - [How can I fix ImportError cannot import name ComposeResult from textual.app ?](#how-can-i-fix-importerror-cannot-import-name-composeresult-from-textualapp-) + - [How can I select and copy text in a Textual app?](#how-can-i-select-and-copy-text-in-a-textual-app) + - [How can I set a translucent app background?](#how-can-i-set-a-translucent-app-background) + - [How do I center a widget in a screen?](#how-do-i-center-a-widget-in-a-screen) + - [How do I pass arguments to an app?](#how-do-i-pass-arguments-to-an-app) + - [Why do some key combinations never make it to my app?](#why-do-some-key-combinations-never-make-it-to-my-app) + - [Why doesn't Textual look good on macOS?](#why-doesnt-textual-look-good-on-macos) + - [Why doesn't Textual support ANSI themes?](#why-doesnt-textual-support-ansi-themes) + - [Why doesn't the `DataTable` scroll programmatically?](#why-doesnt-the-datatable-scroll-programmatically) ## Does Textual support images? @@ -235,44 +236,9 @@ There is currently a light and dark version of the design system, but more are p ## Why doesn't the `DataTable` scroll programmatically? -If it looks like the scrolling in your `DataTable` is broken, it may be because your `DataTable` does not have its height set, which means it is using the default value of `height: auto`. -In turn, this means that the `DataTable` itself does not have a scrollbar and, hence, it cannot scroll. - -If it looks like your `DataTable` has scrollbars, those might belong to the container(s) of the `DataTable`, which in turn makes it look like the scrolling of the `DataTable` is broken. - -To see the difference, try running the app below with and without the comment in the attribute `TableApp.CSS`. -Press E to scroll the `DataTable` to the end. -If the `CSS` is commented out, the `DataTable` does not have a scrollbar and, therefore, there is nothing to scroll. - -
-Example app. - -```py -from textual.app import App, ComposeResult -from textual.widgets import DataTable - - -class TableApp(App): - # CSS = "DataTable { height: 100% }" - - def compose(self) -> ComposeResult: - yield DataTable() - - def on_mount(self) -> None: - table = self.query_one(DataTable) - table.add_column("n") - table.add_rows([(n,) for n in range(300)]) - - def key_e(self) -> None: - self.query_one(DataTable).action_scroll_end() - - -app = TableApp() -if __name__ == "__main__": - app.run() -``` - -
+If scrolling in your `DataTable` is _apparently_ broken, it may be because your `DataTable` is using the default value of `height: auto`. +This means that the table will be sized to fit its rows without scrolling, which may cause the *container* (typically the screen) to scroll. +If you would like the table itself to scroll, set the height to something other than `auto`, like `100%`.
diff --git a/questions/datatable-doesnt-scroll.question.md b/questions/datatable-doesnt-scroll.question.md index 868d04c20..7cd2ca296 100644 --- a/questions/datatable-doesnt-scroll.question.md +++ b/questions/datatable-doesnt-scroll.question.md @@ -5,41 +5,6 @@ alt_titles: - "Datatable cursor goes off screen and doesn't scroll." --- -If it looks like the scrolling in your `DataTable` is broken, it may be because your `DataTable` does not have its height set, which means it is using the default value of `height: auto`. -In turn, this means that the `DataTable` itself does not have a scrollbar and, hence, it cannot scroll. - -If it looks like your `DataTable` has scrollbars, those might belong to the container(s) of the `DataTable`, which in turn makes it look like the scrolling of the `DataTable` is broken. - -To see the difference, try running the app below with and without the comment in the attribute `TableApp.CSS`. -Press E to scroll the `DataTable` to the end. -If the `CSS` is commented out, the `DataTable` does not have a scrollbar and, therefore, there is nothing to scroll. - -
-Example app. - -```py -from textual.app import App, ComposeResult -from textual.widgets import DataTable - - -class TableApp(App): - # CSS = "DataTable { height: 100% }" - - def compose(self) -> ComposeResult: - yield DataTable() - - def on_mount(self) -> None: - table = self.query_one(DataTable) - table.add_column("n") - table.add_rows([(n,) for n in range(300)]) - - def key_e(self) -> None: - self.query_one(DataTable).action_scroll_end() - - -app = TableApp() -if __name__ == "__main__": - app.run() -``` - -
+If scrolling in your `DataTable` is _apparently_ broken, it may be because your `DataTable` is using the default value of `height: auto`. +This means that the table will be sized to fit its rows without scrolling, which may cause the *container* (typically the screen) to scroll. +If you would like the table itself to scroll, set the height to something other than `auto`, like `100%`. From 04083a73f8b0abcc98c3fe9fd220f0c7ae4542b4 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 4 May 2023 11:46:20 +0100 Subject: [PATCH 4/4] exclusive false (#2470) * exclusive false * changelog --- CHANGELOG.md | 1 + src/textual/dom.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 798fb051d..fbc8be178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - The DataTable cursor is now scrolled into view when the cursor coordinate is changed programmatically https://github.com/Textualize/textual/issues/2459 +- run_worker exclusive parameter is now `False` by default https://github.com/Textualize/textual/pull/2470 ## [0.23.0] - 2023-05-03 diff --git a/src/textual/dom.py b/src/textual/dom.py index 3f549b059..1c8512f11 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -240,7 +240,7 @@ class DOMNode(MessagePump): description: str = "", exit_on_error: bool = True, start: bool = True, - exclusive: bool = True, + exclusive: bool = False, ) -> Worker[ResultType]: """Run work in a worker.