mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added quit_after
This commit is contained in:
@@ -177,7 +177,7 @@ class BasicApp(App, css_path="basic.css"):
|
|||||||
app = BasicApp()
|
app = BasicApp()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run(quit_after=1)
|
||||||
|
|
||||||
# from textual.geometry import Region
|
# from textual.geometry import Region
|
||||||
# from textual.color import Color
|
# from textual.color import Color
|
||||||
|
|||||||
@@ -539,10 +539,20 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
keys, action, description, show=show, key_display=key_display
|
keys, action, description, show=show, key_display=key_display
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self) -> ReturnType | None:
|
def run(self, quit_after: float | None = None) -> ReturnType | None:
|
||||||
"""The entry point to run a Textual app."""
|
"""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:
|
async def run_app() -> None:
|
||||||
|
if quit_after is not None:
|
||||||
|
self.set_timer(quit_after, self.shutdown)
|
||||||
await self.process_messages()
|
await self.process_messages()
|
||||||
|
|
||||||
if _ASYNCIO_GET_EVENT_LOOP_IS_DEPRECATED:
|
if _ASYNCIO_GET_EVENT_LOOP_IS_DEPRECATED:
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Screen(Widget):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_current(self) -> bool:
|
def is_current(self) -> bool:
|
||||||
|
"""Check if this screen is current (i.e. visible to user)."""
|
||||||
return self.app.screen is self
|
return self.app.screen is self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user