Created
September 6, 2023 15:40
-
-
Save holdenweb/42db46443a8c8906d8a6d26cb91c45e6 to your computer and use it in GitHub Desktop.
Where does the markup come from?
This file contains hidden or 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
from textual.app import App, ComposeResult | |
from lib import SaveCancel | |
class SkelApp(App): | |
"""A Textual app in which to drop test functionality.""" | |
def compose(self) -> ComposeResult: | |
"""Create child widgets for the app.""" | |
yield SaveCancel(self.report) | |
def action_toggle_dark(self) -> None: | |
"""An action to toggle dark mode.""" | |
self.dark = not self.dark | |
def report(self, arg): | |
from rich import print | |
print(f"ARG: {arg}") | |
self.panic(self.tree) | |
app = SkelApp() | |
if __name__ == "__main__": | |
app.run() |
This file contains hidden or 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
from textual.widget import Widget | |
from textual.widgets import Button | |
from textual.containers import Center, Horizontal, Vertical | |
class SaveCancel(Widget): | |
def __init__(self, callback): | |
super().__init__() | |
self.callback = callback | |
def compose(self): | |
with Center(id="save-cancel-button-row"): | |
with Horizontal(id="save-cancel-buttons"): | |
yield Button("Save", variant="primary", id="save") | |
yield Button("Cancel", variant="error", id="cancel") | |
def on_button_pressed(self, event: Button.Pressed) -> None: | |
id = event.button.id | |
self.callback(id == "save") | |
DEFAULT_CSS = """\ | |
SaveCancel { | |
height: auto; | |
} | |
#save-cancel-button-row { | |
min-height: 3; | |
} | |
#save-cancel-buttons { | |
width: auto; | |
height: 3; | |
} | |
SaveCancel Horizontal { | |
height: 3; | |
} | |
SaveCancel Horizontal Button { | |
height: 3; | |
outline: white 75%; | |
} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment