Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Test code for Textualize/textual#1355
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Dec 13, 2022
1 parent 61ccb89 commit 7644242
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions in_visible.py
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()

0 comments on commit 7644242

Please sign in to comment.