File size: 965 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
45
46
47
48
49
50
51
52
53
54
55
from textual.app import App, ComposeResult
from textual.widgets import Footer, Static


class Focusable(Static, can_focus=True):
    DEFAULT_CSS = """
    Focusable {
        background: blue 20%;        
        height: 1fr;
        padding: 1;
    }
    Focusable:hover {
        outline: solid white;
    }
    Focusable:focus {
        background: red 20%;
    }

    """


class Focusable1(Focusable):

    BINDINGS = [
        ("a", "app.bell", "Ding"),
    ]

    def render(self) -> str:
        return repr(self)


class Focusable2(Focusable):
    CSS = ""
    BINDINGS = [
        ("b", "app.bell", "Beep"),
        ("f1", "app.quit", "QUIT"),
    ]

    def render(self) -> str:
        return repr(self)


class BindingApp(App):
    BINDINGS = [("f1", "app.bell", "Bell")]

    def compose(self) -> ComposeResult:
        yield Focusable1()
        yield Focusable2()
        yield Footer()


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