This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add an example of screen callbacks working fine
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Evidence that screen callbacks are still working. | ||
For a reply to https://github.com/Textualize/textual/issues/4656. | ||
""" | ||
|
||
from textual import on | ||
from textual.app import App, ComposeResult | ||
from textual.screen import Screen | ||
from textual.widgets import Button | ||
|
||
|
||
class Test(Screen[str]): | ||
def compose(self) -> ComposeResult: | ||
yield Button("Yes", id="Yes") | ||
yield Button("No", id="No") | ||
|
||
@on(Button.Pressed) | ||
def test_the_callback(self, event: Button.Pressed) -> None: | ||
assert event.button.id is not None | ||
self.dismiss(event.button.id) | ||
|
||
|
||
class ScreenCallbackTest(App[None]): | ||
def compose(self) -> ComposeResult: | ||
yield Button("Test") | ||
|
||
@on(Button.Pressed) | ||
def test_screen_callback(self) -> None: | ||
def show_result(result: str) -> None: | ||
self.notify(result) | ||
|
||
self.push_screen(Test(), callback=show_result) | ||
|
||
|
||
if __name__ == "__main__": | ||
ScreenCallbackTest().run() | ||
|
||
### screen_callback.py ends here |