Skip to content

Commit

Permalink
Allow App.dark to be set before there's a screen
Browse files Browse the repository at this point in the history
This commit addresses Textualize#1369 by swallowing any `ScreenStackError` when
calling `refresh_css` after setting the -{dark,light}-mode class on the app.
The idea here being that if there is no screen, that's fine, the style will
be taken up once there is one.
  • Loading branch information
davep committed Dec 21, 2022
1 parent dd2b89b commit be0c763
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,14 @@ def watch_dark(self, dark: bool) -> None:
"""Watches the dark bool."""
self.set_class(dark, "-dark-mode")
self.set_class(not dark, "-light-mode")
self.refresh_css()
try:
self.refresh_css()
except ScreenStackError:
# It's possible that `dark` can be set before we have a default
# screen, in an app's `on_load`, for example. So let's eat the
# ScreenStackError -- the above styles will be handled once the
# screen is spun up anyway.
pass

def get_driver_class(self) -> Type[Driver]:
"""Get a driver class for this platform.
Expand Down

0 comments on commit be0c763

Please sign in to comment.