File: data_table_column_cursor.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 (35 lines) | stat: -rw-r--r-- 951 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
import csv
import io

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

CSV = """lane,swimmer,country,time
4,Joseph Schooling,Singapore,50.39
2,Michael Phelps,United States,51.14
5,Chad le Clos,South Africa,51.14
6,László Cseh,Hungary,51.14
3,Li Zhuhao,China,51.26
8,Mehdy Metella,France,51.58
7,Tom Shields,United States,51.73
1,Aleksandr Sadovnikov,Russia,51.84"""


class TableApp(App):
    def compose(self) -> ComposeResult:
        rows = csv.reader(io.StringIO(CSV))
        labels = next(rows)
        data = [row for row in rows]
        backend = ArrowBackend.from_pydict(
            {label: [row[i] for row in data] for i, label in enumerate(labels)}
        )
        table = DataTable(
            backend=backend, cursor_type="column", fixed_columns=1, fixed_rows=1
        )
        table.focus()
        yield table


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