vimsheet.ui.grid

GridWidget — virtual-scrolling spreadsheet grid with variable row heights.

class vimsheet.ui.grid.GridWidget(workbook, config=None, **kwargs)[source]

Bases: ScrollView

Virtual-scrolling spreadsheet grid.

Each data row occupies a variable number of virtual lines based on the maximum newline count across all cells in that row. A live preview override allows insert/edit mode to show uncommitted multi-line content.

The column-header row is frozen at viewport y=0 regardless of scroll position. Data rows start at viewport y=1.

Parameters:
  • workbook (Workbook)

  • config (Any)

  • kwargs (Any)

BINDINGS = []

Keyboard bindings for scrollable containers.

Key(s) | Description |
:- | :- |
up | Scroll up, if vertical scrolling is available. |
down | Scroll down, if vertical scrolling is available. |
left | Scroll left, if horizontal scrolling is available. |
right | Scroll right, if horizontal scrolling is available. |
home | Scroll to the home position, if scrolling is available. |
end | Scroll to the end position, if scrolling is available. |
pageup | Scroll up one page, if vertical scrolling is available. |
pagedown | Scroll down one page, if vertical scrolling is available. |
ctrl+pageup | Scroll left one page, if horizontal scrolling is available. |
ctrl+pagedown | Scroll right one page, if horizontal scrolling is available. |
DEFAULT_CSS = '\n    GridWidget {\n        background: $surface;\n        border: none;\n        height: 1fr;\n        scrollbar-size-horizontal: 0;\n        scrollbar-size-vertical: 1;\n    }\n    '

Default TCSS.

class CursorMoved(row, col)[source]

Bases: Message

Emitted whenever the cursor row/col changes.

Parameters:
__init__(row, col)[source]
Parameters:
Return type:

None

time
bubble: ClassVar[bool] = True
handler_name: ClassVar[str] = 'on_grid_widget_cursor_moved'

Name of the default message handler.

no_dispatch: ClassVar[bool] = False
verbose: ClassVar[bool] = False
cursor_row: reactive[int]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

cursor_col: reactive[int]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

mode: reactive[Mode]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

visual_anchor_row: reactive[int]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

visual_anchor_col: reactive[int]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

show_visual: reactive[bool]

Create a reactive attribute.

Parameters:
  • default – A default value or callable that returns a default.

  • layout – Perform a layout on change.

  • repaint – Perform a repaint on change.

  • init – Call watchers on initialize (post mount).

  • always_update – Call watchers even when the new value equals the old value.

  • recompose – Compose the widget again when the attribute changes.

  • bindings – Refresh bindings when the reactive changes.

  • toggle_class – An optional TCSS classname(s) to toggle based on the truthiness of the value.

__init__(workbook, config=None, **kwargs)[source]

Construct a scrollable container.

Parameters:
  • *children – Child widgets.

  • name – The name of the widget.

  • id – The ID of the widget in the DOM.

  • classes – The CSS classes for the widget.

  • disabled – Whether the widget is disabled or not.

  • can_focus – Can this container be focused?

  • can_focus_children – Can this container’s children be focused?

  • can_maximized – Allow this container to maximize? None to use default logic.,

  • workbook (Workbook)

  • config (Any)

  • kwargs (Any)

Return type:

None

set_search_state(matches, current, pattern='')[source]
Parameters:
Return type:

None

on_mount()[source]
Return type:

None

property sheet: Sheet
get_col_width(col)[source]
Parameters:

col (int)

Return type:

int

update_config(config)[source]
Parameters:

config (Any)

Return type:

None

set_palette(palette)[source]
Parameters:

palette (GridPalette)

Return type:

None

set_preview(row, col, text)[source]
Parameters:
  • row (int | None)

  • col (int | None)

  • text (str)

Return type:

None

collapse_row(row)[source]
Parameters:

row (int)

Return type:

None

expand_row(row)[source]
Parameters:

row (int)

Return type:

None

get_content_width(container, viewport)[source]

Gets the width of the content area.

Parameters:
  • container (Size) – Size of the container (immediate parent) widget.

  • viewport (Size) – Size of the viewport.

Returns:

The optimal width of the content.

Return type:

int

get_content_height(container, viewport, width)[source]

Gets the height (number of lines) in the content area.

Parameters:
  • container (Size) – Size of the container (immediate parent) widget.

  • viewport (Size) – Size of the viewport.

  • width (int) – Width of renderable.

Returns:

The height of the content.

Return type:

int

render_line(y)[source]

Render viewport line y (0 = frozen column-header row).

Parameters:

y (int)

Return type:

Strip

move_cursor(row, col)[source]
Parameters:
Return type:

None

move_by(drow, dcol)[source]
Parameters:
Return type:

None

move_to_row_start()[source]
Return type:

None

move_to_first_nonempty_in_row()[source]
Return type:

None

move_to_row_end()[source]
Return type:

None

move_to_first_row()[source]
Return type:

None

move_to_last_row()[source]
Return type:

None

move_to_first_cell()[source]
Return type:

None

move_to_last_cell()[source]
Return type:

None

jump_next_nonempty_right()[source]
Return type:

None

jump_next_nonempty_left()[source]
Return type:

None

jump_next_nonempty_down()[source]
Return type:

None

jump_next_nonempty_up()[source]
Return type:

None

page_down()[source]
Return type:

None

page_up()[source]
Return type:

None

half_page_down()[source]
Return type:

None

half_page_up()[source]
Return type:

None

go_to_visible_top()[source]
Return type:

None

go_to_visible_middle()[source]
Return type:

None

go_to_visible_bottom()[source]
Return type:

None

start_visual(mode)[source]
Parameters:

mode (Mode)

Return type:

None

visual_selection()[source]
Return type:

CellRange | None

scroll_cell_to_top()[source]
Return type:

None

scroll_cell_to_center()[source]
Return type:

None

scroll_cell_to_bottom()[source]
Return type:

None

watch_cursor_row(_v)[source]
Parameters:

_v (int)

Return type:

None

watch_cursor_col(_v)[source]
Parameters:

_v (int)

Return type:

None

watch_mode(_v)[source]
Parameters:

_v (Mode)

Return type:

None

refresh_grid()[source]
Return type:

None

can_focus = True

Widget may receive focus.

can_focus_children = True

Widget’s children may receive focus.