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:
PyQt5.QtWidgets.QTableViewThe 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¶ 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_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_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
Button cell event handler
- Parameters
toggled (
bool) – Toggle state
-
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_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_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_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_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_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
-
property
row_heights¶ Returns list of tuples (row_index, row height) for current table
-
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
-
class
grid.GridCellDelegate(main_window, grid, code_array)[source]¶ Bases:
PyQt5.QtWidgets.QStyledItemDelegateQStyledItemDelegate 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_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:
PyQt5.QtWidgets.QHeaderViewQHeaderView 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:
PyQt5.QtCore.QAbstractTableModelQAbstractTableModel for Grid
- Parameters
-
code(index)[source]¶ Code in cell index
- Parameters
index (
QModelIndex) – Index of the cell for which the code is returned- Return type
-
columnCount(_=<PyQt5.QtCore.QModelIndex object>)[source]¶ Overloaded QAbstractItemModel.columnCount for code_array backend
- Return type
-
data(index, role=0)[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
ItemFlags
-
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(_=<PyQt5.QtCore.QModelIndex object>)[source]¶ Overloaded QAbstractItemModel.rowCount for code_array backend
- Return type
-
class
grid.TableChoice(main_window, no_tables)[source]¶ Bases:
PyQt5.QtWidgets.QTabBarThe 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
pyspread