Tweaks to DataTable docs. (#2481)

* Tweaks to DataTable docs.

Related PRs: #2479.

* Fix link.
This commit is contained in:
Rodrigo Girão Serrão
2023-05-04 14:55:14 +01:00
committed by GitHub
parent 04083a73f8
commit c4eda48a0a
3 changed files with 8 additions and 3 deletions

View File

@@ -59,9 +59,9 @@ If you want to change the table based solely on coordinates, you can use the [co
### Cursors ### Cursors
The coordinate of the cursor is exposed via the `cursor_coordinate` reactive attribute. The coordinate of the cursor is exposed via the [`cursor_coordinate`][textual.widgets.DataTable.cursor_coordinate] reactive attribute.
Three types of cursors are supported: `cell`, `row`, and `column`. Three types of cursors are supported: `cell`, `row`, and `column`.
Change the cursor type by assigning to the `cursor_type` reactive attribute. Change the cursor type by assigning to the [`cursor_type`][textual.widgets.DataTable.cursor_type] reactive attribute.
=== "Column Cursor" === "Column Cursor"

View File

@@ -7,11 +7,13 @@ from ._context import NoActiveAppError
from ._types import CallbackType, MessageTarget, WatchCallbackType from ._types import CallbackType, MessageTarget, WatchCallbackType
from .actions import ActionParseResult from .actions import ActionParseResult
from .css.styles import RenderStyles from .css.styles import RenderStyles
from .widgets._data_table import CursorType
__all__ = [ __all__ = [
"ActionParseResult", "ActionParseResult",
"Animatable", "Animatable",
"CallbackType", "CallbackType",
"CursorType",
"EasingFunction", "EasingFunction",
"MessageTarget", "MessageTarget",
"NoActiveAppError", "NoActiveAppError",

View File

@@ -38,6 +38,7 @@ CellCacheKey: TypeAlias = (
LineCacheKey: TypeAlias = "tuple[int, int, int, int, Coordinate, Coordinate, Style, CursorType, bool, int, PseudoClasses]" LineCacheKey: TypeAlias = "tuple[int, int, int, int, Coordinate, Coordinate, Style, CursorType, bool, int, PseudoClasses]"
RowCacheKey: TypeAlias = "tuple[RowKey, int, Style, Coordinate, Coordinate, CursorType, bool, bool, int, PseudoClasses]" RowCacheKey: TypeAlias = "tuple[RowKey, int, Style, Coordinate, Coordinate, CursorType, bool, bool, int, PseudoClasses]"
CursorType = Literal["cell", "row", "column", "none"] CursorType = Literal["cell", "row", "column", "none"]
"""The legal types of cursors for [`DataTable.cursor_type`][textual.widgets.DataTable.cursor_type]."""
CellType = TypeVar("CellType") CellType = TypeVar("CellType")
CELL_X_PADDING = 2 CELL_X_PADDING = 2
@@ -304,7 +305,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
zebra_stripes = Reactive(False) zebra_stripes = Reactive(False)
header_height = Reactive(1) header_height = Reactive(1)
show_cursor = Reactive(True) show_cursor = Reactive(True)
cursor_type = Reactive("cell") cursor_type: Reactive[CursorType] = Reactive[CursorType]("cell")
"""The type of the cursor of the `DataTable`."""
cursor_coordinate: Reactive[Coordinate] = Reactive( cursor_coordinate: Reactive[Coordinate] = Reactive(
Coordinate(0, 0), repaint=False, always_update=True Coordinate(0, 0), repaint=False, always_update=True
@@ -312,6 +314,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
hover_coordinate: Reactive[Coordinate] = Reactive( hover_coordinate: Reactive[Coordinate] = Reactive(
Coordinate(0, 0), repaint=False, always_update=True Coordinate(0, 0), repaint=False, always_update=True
) )
"""The coordinate of the `DataTable` that is being hovered."""
class CellHighlighted(Message, bubble=True): class CellHighlighted(Message, bubble=True):
"""Posted when the cursor moves to highlight a new cell. """Posted when the cursor moves to highlight a new cell.