File size: 1,116 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import annotations

from rich.console import RenderableType
from rich.panel import Panel

from textual import events
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical
from textual.widget import Widget


class Box(Widget, can_focus=True):
    DEFAULT_CSS = "#box {background: blue;}"

    def render(self) -> RenderableType:
        return Panel("Box")


class JustABox(App):
    def compose(self) -> ComposeResult:
        # yield Container(Box(classes="box"))
        yield Horizontal(
            Vertical(
                Box(id="box1", classes="box"),
                Box(id="box2", classes="box"),
                id="left_pane",
            ),
            id="horizontal",
        )

    def key_p(self):
        for k, v in self.app.stylesheet.source.items():
            print(k)
        print(self.query_one("#horizontal").styles.layout)

    async def on_key(self, event: events.Key) -> None:
        await self.dispatch_key(event)


app = JustABox(css_path="just_a_box.css", watch_css=True)

if __name__ == "__main__":
    app.run()