-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* screen docs * Added push_screen_wait * words and test * overload typing * docstring * style tweak * ws * Update docs/guide/screens.md Co-authored-by: Rodrigo Girão Serrão <[email protected]> * Update docs/guide/screens.md Co-authored-by: Rodrigo Girão Serrão <[email protected]> * Update src/textual/app.py Co-authored-by: Rodrigo Girão Serrão <[email protected]> * merge fix * wording * wording [skipci] --------- Co-authored-by: Rodrigo Girão Serrão <[email protected]>
- Loading branch information
1 parent
babbc40
commit e5f2231
Showing
7 changed files
with
476 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from textual import on, work | ||
from textual.app import App, ComposeResult | ||
from textual.screen import Screen | ||
from textual.widgets import Button, Label | ||
|
||
|
||
class QuestionScreen(Screen[bool]): | ||
"""Screen with a parameter.""" | ||
|
||
def __init__(self, question: str) -> None: | ||
self.question = question | ||
super().__init__() | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Label(self.question) | ||
yield Button("Yes", id="yes", variant="success") | ||
yield Button("No", id="no") | ||
|
||
@on(Button.Pressed, "#yes") | ||
def handle_yes(self) -> None: | ||
self.dismiss(True) # (1)! | ||
|
||
@on(Button.Pressed, "#no") | ||
def handle_no(self) -> None: | ||
self.dismiss(False) # (2)! | ||
|
||
|
||
class QuestionsApp(App): | ||
"""Demonstrates wait_for_dismiss""" | ||
|
||
CSS_PATH = "questions01.tcss" | ||
|
||
@work # (3)! | ||
async def on_mount(self) -> None: | ||
if await self.push_screen_wait( # (4)! | ||
QuestionScreen("Do you like Textual?"), | ||
): | ||
self.notify("Good answer!") | ||
else: | ||
self.notify(":-(", severity="error") | ||
|
||
|
||
if __name__ == "__main__": | ||
app = QuestionsApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
QuestionScreen { | ||
layout: grid; | ||
grid-size: 2 2; | ||
align: center bottom; | ||
} | ||
|
||
QuestionScreen > Label { | ||
margin: 1; | ||
text-align: center; | ||
column-span: 2; | ||
width: 1fr; | ||
} | ||
|
||
QuestionScreen Button { | ||
margin: 2; | ||
width: 1fr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
692 changes: 346 additions & 346 deletions
692
tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Large diffs are not rendered by default.
Oops, something went wrong.