Use autodoc for DataTable Messages reference

This commit is contained in:
Darren Burns
2023-01-17 13:00:01 +00:00
parent 23eb13d12d
commit be45db4573
5 changed files with 38 additions and 33 deletions

1
docs/api/coordinate.md Normal file
View File

@@ -0,0 +1 @@
::: textual.coordinate.Coordinate

View File

@@ -22,32 +22,31 @@ The example below populates a table with CSV data.
## Reactive Attributes ## Reactive Attributes
| Name | Type | Default | Description | | Name | Type | Default | Description |
|-----------------|--------------|--------------------|---------------------------------------------------------| |-----------------|---------------------------------------------|--------------------|---------------------------------------------------------|
| `show_header` | `bool` | `True` | Show the table header | | `show_header` | `bool` | `True` | Show the table header |
| `fixed_rows` | `int` | `0` | Number of fixed rows (rows which do not scroll) | | `fixed_rows` | `int` | `0` | Number of fixed rows (rows which do not scroll) |
| `fixed_columns` | `int` | `0` | Number of fixed columns (columns which do not scroll) | | `fixed_columns` | `int` | `0` | Number of fixed columns (columns which do not scroll) |
| `zebra_stripes` | `bool` | `False` | Display alternating colors on rows | | `zebra_stripes` | `bool` | `False` | Display alternating colors on rows |
| `header_height` | `int` | `1` | Height of header row | | `header_height` | `int` | `1` | Height of header row |
| `show_cursor` | `bool` | `True` | Show the cursor | | `show_cursor` | `bool` | `True` | Show the cursor |
| `cursor_type` | `str` | `"cell"` | One of `"cell"`, `"row"`, `"column"`, or `"none"` | | `cursor_type` | `str` | `"cell"` | One of `"cell"`, `"row"`, `"column"`, or `"none"` |
| `cursor_cell` | `Coordinate` | `Coordinate(0, 0)` | The coordinates of the cell the cursor is currently on | | `cursor_cell` | [Coordinate][textual.coordinate.Coordinate] | `Coordinate(0, 0)` | The coordinates of the cell the cursor is currently on |
| `hover_cell` | `Coordinate` | `Coordinate(0, 0)` | The coordinates of the cell the _mouse_ cursor is above | | `hover_cell` | [Coordinate][textual.coordinate.Coordinate] | `Coordinate(0, 0)` | The coordinates of the cell the _mouse_ cursor is above |
## Messages ## Messages
### CellHighlighted ### ::: textual.widgets.DataTable.CellHighlighted
The `DataTable.CellHighlighted` message is emitted by the `DataTable` widget when the cursor moves ### ::: textual.widgets.DataTable.CellSelected
to highlight a new cell. It's also emitted when the cell cursor is re-enabled (by setting `show_cursor=True`),
and when the cursor type is changed to `"cell"`.
#### Attributes ### ::: textual.widgets.DataTable.RowHighlighted
| Attribute | Type | Description | ### ::: textual.widgets.DataTable.RowSelected
|--------------|----------------------------------------------|----------------------------------|
| `value` | `CellType` | The value contained in the cell. | ### ::: textual.widgets.DataTable.ColumnHighlighted
| `coordinate` | [Coordinate][textual.coordinates.Coordinate] | The coordinate of the cell. |
### ::: textual.widgets.DataTable.ColumnSelected
## See Also ## See Also

View File

@@ -148,6 +148,7 @@ nav:
- "api/checkbox.md" - "api/checkbox.md"
- "api/color.md" - "api/color.md"
- "api/containers.md" - "api/containers.md"
- "api/coordinate.md"
- "api/data_table.md" - "api/data_table.md"
- "api/directory_tree.md" - "api/directory_tree.md"
- "api/dom_node.md" - "api/dom_node.md"
@@ -253,6 +254,8 @@ plugins:
handlers: handlers:
python: python:
options: options:
show_root_heading: true
show_root_full_path: false
show_source: false show_source: false
filters: filters:
- "!^_" - "!^_"

View File

@@ -4,43 +4,43 @@ from typing import NamedTuple
class Coordinate(NamedTuple): class Coordinate(NamedTuple):
"""An object representing a row/column coordinate.""" """An object representing a row/column coordinate within a grid."""
row: int row: int
column: int column: int
def left(self) -> Coordinate: def left(self) -> Coordinate:
"""Get coordinate to the left. """Get the coordinate to the left.
Returns: Returns:
Coordinate: The coordinate. Coordinate: The coordinate to the left.
""" """
row, column = self row, column = self
return Coordinate(row, column - 1) return Coordinate(row, column - 1)
def right(self) -> Coordinate: def right(self) -> Coordinate:
"""Get coordinate to the right. """Get the coordinate to the right.
Returns: Returns:
Coordinate: The coordinate. Coordinate: The coordinate to the right.
""" """
row, column = self row, column = self
return Coordinate(row, column + 1) return Coordinate(row, column + 1)
def up(self) -> Coordinate: def up(self) -> Coordinate:
"""Get coordinate above. """Get the coordinate above.
Returns: Returns:
Coordinate: The coordinate. Coordinate: The coordinate above.
""" """
row, column = self row, column = self
return Coordinate(row - 1, column) return Coordinate(row - 1, column)
def down(self) -> Coordinate: def down(self) -> Coordinate:
"""Get coordinate below. """Get the coordinate below.
Returns: Returns:
Coordinate: The coordinate. Coordinate: The coordinate below.
""" """
row, column = self row, column = self
return Coordinate(row + 1, column) return Coordinate(row + 1, column)

View File

@@ -896,8 +896,10 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
self.emit_no_wait(DataTable.ColumnSelected(self, column)) self.emit_no_wait(DataTable.ColumnSelected(self, column))
class CellHighlighted(Message, bubble=True): class CellHighlighted(Message, bubble=True):
"""Emitted when the cursor moves to a new cell. This message is only emitted when the """Emitted when the cursor moves to highlight a new cell.
cursor_type is set to `"cell"`. It's only relevant when the `cursor_type` is `"cell"`.
It's also emitted when the cell cursor is re-enabled (by setting `show_cursor=True`),
and when the cursor type is changed to `"cell"`.
Attributes: Attributes:
sender (DataTable): The DataTable the cell was highlighted in. sender (DataTable): The DataTable the cell was highlighted in.
@@ -918,8 +920,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
yield "coordinate", self.coordinate yield "coordinate", self.coordinate
class CellSelected(Message, bubble=True): class CellSelected(Message, bubble=True):
"""Emitted when a cell is selected. This message is only emitted when the """Emitted by the `DataTable` widget when a cell is selected.
cursor_type is set to `"cell"`. It's only relevant when the `cursor_type` is `"cell"`.
Attributes: Attributes:
sender (DataTable): The DataTable the cell was selected in. sender (DataTable): The DataTable the cell was selected in.