added quit_after

This commit is contained in:
Will McGugan
2022-08-17 09:47:54 +01:00
parent abe87f755c
commit cb7d806040
3 changed files with 14 additions and 3 deletions

View File

@@ -177,7 +177,7 @@ class BasicApp(App, css_path="basic.css"):
app = BasicApp()
if __name__ == "__main__":
app.run()
app.run(quit_after=1)
# from textual.geometry import Region
# from textual.color import Color

View File

@@ -539,10 +539,20 @@ class App(Generic[ReturnType], DOMNode):
keys, action, description, show=show, key_display=key_display
)
def run(self) -> ReturnType | None:
"""The entry point to run a Textual app."""
def run(self, quit_after: float | None = None) -> ReturnType | None:
"""The main entry point for apps.
Args:
quit_after (float | None, optional): Quit after a given number of seconds, or None
to run forever. Defaults to None.
Returns:
ReturnType | None: _description_
"""
async def run_app() -> None:
if quit_after is not None:
self.set_timer(quit_after, self.shutdown)
await self.process_messages()
if _ASYNCIO_GET_EVENT_LOOP_IS_DEPRECATED:

View File

@@ -53,6 +53,7 @@ class Screen(Widget):
@property
def is_current(self) -> bool:
"""Check if this screen is current (i.e. visible to user)."""
return self.app.screen is self
@property