mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* Preamble. Mention commonly searched for capabilities missing, e.g., formatting and filtering. * Clarify zebra_stripes as using alternating styles. * Expand Cursors section to mention None type of cursor, clarify keyboard and mouse events, and that row indices start at one. Expand example for No Cursor option. Also minor typos to previous two commits (preamble wording and zebra stripes). * Expand sorting section for clarity. Minor typos in Labeled Rows and Cursors sections. * In Keys section, mention functions taking coordinates. Fix typo in Sorting section. * Minor changes --------- Co-authored-by: Darren Burns <darrenb900@gmail.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from itertools import cycle
|
|
|
|
from textual.app import App, ComposeResult
|
|
from textual.widgets import DataTable
|
|
|
|
ROWS = [
|
|
("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),
|
|
(10, "Darren Burns", "Scotland", 51.84),
|
|
]
|
|
|
|
cursors = cycle(["column", "row", "cell", "none"])
|
|
|
|
|
|
class TableApp(App):
|
|
def compose(self) -> ComposeResult:
|
|
yield DataTable()
|
|
|
|
def on_mount(self) -> None:
|
|
table = self.query_one(DataTable)
|
|
table.cursor_type = next(cursors)
|
|
table.zebra_stripes = True
|
|
table.add_columns(*ROWS[0])
|
|
table.add_rows(ROWS[1:])
|
|
|
|
def key_c(self):
|
|
table = self.query_one(DataTable)
|
|
table.cursor_type = next(cursors)
|
|
|
|
|
|
app = TableApp()
|
|
if __name__ == "__main__":
|
|
app.run()
|