grid.*

Provides

class grid.Grid(main_window, model=None)[source]

Bases: PyQt5.QtWidgets.QTableView

The main grid of pyspread

Parameters
  • main_window (QMainWindow) – Application main window

  • model – GridTableModel for grid

_refresh_frozen_cell(key)[source]

Refreshes the frozen cell key

Does neither emit dataChanged nor clear _attr_cache or _table_cache.

Parameters

key (Tuple[int, int, int]) – Key of cell to be refreshed

_selected_idx_to_str(selected_idx)[source]

Converts selected_idx to string with cell indices

Parameters

selected_idx (Iterable[QModelIndex]) – Indices of selected cells

Return type

str

adjust_size()[source]

Adjusts size to header maxima

closeEditor(editor, hint)[source]

Overrides QTableView.closeEditor

Changes to overridden behavior:
  • Data is submitted when a cell is changed without pressing <Enter> e.g. by mouse click or arrow keys.

Parameters
  • editor (QWidget) – Editor to be closed

  • hint (EndEditHint) – Hint to be overridden if == QAbstractItemDelegate.NoHint

property column: int

Current column

Return type

int

property column_widths: List[Tuple[int, float]]

Returns list of tuples (col_index, col_width) for current table

Return type

List[Tuple[int, float]]

contextMenuEvent(event)[source]

Overrides contextMenuEvent to install GridContextMenu

Parameters

event (QContextMenuEvent) – Context menu event

property current: Tuple[int, int, int]

Tuple of row, column, table of the current index

Return type

Tuple[int, int, int]

focusInEvent(event)[source]

Overrides focusInEvent storing last focused grid in main_window

gui_update()[source]

Emits gui update signal

has_selection()[source]

Returns True if more than one cell is selected, else False

This method handles spanned/merged cells. One single cell that is selected is considered as no cell being selected.

Return type

bool

is_column_data_discarded(count)[source]

True if column data is to be discarded on column insertion

Parameters

count (int) – Columns to be inserted

Return type

bool

is_row_data_discarded(count)[source]

True if row data is to be discarded on row insertion

Parameters

count (int) – Rows to be inserted

Return type

bool

is_table_data_discarded(count)[source]

True if table data is to be discarded on table insertion

Parameters

count (int) – Tables to be inserted

Return type

bool

keyPressEvent(event)[source]

Overrides QTableView.keyPressEvent

Changes to overridden behavior:
  • If Shift is pressed, the cell in the next column is selected.

  • If Shift is not pressed, the cell in the next row is selected.

Parameters

event (QKeyEvent) – Key event

on_align_bottom(toggled)[source]

Align bottom button pressed event handler

Parameters

toggled (bool) – Toggle state

on_align_middle(toggled)[source]

Align centere button pressed event handler

Parameters

toggled (bool) – Toggle state

on_align_top(toggled)[source]

Align top button pressed event handler

Parameters

toggled (bool) – Toggle state

on_background_color()[source]

Background color change event handler

on_bold_pressed(toggled)[source]

Bold button pressed event handler

Parameters

toggled (bool) – Toggle state

on_border_choice(event)[source]

Border choice style event handler

Parameters

event (QEvent) – Any event

on_borderwidth()[source]

Border width change event handler

on_button_cell_pressed(toggled)[source]

Button cell event handler

Parameters

toggled (bool) – Toggle state

on_column_resized(column, old_width, new_width)[source]

Column resized event handler

Parameters
  • row – Column that is resized

  • old_width (float) – Column width before resizing

  • new_width (float) – Column width after resizing

on_current_changed(*_)[source]

Event handler for change of current cell

on_data_changed()[source]

Event handler for data changes

on_delete_columns()[source]

Delete columns event handler

on_delete_rows()[source]

Delete rows event handler

on_delete_table()[source]

Delete table event handler

on_font()[source]

Font change event handler

on_font_dialog()[source]

Font dialog event handler

on_font_size()[source]

Font size change event handler

on_freeze_pressed(toggled)[source]

Freeze cell event handler

Parameters

toggled (bool) – Toggle state

on_image_renderer_pressed(toggled)[source]

Image renderer button pressed event handler

Parameters

toggled (bool) – Toggle state

on_insert_columns()[source]

Insert columns event handler

on_insert_rows()[source]

Insert rows event handler

on_insert_table()[source]

Insert table event handler

on_italics_pressed(toggled)[source]

Italics button pressed event handler

Parameters

toggled (bool) – Toggle state

on_justify_center(toggled)[source]

Justify center button pressed event handler

Parameters

toggled (bool) – Toggle state

on_justify_fill(toggled)[source]

Justify fill button pressed event handler

Parameters

toggled (bool) – Toggle state

on_justify_left(toggled)[source]

Justify left button pressed event handler

Parameters

toggled (bool) – Toggle state

on_justify_right(toggled)[source]

Justify right button pressed event handler

Parameters

toggled (bool) – Toggle state

on_line_color()[source]

Line color change event handler

on_lock_pressed(toggled)[source]

Lock button pressed event handler

Parameters

toggled (bool) – Toggle state

on_markup_renderer_pressed(toggled)[source]

Markup renderer button pressed event handler

Parameters

toggled (bool) – Toggle state

on_matplotlib_renderer_pressed(toggled)[source]

Matplotlib renderer button pressed event handler

Parameters

toggled (bool) – Toggle state

on_merge_pressed()[source]

Merge cells button pressed event handler

on_quote()[source]

Quote cells event handler

on_rotate_0(toggled)[source]

Set cell rotation to 0° left button pressed event handler

Parameters

toggled (bool) – Toggle state

on_rotate_180(toggled)[source]

Set cell rotation to 180° left button pressed event handler

Parameters

toggled (bool) – Toggle state

on_rotate_270(toggled)[source]

Set cell rotation to 270° left button pressed event handler

Parameters

toggled (bool) – Toggle state

on_rotate_90(toggled)[source]

Set cell rotation to 90° left button pressed event handler

Parameters

toggled (bool) – Toggle state

on_row_resized(row, old_height, new_height)[source]

Row resized event handler

Parameters
  • row (int) – Row that is resized

  • old_height (float) – Row height before resizing

  • new_height (float) – Row height after resizing

on_selection_changed()[source]

Selection changed event handler

on_show_frozen_pressed(toggled)[source]

Show frozen cells event handler

Parameters

toggled (bool) – Toggle state

on_strikethrough_pressed(toggled)[source]

Strikethrough button pressed event handler

Parameters

toggled (bool) – Toggle state

on_text_color()[source]

Text color change event handler

on_text_renderer_pressed(toggled)[source]

Text renderer button pressed event handler

Parameters

toggled (bool) – Toggle state

on_underline_pressed(toggled)[source]

Underline button pressed event handler

Parameters

toggled (bool) – Toggle state

on_zoom_1()[source]

Sets zoom level ot 1.0

on_zoom_in()[source]

Zoom in event handler

on_zoom_out()[source]

Zoom out event handler

refresh_frozen_cells()[source]

Refreshes all frozen cells

refresh_selected_frozen_cells()[source]

Refreshes selected frozen cells

reset_selection()[source]

Select upper left cell

property row: int

Current row

Return type

int

property row_heights: List[Tuple[int, float]]

Returns list of tuples (row_index, row height) for current table

Return type

List[Tuple[int, float]]

property selected_idx: List[PyQt5.QtCore.QModelIndex]

Currently selected indices

Return type

List[QModelIndex]

property selection: lib.selection.Selection

Pyspread selection based on self’s QSelectionModel

Return type

Selection

property selection_mode: bool

In selection mode, cells cannot be edited

Return type

bool

set_selection_mode(value=True)[source]

Setter for selection mode

This method is required for accessing selection mode from QActions.

Parameters

value – If True, selection mode is set, if False unset

property table: int

Current table

Return type

int

undo_resizing_column()[source]

Sets self.__undo_resizing_column to True for context

undo_resizing_row()[source]

Sets self.__undo_resizing_row to True for context

update_cell_spans()[source]

Update cell spans from model data

update_index_widgets()[source]

Remove old index widgets from model data

update_zoom()[source]

Updates the zoom level visualization to the current zoom factor

wheelEvent(event)[source]

Overrides mouse wheel event handler

Parameters

event (QWheelEvent) – Mouse wheel event

property zoom: float

Returns zoom level

Return type

float

class grid.GridCellDelegate(main_window, grid, code_array)[source]

Bases: PyQt5.QtWidgets.QStyledItemDelegate

QStyledItemDelegate for main grid QTableView

Parameters
  • main_window (QMainWindow) – Application main window

  • grid (Grid) – Grid, i.e. QTableView instance

  • code_array (CodeArray) – Main backend model instance

_get_aligned_image_rect(rect, index, image_width, image_height)[source]

Returns image rect dependent on alignment and justification

Parameters
  • rect (QRectF) – Rect to be aligned

  • image_width (Union[int, float]) – Width of image [px]

  • image_height (Union[int, float]) – Height of image [px]

Return type

QRectF

_get_render_text_document(rect, option, index)[source]

Returns styled QTextDocument that is ready for setting content

Parameters
  • rect (QRectF) – Cell rect of the cell to be painted

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell for which markup is rendered

Return type

QTextDocument

_render_markup(painter, rect, option, index)[source]

HTML markup renderer

Parameters
  • painter (QPainter) – Painter with which markup is rendered

  • rect (QRectF) – Cell rect of the cell to be painted

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell for which markup is rendered

_render_matplotlib(painter, rect, index)[source]

Matplotlib renderer

Parameters
  • painter (QPainter) – Painter with which the matplotlib image is rendered

  • rect (QRectF) – Cell rect of the cell to be painted

  • index (QModelIndex) – Index of cell for which the matplotlib image is rendered

_render_qimage(painter, rect, index, qimage=None)[source]

QImage renderer

Parameters
  • painter (QPainter) – Painter with which qimage is rendered

  • rect (QRectF) – Cell rect of the cell to be painted

  • index (QModelIndex) – Index of cell for which qimage is rendered

  • qimage (Union[str, QImage, None]) – Image to be rendered, may be svg string

_render_text(painter, rect, option, index)[source]

Text renderer

Parameters
  • painter (QPainter) – Painter with which markup is rendered

  • rect (QRectF) – Cell rect of the cell to be painted

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell for which markup is rendered

_render_text_document(doc, painter, rect, option, index)[source]

QTextDocument renderer

Parameters
  • doc (QTextDocument) – Text document to be painted

  • painter (QPainter) – Painter with which markup is rendered

  • rect (QRectF) – Cell rect of the cell to be painted

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell for which markup is rendered

createEditor(parent, option, index)[source]

Overloads QStyledItemDelegate

Disables editor in locked cells Switches to chart dialog in chart cells

Parameters
  • parent (QWidget) – Parent widget for the cell editor to be returned

  • option (QStyleOptionViewItem) – Style option for the cell editor

  • index (QModelIndex) – Index of cell for which a cell editor is created

Return type

QWidget

eventFilter(source, event)[source]

Overloads eventFilter. Overrides QLineEdit default shortcut.

Quotes cell editor content for <Ctrl>+<Enter> and <Ctrl>+<Return>. Counts as undoable action.

Parameters
  • source (QObject) – Source widget of event

  • event (QEvent) – Any QEvent

Return type

bool

paint(painter, option, index)[source]

Overloads QStyledItemDelegate to add cell border painting

Parameters
  • painter (QPainter) – Painter with which borders are drawn

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell to be rendered

paint_(painter, rect, option, index)[source]

Calls the overloaded paint function or creates html delegate

Parameters
  • painter (QPainter) – Painter with which borders are drawn

  • rect (QRectF) – Cell rect of the cell to be painted

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell for which borders are drawn

setEditorData(editor, index)[source]

Overloads setEditorData to use code_array data

Parameters
  • editor (QWidget) – Cell editor, in which data is set

  • index (QModelIndex) – Index of cell from which the cell editor data is set

setModelData(editor, model, index)[source]

Overloads setModelData to use code_array data

Parameters
  • editor (QWidget) – Cell editor, from which data is retrieved

  • model (QAbstractItemModel) – GridTableModel

  • index (QModelIndex) – Index of cell for which data is set

sizeHint(option, index)[source]

Overloads SizeHint

Parameters
  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of the cell for the size hint

Return type

QSize

updateEditorGeometry(editor, option, _)[source]

Overloads updateEditorGeometry to update editor geometry to cell

Parameters
  • editor (QWidget) – Cell editor, for which geometry is retrieved

  • option (QStyleOptionViewItem) – Style option of the editor

class grid.GridHeaderView(orientation, grid)[source]

Bases: PyQt5.QtWidgets.QHeaderView

QHeaderView with zoom support

Parameters
  • orientation (Orientation) – Orientation of the QHeaderView

  • grid (Grid) – The main grid widget

contextMenuEvent(event)[source]

Overrides contextMenuEvent

Installs HorizontalHeaderContextMenu or VerticalHeaderContextMenu depending on self.orientation().

Parameters

event (QContextMenuEvent) – The triggering event

paintSection(painter, rect, logicalIndex)[source]

Overrides paintSection, which supports zoom

Parameters
  • painter (QPainter) – Painter with which the section is drawn

  • rect (QRect) – Outer rectangle of the section to be drawn

  • logicalIndex (int) – Index of the section to be drawn

sectionSizeHint(logicalIndex)[source]

Overrides sectionSizeHint, which supports zoom

Parameters

logicalIndex (int) – Index of the section for the size hint

Return type

int

sizeHint()[source]

Overrides sizeHint, which supports zoom

Return type

QSize

update_zoom()[source]

Updates zoom for the section sizes

class grid.GridTableModel(main_window, shape)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

QAbstractTableModel for Grid

Parameters
  • main_window (QMainWindow) – Application main window

  • shape (Tuple[int, int, int]) – Grid shape (rows, columns, tables)

code(index)[source]

Code in cell index

Parameters

index (QModelIndex) – Index of the cell for which the code is returned

Return type

str

columnCount(_=<PyQt5.QtCore.QModelIndex object>)[source]

Overloaded QAbstractItemModel.columnCount for code_array backend

Return type

int

current(index)[source]

Tuple of row, column, table of given index

Parameters

index (QModelIndex) – Index of the cell to be made the current cell

Return type

Tuple[int, int, int]

data(index, role=0)[source]

Overloaded data for code_array backend

Parameters
  • index (QModelIndex) – Index of the cell, for which data is returned

  • role (ItemDataRole) – Role of data to be returned

Return type

Any

flags(index)[source]

Overloaded, makes items editable

Parameters

index (QModelIndex) – Index of cell for which flags are returned

Return type

ItemFlags

font(key)[source]

Returns font for given key

Parameters

key (Tuple[int, int, int]) – Key of cell, for which font is returned

Return type

QFont

property grid: grid.Grid
Return type

Grid

headerData(idx, _, role)[source]

Overloaded for displaying numbers in header

Parameters
  • idx (QModelIndex) – Index of header for which data is returned

  • role (ItemDataRole) – Role of data to be returned

Return type

str

insertColumns(column, count)[source]

Overloaded QAbstractItemModel.insertColumns for code_array backend

Parameters
  • column (int) – Column at which columns are inserted

  • count (int) – Number of columns to be inserted

Return type

bool

insertRows(row, count)[source]

Overloaded QAbstractItemModel.insertRows for code_array backend

Parameters
  • row (int) – Row at which rows are inserted

  • count (int) – Number of rows to be inserted

Return type

bool

insertTable(table, count=1)[source]

Inserts tables

Parameters
  • table (int) – Table at which tables are inserted

  • count (int) – Number of tables to be inserted

inserting_columns(index, first, last)[source]

Context manager for inserting columns

see QAbstractItemModel.beginInsertColumns

Parameters
  • index (QModelIndex) – Parent into which the new columns are inserted

  • first (int) – Column number that first column will have after insertion

  • last (int) – Column number that last column will have after insertion

inserting_rows(index, first, last)[source]

Context manager for inserting rows

see QAbstractItemModel.beginInsertRows

Parameters
  • index (QModelIndex) – Parent into which the new rows are inserted

  • first (int) – Row number that first row will have after insertion

  • last (int) – Row number that last row will have after insertion

model_reset()[source]

Context manager for handle changing/resetting model data

removeColumns(column, count)[source]

Overloaded QAbstractItemModel.removeColumns for code_array backend

Parameters
  • column (int) – Column at which columns are removed

  • count (int) – Number of columns to be removed

Return type

bool

removeRows(row, count)[source]

Overloaded QAbstractItemModel.removeRows for code_array backend

Parameters
  • row (int) – Row at which rows are removed

  • count (int) – Number of rows to be removed

Return type

bool

removeTable(table, count=1)[source]

Removes tables

Parameters
  • table (int) – Table at which tables are removed

  • count (int) – Number of tables to be removed

removing_columns(index, first, last)[source]

Context manager for removing columns

see QAbstractItemModel.beginRemoveColumns

Parameters
  • index (QModelIndex) – Parent from which columns are removed

  • first (int) – Column number of the first column to be removed

  • last (int) – Column number of the last column to be removed

removing_rows(index, first, last)[source]

Context manager for removing rows

see QAbstractItemModel.beginRemoveRows

Parameters
  • index (QModelIndex) – Parent from which rows are removed

  • first (int) – Row number of the first row to be removed

  • last (int) – Row number of the last row to be removed

reset()[source]

Deletes all grid data including undo data

rowCount(_=<PyQt5.QtCore.QModelIndex object>)[source]

Overloaded QAbstractItemModel.rowCount for code_array backend

Return type

int

setData(index, value, role, raw=False, table=None)[source]

Overloaded setData for code_array backend

Parameters
  • index (QModelIndex) – Index of the cell, for which data is set

  • value (Any) – Value of data to be set

  • role (ItemDataRole) – Role of data to be set

  • raw (bool) – Sets raw data without string formatting in EditRole

  • table (Optional[int]) – Table for which data shall is set

Return type

bool

property shape: Tuple[int, int, int]

Returns 3-tuple of rows, columns and tables

Return type

Tuple[int, int, int]

class grid.TableChoice(main_window, no_tables)[source]

Bases: PyQt5.QtWidgets.QTabBar

The TabBar below the main grid

Parameters
  • main_window (QMainWindow) – Application main window

  • no_tables (int) – Number of tables to be initially created

contextMenuEvent(event)[source]

Overrides contextMenuEvent to install GridContextMenu

Parameters

event (QContextMenuEvent) – Triggering event

property no_tables: int

Returns the number of tables in the table_choice

Return type

int

on_table_changed(current)[source]

Event handler for table changes

Parameters

current (int) – The current table to be displayed

property table: int

Returns current table from table_choice that is displayed

Return type

int