File: datatable_hot_reloading.py

package info (click to toggle)
textual-fastdatatable 0.12.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,856 kB
  • sloc: python: 3,461; makefile: 24
file content (58 lines) | stat: -rw-r--r-- 1,328 bytes parent folder | download
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
56
57
58
from pathlib import Path

from textual.app import App, ComposeResult
from textual_fastdatatable import ArrowBackend, DataTable

CSS_PATH = (Path(__file__) / "../datatable_hot_reloading.tcss").resolve()

# Write some CSS to the file before the app loads.
# Then, the test will clear all the CSS to see if the
# hot reloading applies the changes correctly.
CSS_PATH.write_text(
    """\
DataTable > .datatable--cursor {
    background: purple;
}

DataTable > .datatable--fixed {
    background: red;
}

DataTable > .datatable--fixed-cursor {
    background: blue;
}

DataTable > .datatable--header {
    background: yellow;
}

DataTable > .datatable--odd-row {
    background: pink;
}

DataTable > .datatable--even-row {
    background: brown;
}
"""
)


class DataTableHotReloadingApp(App[None]):
    CSS_PATH = CSS_PATH

    def compose(self) -> ComposeResult:
        data = {
            # orig test set A width=10, we fake it with spaces
            "A         ": ["one", "three", "five"],
            "B": ["two", "four", "six"],
        }
        backend = ArrowBackend.from_pydict(data)
        yield DataTable(backend, zebra_stripes=True, cursor_type="row", fixed_columns=1)

    def on_mount(self) -> None:
        self.query_one(DataTable)


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