From c4eda48a0a0dedf0ac54eeaaa2ce651ec01ed486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Thu, 4 May 2023 14:55:14 +0100 Subject: [PATCH] Tweaks to DataTable docs. (#2481) * Tweaks to DataTable docs. Related PRs: #2479. * Fix link. --- docs/widgets/data_table.md | 4 ++-- src/textual/types.py | 2 ++ src/textual/widgets/_data_table.py | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/widgets/data_table.md b/docs/widgets/data_table.md index 215d0541b..6d2100a26 100644 --- a/docs/widgets/data_table.md +++ b/docs/widgets/data_table.md @@ -59,9 +59,9 @@ If you want to change the table based solely on coordinates, you can use the [co ### 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`. -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" diff --git a/src/textual/types.py b/src/textual/types.py index dd681f657..1b5d3ea25 100644 --- a/src/textual/types.py +++ b/src/textual/types.py @@ -7,11 +7,13 @@ from ._context import NoActiveAppError from ._types import CallbackType, MessageTarget, WatchCallbackType from .actions import ActionParseResult from .css.styles import RenderStyles +from .widgets._data_table import CursorType __all__ = [ "ActionParseResult", "Animatable", "CallbackType", + "CursorType", "EasingFunction", "MessageTarget", "NoActiveAppError", diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index 5991c98db..bbe07ebc6 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -38,6 +38,7 @@ CellCacheKey: TypeAlias = ( 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]" CursorType = Literal["cell", "row", "column", "none"] +"""The legal types of cursors for [`DataTable.cursor_type`][textual.widgets.DataTable.cursor_type].""" CellType = TypeVar("CellType") CELL_X_PADDING = 2 @@ -304,7 +305,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): zebra_stripes = Reactive(False) header_height = Reactive(1) 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( 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( Coordinate(0, 0), repaint=False, always_update=True ) + """The coordinate of the `DataTable` that is being hovered.""" class CellHighlighted(Message, bubble=True): """Posted when the cursor moves to highlight a new cell.