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.
✨ Test code for Textualize/textual#1355
- Loading branch information
Showing
1 changed file
with
55 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,55 @@ | ||
"""https://github.com/Textualize/textual/issues/1355""" | ||
|
||
from textual.app import App, ComposeResult | ||
from textual.widgets import Header, Footer, Label, Button | ||
from textual.containers import Vertical | ||
|
||
class ShowHideApp( App[ None ] ): | ||
|
||
CSS = """ | ||
Horizontal { | ||
height: 1fr; | ||
border: solid red; | ||
} | ||
Button { | ||
width: 100%; | ||
height: 1fr; | ||
} | ||
Label { | ||
width: 100%; | ||
height: 9fr; | ||
content-align: center middle; | ||
background: #888800; | ||
visibility: visible; | ||
} | ||
.hidden { | ||
visibility: hidden; | ||
} | ||
""" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header() | ||
yield Vertical( | ||
Vertical( | ||
Button( "Toggle show/hide via code", id="via-code" ), | ||
Label( "I can be toggled via code; press the button", id="via-code-label" ) | ||
), | ||
Vertical( | ||
Button( "Toggle show/hide via classes", id="via-classes" ), | ||
Label( "I can be toggled via classes; press the button", id="via-classes-label" ) | ||
) | ||
) | ||
yield Footer() | ||
|
||
def on_button_pressed( self, event: Button.Pressed ) -> None: | ||
if event.button.id == "via-code": | ||
label = self.query_one( "#via-code-label" ) | ||
label.styles.visibility = "visible" if label.styles.visibility == "hidden" else "hidden" | ||
self.refresh(layout=True) | ||
elif event.button.id == "via-classes": | ||
self.query_one( "#via-classes-label" ).toggle_class( "hidden" ) | ||
|
||
if __name__ == "__main__": | ||
ShowHideApp().run() | ||
|