mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
tweak to keys command
This commit is contained in:
@@ -239,6 +239,8 @@ class App(Generic[ReturnType], DOMNode):
|
||||
TITLE: str | None = None
|
||||
SUB_TITLE: str | None = None
|
||||
|
||||
BINDINGS = [Binding("ctrl+c", "quit", "Quit", show=False, priority=True)]
|
||||
|
||||
title: Reactive[str] = Reactive("")
|
||||
sub_title: Reactive[str] = Reactive("")
|
||||
dark: Reactive[bool] = Reactive(True)
|
||||
@@ -300,7 +302,6 @@ class App(Generic[ReturnType], DOMNode):
|
||||
|
||||
self._logger = Logger(self._log)
|
||||
|
||||
self._bindings.bind("ctrl+c", "quit", show=False, priority=True)
|
||||
self._refresh_required = False
|
||||
|
||||
self.design = DEFAULT_COLORS
|
||||
|
||||
@@ -2,23 +2,36 @@ from rich.panel import Panel
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual import events
|
||||
from textual.widgets import Header, Footer, TextLog
|
||||
from textual.containers import Horizontal
|
||||
from textual.widgets import Button, Header, TextLog
|
||||
|
||||
|
||||
class KeyLog(TextLog, inherit_bindings=False):
|
||||
"""We don't want to handle scroll keys."""
|
||||
|
||||
|
||||
class KeysApp(App):
|
||||
class KeysApp(App, inherit_bindings=False):
|
||||
"""Show key events in a text log."""
|
||||
|
||||
TITLE = "Textual Keys"
|
||||
|
||||
BINDINGS = [("c", "clear", "Clear")]
|
||||
CSS = """
|
||||
#buttons {
|
||||
dock: bottom;
|
||||
height: 3;
|
||||
}
|
||||
Button {
|
||||
width: 1fr;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield Footer()
|
||||
yield Horizontal(
|
||||
Button("Clear", id="clear", variant="warning"),
|
||||
Button("Quit", id="quit", variant="error"),
|
||||
id="buttons",
|
||||
)
|
||||
yield KeyLog()
|
||||
|
||||
def on_ready(self) -> None:
|
||||
@@ -27,8 +40,11 @@ class KeysApp(App):
|
||||
def on_key(self, event: events.Key) -> None:
|
||||
self.query_one(KeyLog).write(event)
|
||||
|
||||
def action_clear(self) -> None:
|
||||
self.query_one(KeyLog).clear()
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
if event.button.id == "quit":
|
||||
self.exit()
|
||||
elif event.button.id == "clear":
|
||||
self.query_one(KeyLog).clear()
|
||||
|
||||
|
||||
app = KeysApp()
|
||||
|
||||
Reference in New Issue
Block a user