grid.*¶
Pyspread’s main grid
Provides
Grid
: QTableView of the main gridGridHeaderView
: QHeaderView for the main grids headersGridTableModel
: QAbstractTableModel linking the view to code_array backendGridCellDelegate
: QStyledItemDelegate handling custom painting and editorsTableChoice
: The TabBar below the main grid
- class grid.Grid(main_window, model=None)[source]¶
Bases:
QTableView
The main grid of pyspread
- Parameters:
main_window (
QMainWindow
) – Application main windowmodel – GridTableModel for grid
- _refresh_frozen_cell(key)[source]¶
Refreshes the frozen cell key
Does neither emit dataChanged nor clear _attr_cache or _table_cache.
- 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 closedhint (
EndEditHint
) – Hint to be overridden if == QAbstractItemDelegate.NoHint
- property column_widths: List[Tuple[int, float]]¶
Returns list of tuples (col_index, col_width) for current table
- contextMenuEvent(event)[source]¶
Overrides contextMenuEvent to install GridContextMenu
- Parameters:
event (
QContextMenuEvent
) – Context menu event
- 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:
- 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_bold_pressed(toggled)[source]¶
Bold button pressed event handler
- Parameters:
toggled (
bool
) – Toggle state
- on_button_cell_pressed(toggled)[source]¶
Button cell event handler
- Parameters:
toggled (
bool
) – Toggle state
- on_freeze_pressed(toggled)[source]¶
Freeze cell event handler
- Parameters:
toggled (
bool
) – Toggle state
- on_italics_pressed(toggled)[source]¶
Italics button pressed event handler
- Parameters:
toggled (
bool
) – Toggle state
- on_lock_pressed(toggled)[source]¶
Lock button pressed event handler
- Parameters:
toggled (
bool
) – Toggle state
- 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_underline_pressed(toggled)[source]¶
Underline button pressed event handler
- Parameters:
toggled (
bool
) – Toggle state
- property row_heights: List[Tuple[int, float]]¶
Returns list of tuples (row_index, row height) for current table
- set_selection_mode(value=True)[source]¶
Setter for selection mode for all grids
- Parameters:
value – If True, selection mode is set, if False unset
- toggle_selection_mode()[source]¶
Toggle selection mode for all grids
This method is required for accessing selection mode from QActions.
- class grid.GridCellDelegate(main_window, grid, code_array)[source]¶
Bases:
QStyledItemDelegate
QStyledItemDelegate for main grid QTableView
- Parameters:
- _get_aligned_image_rect(rect, index, image_width, image_height)[source]¶
Returns image rect dependent on alignment and justification
- _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 paintedoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 renderedrect (
QRectF
) – Cell rect of the cell to be paintedoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 renderedrect (
QRectF
) – Cell rect of the cell to be paintedindex (
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 renderedrect (
QRectF
) – Cell rect of the cell to be paintedindex (
QModelIndex
) – Index of cell for which qimage is renderedqimage (
QImage
) – Image to be rendered, decoration drawn if not provided
- _render_svg(painter, rect, index, svg_str=None)[source]¶
SVG renderer
- Parameters:
painter (
QPainter
) – Painter with which qimage is renderedrect (
QRectF
) – Cell rect of the cell to be paintedindex (
QModelIndex
) – Index of cell for which qimage is renderedsvg_str (
str
) – SVG string
- _render_text(painter, rect, option, index)[source]¶
Text renderer
- Parameters:
painter (
QPainter
) – Painter with which markup is renderedrect (
QRectF
) – Cell rect of the cell to be paintedoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 paintedpainter (
QPainter
) – Painter with which markup is renderedrect (
QRectF
) – Cell rect of the cell to be paintedoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 returnedoption (
QStyleOptionViewItem
) – Style option for the cell editorindex (
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 eventevent (
QEvent
) – Any QEvent
- Return type:
- paint(painter, option, index)[source]¶
Overloads QStyledItemDelegate to add cell border painting
- Parameters:
painter (
QPainter
) – Painter with which borders are drawnoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 drawnrect (
QRectF
) – Cell rect of the cell to be paintedoption (
QStyleOptionViewItem
) – Style option for renderingindex (
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 setindex (
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 retrievedmodel (
QAbstractItemModel
) – GridTableModelindex (
QModelIndex
) – Index of cell for which data is set
- class grid.GridHeaderView(orientation, grid)[source]¶
Bases:
QHeaderView
QHeaderView with zoom support
- Parameters:
orientation (
Orientation
) – Orientation of the QHeaderViewgrid (
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 drawnrect (
QRect
) – Outer rectangle of the section to be drawnlogicalIndex (
int
) – Index of the section to be drawn
- class grid.GridTableModel(main_window, shape)[source]¶
Bases:
QAbstractTableModel
QAbstractTableModel for Grid
- Parameters:
- cell_to_update¶
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- code(index)[source]¶
Code in cell index
- Parameters:
index (
QModelIndex
) – Index of the cell for which the code is returned- Return type:
- columnCount(_=<PyQt6.QtCore.QModelIndex object>)[source]¶
Overloaded QAbstractItemModel.columnCount for code_array backend
- Return type:
- data(index, role=ItemDataRole.DisplayRole)[source]¶
Overloaded data for code_array backend
- Parameters:
index (
QModelIndex
) – Index of the cell, for which data is returnedrole (
ItemDataRole
) – Role of data to be returned
- Return type:
- flags(index)[source]¶
Overloaded, makes items editable
- Parameters:
index (
QModelIndex
) – Index of cell for which flags are returned- Return type:
ItemFlag
- headerData(idx, _, role)[source]¶
Overloaded for displaying numbers in header
- Parameters:
idx (
QModelIndex
) – Index of header for which data is returnedrole (
ItemDataRole
) – Role of data to be returned
- Return type:
- insertColumns(column, count)[source]¶
Overloaded QAbstractItemModel.insertColumns for code_array backend
- inserting_columns(index, first, last)[source]¶
Context manager for inserting columns
see QAbstractItemModel.beginInsertColumns
- inserting_rows(index, first, last)[source]¶
Context manager for inserting rows
see QAbstractItemModel.beginInsertRows
- removeColumns(column, count)[source]¶
Overloaded QAbstractItemModel.removeColumns for code_array backend
- removing_columns(index, first, last)[source]¶
Context manager for removing columns
see QAbstractItemModel.beginRemoveColumns
- removing_rows(index, first, last)[source]¶
Context manager for removing rows
see QAbstractItemModel.beginRemoveRows
- rowCount(_=<PyQt6.QtCore.QModelIndex object>)[source]¶
Overloaded QAbstractItemModel.rowCount for code_array backend
- Return type:
- class grid.TableChoice(main_window, no_tables)[source]¶
Bases:
QTabBar
The TabBar below the main grid
- Parameters:
main_window (
QMainWindow
) – Application main windowno_tables (
int
) – Number of tables to be initially created
- contextMenuEvent(event)[source]¶
Overrides contextMenuEvent to install GridContextMenu
- Parameters:
event (
QContextMenuEvent
) – Triggering event