mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
header fixes, and lazy queries
This commit is contained in:
@@ -14,9 +14,9 @@ class AddRemoveApp(App):
|
||||
CSS = """
|
||||
#buttons {
|
||||
dock: top;
|
||||
height: auto;
|
||||
height: auto;
|
||||
}
|
||||
Button {
|
||||
#buttons Button {
|
||||
width: 1fr;
|
||||
}
|
||||
#items {
|
||||
@@ -26,8 +26,8 @@ class AddRemoveApp(App):
|
||||
Thing {
|
||||
height: 5;
|
||||
background: $panel;
|
||||
border: wide $primary;
|
||||
margin: 0 1;
|
||||
border: tall $primary;
|
||||
margin: 1 1;
|
||||
content-align: center middle;
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ App > Screen {
|
||||
|
||||
background: $surface;
|
||||
color: $text-surface;
|
||||
layers: sidebar;
|
||||
layers: base sidebar;
|
||||
|
||||
color: $text-background;
|
||||
background: $background;
|
||||
@@ -89,14 +89,7 @@ DataTable {
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
#header {
|
||||
color: $text-secondary-background;
|
||||
background: $secondary-background;
|
||||
height: 1;
|
||||
content-align: center middle;
|
||||
|
||||
dock: top;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tweet {
|
||||
@@ -121,7 +114,7 @@ Tweet {
|
||||
overflow-x: auto;
|
||||
overflow-y: scroll;
|
||||
margin: 1 2;
|
||||
height: 20;
|
||||
height: 24;
|
||||
align-horizontal: center;
|
||||
layout: vertical;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ from rich.text import Text
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.reactive import Reactive
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Static, DataTable, DirectoryTree, Footer
|
||||
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
|
||||
from textual.layout import Vertical
|
||||
|
||||
CODE = '''
|
||||
@@ -112,17 +112,14 @@ class BasicApp(App, css_path="basic.css"):
|
||||
self.bind("s", "toggle_class('#sidebar', '-active')", description="Sidebar")
|
||||
self.bind("d", "toggle_dark", description="Dark mode")
|
||||
self.bind("q", "quit", description="Quit")
|
||||
self.bind("f", "query_test", description="Query test")
|
||||
|
||||
def compose(self):
|
||||
yield Header()
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
table = DataTable()
|
||||
self.scroll_to_target = Tweet(TweetBody())
|
||||
|
||||
yield Static(
|
||||
Text.from_markup(
|
||||
"[b]This is a [u]Textual[/u] app, running in the terminal"
|
||||
),
|
||||
id="header",
|
||||
)
|
||||
yield from (
|
||||
Tweet(TweetBody()),
|
||||
Widget(
|
||||
@@ -166,12 +163,30 @@ class BasicApp(App, css_path="basic.css"):
|
||||
for n in range(100):
|
||||
table.add_row(*[f"Cell ([b]{n}[/b], {col})" for col in range(6)])
|
||||
|
||||
def on_mount(self):
|
||||
self.sub_title = "Widget demo"
|
||||
|
||||
async def on_key(self, event) -> None:
|
||||
await self.dispatch_key(event)
|
||||
|
||||
def action_toggle_dark(self):
|
||||
self.dark = not self.dark
|
||||
|
||||
def action_query_test(self):
|
||||
query = self.query("Tweet")
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
|
||||
query = query.exclude(".scroll-horizontal")
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
|
||||
query = query.filter(".rubbish")
|
||||
self.log(query)
|
||||
self.log(query.first())
|
||||
|
||||
async def key_q(self):
|
||||
await self.shutdown()
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
from textual.app import App
|
||||
from textual.widgets import Footer
|
||||
from textual.widgets import Header, Footer
|
||||
|
||||
|
||||
class FooterApp(App):
|
||||
def on_mount(self):
|
||||
self.dark = True
|
||||
self.sub_title = "Header and footer example"
|
||||
self.bind("b", "app.bell", description="Play the Bell")
|
||||
self.bind("d", "dark", description="Toggle dark")
|
||||
self.bind("f1", "app.bell", description="Hello World")
|
||||
self.bind("f2", "app.bell", description="Do something")
|
||||
|
||||
def action_dark(self):
|
||||
self.dark = not self.dark
|
||||
|
||||
def compose(self):
|
||||
yield Header()
|
||||
yield Footer()
|
||||
|
||||
Reference in New Issue
Block a user