diff --git a/CHANGELOG.md b/CHANGELOG.md index 041c7ff433..67766594bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Added `App.dom_ready_signal`. This signal is published one time when the App first finishes loading. Its purpose is to provide a simple way for widget libraries to do work only when the DOM is ready, since they cannot use the `Ready` event sent to the App class. + ### Fixed - Fixed `VERTICAL_BREAKPOINTS` doesn't work https://github.com/Textualize/textual/pull/5785 diff --git a/src/textual/app.py b/src/textual/app.py index ba87005aba..110f6d2c45 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -791,6 +791,16 @@ def __init__( perform work after the app has resumed. """ + self.dom_ready_signal: Signal[App] = Signal(self, "dom-ready") + """Signal that is published when the app is finished loading and the + DOM is ready. Note that this signal is only sent once when the app first loads. + + This is intended for third-party widget libraries that need to perform + actions requiring a fully loaded DOM (such as querying for widgets) but + cannot override the App class's `on_ready` method. Subscribers must be + DOMNode instances (such as widgets or other DOM components). + """ + self.set_class(self.current_theme.dark, "-dark-mode") self.set_class(not self.current_theme.dark, "-light-mode") diff --git a/src/textual/screen.py b/src/textual/screen.py index 23517afaa1..c6bee789bb 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -1269,6 +1269,7 @@ def _refresh_layout(self, size: Size | None = None, scroll: bool = False) -> Non else: self.app.post_message(events.Ready()) self.app._dom_ready = True + self.call_next(self.app.dom_ready_signal.publish, self.app) async def _on_update(self, message: messages.Update) -> None: message.stop()