fix tests

This commit is contained in:
Will McGugan
2022-09-26 09:51:33 +01:00
parent 53d8e02d0d
commit 3f0955cbe5
19 changed files with 314 additions and 39 deletions

View File

@@ -0,0 +1,7 @@
Bar {
height: 5;
content-align: center middle;
text-style: bold;
margin: 1 2;
color: $text;
}

View File

@@ -0,0 +1,31 @@
from textual.app import App, ComposeResult
from textual.color import Color
from textual.widgets import Footer, Static
class Bar(Static):
pass
class BindingApp(App):
CSS_PATH = "binding01.css"
BINDINGS = [
("r", "add_bar('red')", "Add Red"),
("g", "add_bar('green')", "Add Green"),
("b", "add_bar('blue')", "Add Blue"),
]
def compose(self) -> ComposeResult:
yield Footer()
def action_add_bar(self, color: str) -> None:
bar = Bar(color)
bar.styles.background = Color.parse(color).with_alpha(0.5)
self.mount(bar)
self.call_later(self.screen.scroll_end, animate=False)
if __name__ == "__main__":
app = BindingApp()
app.run()

View File

@@ -1,12 +0,0 @@
Screen {
layout: horizontal;
}
KeyLogger {
width: 1fr;
border: blank;
}
KeyLogger:focus {
border: wide $accent;
}

View File

@@ -3,19 +3,17 @@ from textual.widgets import TextLog
from textual import events
class KeyLogger(TextLog):
def on_key(self, event: events.Key) -> None:
self.write(event)
class InputApp(App):
"""App to display key events."""
CSS_PATH = "input02.css"
def compose(self) -> ComposeResult:
yield KeyLogger()
yield KeyLogger()
yield TextLog()
def on_key(self, event: events.Key) -> None:
self.query_one(TextLog).write(event)
def key_space(self) -> None:
self.bell()
if __name__ == "__main__":

View File

@@ -0,0 +1,17 @@
Screen {
layout: grid;
grid-size: 2 2;
grid-columns: 1fr;
}
KeyLogger {
border: blank;
}
KeyLogger:hover {
border: wide $secondary;
}
KeyLogger:focus {
border: wide $accent;
}

View File

@@ -0,0 +1,25 @@
from textual.app import App, ComposeResult
from textual.widgets import TextLog
from textual import events
class KeyLogger(TextLog):
def on_key(self, event: events.Key) -> None:
self.write(event)
class InputApp(App):
"""App to display key events."""
CSS_PATH = "key03.css"
def compose(self) -> ComposeResult:
yield KeyLogger()
yield KeyLogger()
yield KeyLogger()
yield KeyLogger()
if __name__ == "__main__":
app = InputApp()
app.run()