preflight checks

This commit is contained in:
Will McGugan
2025-02-27 10:40:06 +00:00
parent 3955ece036
commit 5ec2e17e5e
2 changed files with 16 additions and 1 deletions

View File

@@ -1026,7 +1026,7 @@ class App(Generic[ReturnType], DOMNode):
@property @property
def debug(self) -> bool: def debug(self) -> bool:
"""Is debug mode enabled?""" """Is debug mode enabled?"""
return "debug" in self.features return "debug" in self.features or constants.DEBUG
@property @property
def is_headless(self) -> bool: def is_headless(self) -> bool:

View File

@@ -504,6 +504,8 @@ class Widget(DOMNode):
"""Time of last scroll.""" """Time of last scroll."""
self._user_scroll_interrupt: bool = False self._user_scroll_interrupt: bool = False
"""Has the user interrupted a scroll to end?""" """Has the user interrupted a scroll to end?"""
if self.app.debug:
self._preflight()
@property @property
def is_mounted(self) -> bool: def is_mounted(self) -> bool:
@@ -651,6 +653,19 @@ class Widget(DOMNode):
"""Text selection information, or `None` if no text is selected in this widget.""" """Text selection information, or `None` if no text is selected in this widget."""
return self.screen.selections.get(self, None) return self.screen.selections.get(self, None)
def _preflight(self) -> None:
"""Called in debug mode to do preflight checks.
Errors are reported via self.log.
"""
from textual.screen import Screen
if not isinstance(self, Screen) and hasattr(self, "CSS"):
self.log.warning(
f"'{self.__class__.__name__}.CSS' will be ignored (use 'DEFAULT_CSS' class variable for widgets)"
)
def _cover(self, widget: Widget) -> None: def _cover(self, widget: Widget) -> None:
"""Set a widget used to replace the visuals of this widget (used for loading indicator). """Set a widget used to replace the visuals of this widget (used for loading indicator).