mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix tests
This commit is contained in:
7
docs/examples/guide/input/binding01.css
Normal file
7
docs/examples/guide/input/binding01.css
Normal file
@@ -0,0 +1,7 @@
|
||||
Bar {
|
||||
height: 5;
|
||||
content-align: center middle;
|
||||
text-style: bold;
|
||||
margin: 1 2;
|
||||
color: $text;
|
||||
}
|
||||
31
docs/examples/guide/input/binding01.py
Normal file
31
docs/examples/guide/input/binding01.py
Normal 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()
|
||||
@@ -1,12 +0,0 @@
|
||||
Screen {
|
||||
layout: horizontal;
|
||||
}
|
||||
|
||||
KeyLogger {
|
||||
width: 1fr;
|
||||
border: blank;
|
||||
}
|
||||
|
||||
KeyLogger:focus {
|
||||
border: wide $accent;
|
||||
}
|
||||
@@ -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__":
|
||||
|
||||
17
docs/examples/guide/input/key03.css
Normal file
17
docs/examples/guide/input/key03.css
Normal 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;
|
||||
}
|
||||
25
docs/examples/guide/input/key03.py
Normal file
25
docs/examples/guide/input/key03.py
Normal 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()
|
||||
Reference in New Issue
Block a user