dispatch kehy

This commit is contained in:
Will McGugan
2022-02-07 12:00:36 +00:00
parent 8ad03e2216
commit c74c069629
6 changed files with 9 additions and 10 deletions

View File

@@ -18,9 +18,5 @@ class BasicApp(App):
sidebar=Widget(),
)
# # self.app.panic(self["#sidebar"].styles.has_rule("border"))
# self.app.panic(repr(self["#sidebar"]._inline_styles.border))
BasicApp.run(css_file="basic.css", watch_css=True, log="textual.log")

View File

@@ -1,7 +1,7 @@
from textual.app import App
from textual import events
from textual.widgets import Placeholder
from textual.widget import Widget
from textual import events
class BasicApp(App):
@@ -16,6 +16,9 @@ class BasicApp(App):
sidebar=Widget(),
)
async def on_key(self, event: events.Key) -> None:
await self.dispatch_key(event)
def key_a(self) -> None:
self.query("#footer").set_styles(text="on magenta")

View File

@@ -434,7 +434,7 @@ class DockProperty:
Returns:
str: The dock name as a string, or "" if the rule is not set.
"""
return obj._rules.get("dock") or ""
return obj._rules.get("dock") or "_default"
def __set__(self, obj: Styles, spacing: str | None):
"""Set the Dock property

View File

@@ -311,7 +311,7 @@ class MessagePump:
else:
return False
async def dispatch_key(self, event: events.Key) -> bool:
async def dispatch_key(self, event: events.Key) -> None:
"""Dispatch a key event to method.
This method will call the method named 'key_<event.key>' if it exists. This key method
@@ -324,8 +324,7 @@ class MessagePump:
key_method = getattr(self, f"key_{event.key}", None)
if key_method is not None:
await invoke(key_method, event)
return True
return False
event.prevent_default()
async def on_timer(self, event: events.Timer) -> None:
event.prevent_default()

View File

@@ -18,6 +18,7 @@ class View(Widget):
DEFAULT_STYLES = """
layout: dock;
docks: _default=top;
"""
def __init__(self, name: str | None = None, id: str | None = None) -> None:

View File

@@ -57,7 +57,7 @@ class Widget(DOMNode):
can_focus: bool = False
DEFAULT_STYLES = """
dock: _default;
"""
def __init__(self, name: str | None = None, id: str | None = None) -> None: