mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* Renaming some component classes in DataTable * Some more renaming of DataTable component classes * Separate styling for fixed rows/columns from labels * Highlight fixed rows/cols affected by colour differently * Tweaking styles for fixed data in DataTable * Update DataTable snapshots * Add row label to Row metadata * Wiring up some labelled row logic behind flags * Renaming variable in DataTable * Variable renaming in DataTable * [no ci] Labelling rows progress * Add RenderedRow abstraction to DataTable * Computing label widths * Use the Column object to represent row label column * Ability to toggle row labels reactively * Adjust width calculation for label widths * Add DataTable.RowLabelSelected * Posting the RowLabelClick message * Hovering of row labels applies new style * Remove a print * Ensure horizontal scrolling with column cursor accounts for row label column * Account for possible row labels in cell cursor horizontal scrolling * Ensure cursor highlighting is correct on row label cells * Document component class for DataTable label hover * Test to ensure clicking row label emits correct event * Add snapshot test for DataTable with fixed rows/cols and row labels * Using pilot pause instead of wait_for_idle directly * Update CHANGELOG * Add a docstring * Add a note to CHANGELOG.md about RowLabelSelected
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from textual.app import App, ComposeResult
|
|
from textual.widgets import DataTable
|
|
|
|
ROWS = [
|
|
("lane", "swimmer", "country", "time"),
|
|
(5, "Chad le Clos", "South Africa", 51.14),
|
|
(4, "Joseph Schooling", "Singapore", 50.39),
|
|
(2, "Michael Phelps", "United States", 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),
|
|
(10, "Darren Burns", "Scotland", 51.84),
|
|
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
|
|
]
|
|
|
|
|
|
class TableApp(App):
|
|
def compose(self) -> ComposeResult:
|
|
yield DataTable()
|
|
|
|
def on_mount(self) -> None:
|
|
table = self.query_one(DataTable)
|
|
table.fixed_rows = 1
|
|
table.fixed_columns = 1
|
|
table.focus()
|
|
rows = iter(ROWS)
|
|
column_labels = next(rows)
|
|
for column in column_labels:
|
|
table.add_column(column, key=column)
|
|
for index, row in enumerate(rows):
|
|
table.add_row(*row, label=str(index))
|
|
|
|
|
|
app = TableApp()
|
|
if __name__ == "__main__":
|
|
app.run()
|