schrodinger.ui.qt.table module

Contains classes that can be used to display a QTable that can show both structures and text data in arbitrary cells.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.ui.qt.table.EmittingScrollBar

Bases: PyQt6.QtWidgets.QScrollBar

Works the same as a normal scrollbar, but emits signals when it is shown or hidden.

shown

pyqtSignal(*types, name: str = …, revision: 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.

hidden

pyqtSignal(*types, name: str = …, revision: 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.

showEvent(event)

Emit a signal to indicate that the scrollbar has been shown

Parameters

event (QShowEvent object) – the event generated when shown

hideEvent(event)

Emit a signal to indicate that the scrollbar has been hidden

Parameters

event (QHideEvent object) – the event generated when hidden

class schrodinger.ui.qt.table.SHeaderView(orientation, parent)

Bases: PyQt6.QtWidgets.QHeaderView

Class for horizontal and vertical headers of a table. This class is robust to a resizing issue that can occur when the whole table begins to resize when the user resizes a row or column. It uses globalPos() for the mouse move event during resizing rather than pos(), as pos() is relative to the widget corner (which itself is moving when the problem occurs).

__init__(orientation, parent)

Instantiate an SHeaderView object

Parameters
  • orientation (int (QtCore.Qt.Horizontal or QtCore.Qt.Vertical)) – whether this is horizontal or vertical

  • parent (QTableView object) – The table that should be resized by this header

mouseReleaseEvent(event)

Stop any resizing that we are doing

Parameters

event (QMouseEvent) – the event object

mouseMoveEvent(event)

Makes resizing of rows/columns robust to motion of the widget itself by using global mouse coordinates rather than local-to-the-widget coordinates.

Note that, if the mouse is pressed in the header, the header still gets mouse move events until the mouse button is released even if the cursor leaves the header area.

Parameters

event (QMouseEvent) – the event object

class schrodinger.ui.qt.table.DataViewerTable(model=None, parent=None, aspect_ratio=True, fill='rows', gang='both', resizable='none', fit_view='none', vscrollbar='default', hscrollbar='default', cell_height=100, cell_width=100, enable_copy=True, universal_row_gang_setting=False, universal_column_gang_setting=False)

Bases: PyQt6.QtWidgets.QTableView

__init__(model=None, parent=None, aspect_ratio=True, fill='rows', gang='both', resizable='none', fit_view='none', vscrollbar='default', hscrollbar='default', cell_height=100, cell_width=100, enable_copy=True, universal_row_gang_setting=False, universal_column_gang_setting=False)
Parameters
  • model (QAbstractTableModel) – The model for this table. The typical class to use with this table is the StructureDataViewerModel class

  • parent (QWidget) – The widget that owns this table widget

  • aspect_ratio (bool) – if True (default) keeps the cell height & width aspect ratio locked at the ratio indicated by cell_height and cell width. Note that True implies gang=”both”. If aspect_ratio is true, fill can be “rows” OR “columns”, but NOT “both”.

  • fill ("rows", "columns", "both" or "none") – The specified table feature will expand or contract to exactly fit within the table’s viewport.

  • “none”: means neither rows or columns will expand

  • “rows”: means rows will expand (default)

  • “columns”: means columns will expand

  • “both”: means both rows and columns will expand

fill cannot be “both” if aspect_ratio is True.

Setting a feature to fill will turn off the corresponding scrollbar.

Parameters

gang ("rows", "columns", "both" or "none") – Controls whether rows and/or columns can be independently resized.

  • “none” - rows and columns can be independently resized

  • “rows” - rows are ganged so that changing the size of one row will change all the rows

  • “columns” - columns are ganged so that changing the size of one column will change all the columns

  • “both” - both rows and columns are ganged (default)

Parameters
  • universal_row_gang_setting (bool) – If true, then the gang setting applies to ALL rows and a subset of rows may not be ganged. If False (the default), either a subset or all rows may be ganged. It is never necessary to set this option, however setting it does allow for a slight improvement in memory usage for very large tables. Note that this setting applies whether the rows are all ganged or all not ganged. Note that this setting in combination with ganging rows will prevent actions such as hiding the row that change the row size.

  • universal_column_gang_setting (bool) – If true, then the gang setting applies to ALL columns and a subset of columns may not be ganged. If False (the default), either a subset or all columns may be ganged. It is never necessary to set this option, however setting it does allow for a slight improvement in memory usage for very large tables. Note that this setting applies whether the columns are all ganged or all not ganged. Note that this setting in combination with ganging columns will prevent actions such as hiding the column that change the column size.

  • resizable ("rows", "columns", "both" or "none") – the table features that can be resized by the user.

  • “none” - neither rows nor columns can be resized by the user

  • “rows” - rows can be resized by the user

  • “columns” - columns can be resized by the user

  • “both” - both rows and columns can be resized by the user (default)

Note - a feature that has fill turned on cannot be resized by the user, and if fill is turned on and aspect_ratio is True, neither rows nor columns can be resized by the user.

Parameters

fit_view ("rows", "columns", "both" or "none") – the table features that determine the size of the table’s viewport (the part visible to the user).

When this is turned on for a feature, the visible part of the table resizes dynamically to exactly fit that feature. For instance, if fit_view=’rows’, the visible part of the table will resize to exactly fit all the rows any time the size of a row changes.

  • “none” - neither rows nor columns determine the viewport size

  • “rows” - rows determine the viewport height

  • “columns” - columns determine the viewport width

  • “both” - both rows and columns determine the viewport size

Note - a feature that has fill turned on cannot have viewport_fit turned on. fill uses the size of the viewport to determine the size of the cells, while fit_view uses the sie of the cells to determine the size of the viewport.

Note 2 - Setting a feature to fit_view will turn off the corresponding scrollbar.

Note 3 - User resizing of rows with both gang and fit_view=’rows’ or ‘both’ tends to be a bit wonky because the amount the row resizes depends on the placement of the mouse relative to the table, and the table moves as it resizes to the rows, so you tend to get very large changes rapidly.

Parameters

vscrollbar ("on", "off" or "default") – Vertical scrollbar setting - “on” - always on - “off” - always off - “default” - (default) on as needed

If either fit_view or fill = “rows” or “both”, the vertical scrollbar is turned off

Parameters

hscrollbar ("on", "off" or "default") – Horizontal scrollbar setting - “on” - always on - “off” - always off - “default” - (default) on as needed

If either fit_view for fill =”columns” or “both”, the horizontal scrollbar is turned off

Parameters
  • cell_width (int) – default width of cells in pixels

  • cell_height (int) – default height of cells in pixels

  • enable_copy (bool) – True if data in the table can be copied to the clipboard. Cells with structures copy the title of the structure to the clipboard, else the string conversion of the structure to the clipboard.

auto_size

Whether the table should automatically resize in response to changes

copyImageToClipboard()

Copy an image of the table to the clipboard

headerClicked(col)
enforceScrollBarPolicies()

Sets the scrollbar policies as required by the sizing policies

setFitViewPolicy(fit_view, resize=True, policy_check=True, enforce_scroll_bars=True)

Sets whether the viewport should be resized to the rows/columns or not

Parameters

fit_view ("rows", "columns", "both" or "none") – the table features that determine the size of the table’s viewport (the part visible to the user).

When this is turned on for a feature, the visible part of the table resizes dynamically to exactly fit that feature. For instance, if fit_view=’rows’, the visible part of the table will resize to exactly fit all the rows any time the size of a row changes.

  • “none” - neither rows nor columns determine the viewport size

  • “rows” - rows determine the viewport height

  • “columns” - columns determine the viewport width

  • “both” - both rows and columns determine the viewport size

Note - a feature that has fill turned on cannot have viewport_fit turned on. fill uses the size of the viewport to determine the size of the cells, while fit_view uses the sie of the cells to determine the size of the viewport.

Note 2 - Setting a feature to fit_view will turn off the corresponding scrollbar.

Note 3 - User resizing of rows with both gang and fit_view=’rows’ or ‘both’ tends to be a bit wonky because the amount the row resizes depends on the placement of the mouse relative to the table, and the table moves as it resizes to the rows, so you tend to get very large changes rapidly.

Parameters
  • resize (bool) – Whether to resize the table

  • policy_check (bool) – Whether to check for conflicting sizing policies.

  • enforce_scroll_bars (bool) – Whether to enforce the default scrollbar policy for fit view settings

setFillPolicy(fill, resize=True, policy_check=True, enforce_scroll_bars=True)

Sets whether columns or rows should fill the viewport or not

Parameters
  • fill ("rows", "columns", "both" or "none") – The specified table feature will expand or contract to exactly fit within the table’s viewport. “both” means both rows and columns will expand, and “none” means neither will. fill cannot be “both” if aspect_ratio is True. Setting a feature to fill will turn off the corresponding scrollbar.

  • resize (bool) – Whether to resize the table

  • policy_check (bool) – Whether to check for conflicting sizing policies.

  • enforce_scroll_bars (bool) – Whether to enforce the default scrollbar policy for fill settings

setGangPolicy(gang, resize=True, policy_check=True)

Sets whether the rows or columns are ganged or not

Parameters

gang ("rows", "columns", "both" or "none") – Controls whether rows and/or columns can be independently resized.

  • “none”: rows and columns can be independently resized

  • “rows”: rows are ganged so that changing the size of one row will change all the rows

  • “columns”: columns are ganged so that changing the size of one column will change all the columns

  • “both” - both rows and columns are ganged (default)

Parameters
  • resize (bool) – Whether to resize the table

  • policy_check (bool) – Whether to check for conflicting sizing policies. Not used for this routine, but kept for consistency with other sizing policy routines

isRowGanged(row)

Returns True if row is ganged, False if not

Parameters

row (int) – the row to check for ganging

isColumnGanged(column)

Returns True if column is ganged, False if not

Parameters

column (int) – the column to check for ganging

setRowIsGanged(row, is_ganged)

Sets a flag on row to indicate whether its size is ganged with other rows or not. Note that this has no effect if rows are not already ganged. This function should not be called if universal_row_gang_settings was set to True.

Parameters
  • row (int) – the row number this applies to

  • is_ganged (bool) – True if the row should be ganged, False if not

setColumnIsGanged(column, is_ganged)

Sets a flag on column to indicate whether its size is ganged with other columns or not. Note that this has no effect if columns are not already ganged. This function should not be called if universal_column_gang_setting was set to True.

Parameters
  • column (int) – the column number this applies to

  • is_ganged (bool) – True if the column should be ganged, False if not

setAspectRatioPolicy(fixed, resize=True, policy_check=True)

Sets whether the cell aspect ratio is locked or not

Parameters
  • fixed (bool) – If True, cell aspect ratio is locked. If False, it is not

  • resize (bool) – Whether to resize the table

  • policy_check (bool) – Whether to check for conflicting sizing policies.

setResizablePolicy(resizable, resize=True, policy_check=True)

Sets whether the rows/columns can be resized by the user

Parameters

resizable ("rows", "columns", "both" or "none") – the table features that can be resized by the user.

  • “none” - neither rows nor columns can be resized by the user

  • “rows” - rows can be resized by the user

  • “columns” - columns can be resized by the user

  • “both” - both rows and columns can be resized by the user (default)

Note - a feature that has fill turned on cannot be resized by the user, and if fill is turned on and aspect_ratio is True, neither rows nor columns can be resized by the user.

Parameters
  • resize (bool) – Whether to resize the table

  • policy_check (bool) – Whether to check for conflicting sizing policies.

setSortingEnabled(sorting)

Sets sorting enabled

Parameters

sorting (bool) – If True, sorting is enabled

checkSizingPolicies()

Raises a ValueError if we have conflicting sizing policies

initiateCellSizes(rows=True, columns=True)

Sets all the cells to their intial default size

Parameters
  • rows (bool) – whether to set the rows to their default height

  • columns (bool) – whether to set the columns to their default width

rowsInserted(index, start, end)

Slot that receives a signal when rows are inserted in the model. Make sure our row_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the rows inserted

  • end (int) – The ending index of the rows inserted (inclusive)

rowsMoved(index1, start, end, index2, place)

Slot that receives a signal when rows are moved in the model. Make sure our row_is_ganged list stays current.

Parameters
  • index1 (QModelIndex) – unused

  • start (int) – The starting index of the rows moved

  • end (int) – The ending index of the rows moved (inclusive)

  • index2 (QModelIndex) – unused

  • place (int) – The new starting index of the moved rows

rowsRemoved(index, start, end)

Slot that receives a signal when rows are removed in the model. Make sure our row_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the rows removed

  • end (int) – The ending index of the rows removed (inclusive)

columnsInserted(index, start, end)

Slot that receives a signal when columns are inserted in the model. Make sure our column_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the columns inserted

  • end (int) – The ending index of the columns inserted (inclusive)

columnsMoved(index1, start, end, index2, place)

Slot that receives a signal when columns are moved in the model. Make sure our column_is_ganged list stays current.

Parameters
  • index1 (QModelIndex) – unused

  • start (int) – The starting index of the columns moved

  • end (int) – The ending index of the columns moved (inclusive)

  • index2 (QModelIndex) – unused

  • place (int) – The new starting index of the moved columns

columnsRemoved(index, start, end)

Slot that receives a signal when columns are removed in the model. Make sure our column_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the columns removed

  • end (int) – The ending index of the columns removed (inclusive)

columnCountChanged(old_count, new_count)

Called when a column is added or deleted, and sets the columns to their initial size.

Parameters
  • old_count (int) – the old number of columns

  • new_count (int) – the num number of columns

rowCountChanged(old_count, new_count)

Called when a row is added or deleted, and sets the rows to their initial size.

Parameters
  • old_count (int) – the old number of rows

  • new_count (int) – the num number of rows

keyPressEvent(event)
Parameters

event (QKeyEvent) – The keypress event

Currently only does anything for Ctrl-C (copy to clipboard)

setItemDelegate(delegate)

Set the delegate for this table

Parameters

delegate (StructureDataViewerDelegate) – delegate that draws the data for this table

setDelegate(delegate)

Set the delegate for this table

Parameters

delegate (StructureDataViewerDelegate) – delegate that draws the data for this table

rowResized(row, old_size, new_size, manual=False)

Resizes any cells that need to be resized when a row size is changed

Parameters
  • row (int) – the row number that changed

  • old_size (int) – the old size of the row

  • new_size (int) – the new size of the row

  • manual (bool) – True if this a manual resize being called by a script. If True, this forces the method to execute even if AutoResizing has been set to false.

columnResized(column, old_size, new_size, manual=False)

Resizes any cells that need to be resized when a column size is changed

Parameters
  • column (int) – the column number that changed

  • old_size (int) – the old size of the column

  • new_size (int) – the new size of the column

  • manual (bool) – True if this a manual resize being called by a script. If True, this forces the method to execute even if AutoResizing has been set to false.

reEnableColumnResize()
fitToRows()

Fits the viewport to exactly show all the rows

fitToColumns()

Fits the viewport to exactly show all the columns

totalRowHeight()

The sum of the heights of all the rows

Return type

int

Returns

the sum of all the row heights

averageGangedRowHeight()

This routine has been changed to return the MOST COMMON non-zero height of all the ganged rows

Return type

int

Returns

the most common integer average row height, or the default height if there are no non-zero ganged rows

totalColumnWidth()

The sum of the widths of all the columns

Return type

int

Returns

the sum of all the column widths

averageGangedColumnWidth()

This routine has been changed to return the MOST COMMON non-zero width of all the ganged columns

Return type

int

Returns

the most common integer average column width, or the default width if there are no non-zero ganged columns

scrollBarChanged(orientation)

A scrollbar has changed appearance, make sure we have the proper size

setAutoSizing(state)

Turn the auto resizing of rows and column on or off. Normally this should be on (default), however, if multiple changes will be made and no resizing needs to be done until all changes are complete, then setting AutoSizing to False will save considerable time for large tables. Be sure to setAutoSizing(True) when finished so the table can adjust to the changes made.

Parameters

state (bool) – True if rows and columns should be resized automatically in response to table changes, False if not

fixSize(manual=False)

Resize everything as the user and program desires

Parameters

manual (bool) – True if this a manual resize being called by a script. If True, this forces the method to execute even if AutoResizing has been set to false.

fitCellsToData(include_column_header=False)

Resizes rows and columns to fit the data they contain using the sizeHint from the delegate

Parameters

include_column_header (bool) – True if the column header should be included when figuring the column width, False if not

fitRowsToData()

Resizes all the rows to fit the data they contain using the sizeHint from the delegate.

fitRowToData(row)

Resizes row to the largest sizeHint of any of its cells. Uses the sizeHint of the delegate.

Parameters

row (int) – the row of interest

fitColumnsToData(include_header=False)

Resizes all the columns to fit the data they contain using the sizeHint from the delegate.

Parameters

include_header (bool) – True if the header should be included in the calculation of column width, False if not

fitColumnToData(column, include_header=False)

Resizes column to the largest sizeHint of any of its cells. Uses the sizeHint of the delegate.

Parameters
  • column (int) – the column of interest

  • include_header (bool) – True if the header should be included in the calculation of column width, False if not

resizeRowsToContents()

Resizes all the rows according to all the resize properties

resizeColumnsToContents()

Resizes all the columns according to all the resize properties

resizeEvent(event)

Called when the viewport changes size. Changes the size of any cells that need to be changed in response to this - typically because fill has been set on rows or columns.

Parameters

event (QEvent) – the event that occured

sizeHintForColumn(column)

This method gives the size hints for columns - its existance means that the resizeColumnsToContents() method uses this hint rather than hints from the delegate.

Parameters

column (int) – the column we want a size hint for

Return type

int

Returns

the size hint for column

sizeHintForRow(row)

This method gives the size hints for rows - its existance means that the resizeRowsToContents() method uses this hint rather than hints from the delegate.

Parameters

row (int) – the row we want a size hint for

Return type

int

Returns

the size hint for row

isScrolling()
isActivelyScrolling()
setToolTipSize(width, height)
Parameters
  • width (int) – width in pixels of tooltip

  • height (int) – height in pixels of tooltip

class schrodinger.ui.qt.table.ViewerModel(rowcount=0, columncount=4, unique=False)

Bases: PyQt6.QtCore.QAbstractTableModel

sizeChanged

pyqtSignal(*types, name: str = …, revision: 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.

__init__(rowcount=0, columncount=4, unique=False)
structCount()
appendStruct(struct)
clearStructs()
getStruct(index)
setStruct(index, struct)

Given the index, replace the structure with the new value. If the _unique flag is true and the new value already exists in table, it is not added.

Returns

Return whether the new structure was successfully set at the specified index.

Return type

bool

removeStruct(row, column)
rowCount(self, parent: QModelIndex = QModelIndex()) int
columnCount(self, parent: QModelIndex = QModelIndex()) int
data(self, index: QModelIndex, role: int = Qt.DisplayRole) Any
insertRows(self, row: int, count: int, parent: QModelIndex = QModelIndex()) bool
insertColumns(self, column: int, count: int, parent: QModelIndex = QModelIndex()) bool
removeRows(self, row: int, count: int, parent: QModelIndex = QModelIndex()) bool
removeColumns(self, column: int, count: int, parent: QModelIndex = QModelIndex()) bool
resize(row, column)
resizeRows(row)
resizeColumns(cols)
setTable(view)
reset()

PANEL-8852: Method added to prevent QtUpgradeError. This preserves backwards compatibility with QtCore.QAbstractTableModel.reset() but does not reset anything.

class schrodinger.ui.qt.table.StructureDataViewerModel(rows=4, columns=8, vlabels=None, hlabels=None)

Bases: schrodinger.ui.qt.table.ViewerModel

A table model that handles 2-D structures and data.

This inherits ViewerModel, but is designed to be less 2-D structure-centric than that model, which assumes all the cells contain structures.

headerDataChanged

pyqtSignal(*types, name: str = …, revision: 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.

__init__(rows=4, columns=8, vlabels=None, hlabels=None)
Parameters
  • rows (int) – number of rows in the table

  • columns (int) – number of columns in the table

  • vlabels (list of strings) – labels for the row headers

  • hlabels (list of strings) – labels for the column headers

setTable(table)
Parameters

table (DataViewerTable) – the table this model contains data for

Deprecated table

This function should not be used, because a model can refer to multiple views.

setDelegate(delegate)

Sets the Delegate that draws the data from this model.

Parameters

delegate (StructureDataViewerDelegate) – delegate that draws the data from this model

Deprecated delegate

This function should not be used, because a model can have many delegates

myDataChanged(row1, column1, row2, column2)

Emits the proper signal to indicate that data in the table has changed.

Rows and columns are 0-indexed

Parameters
  • row1 (non-negative int) – row index of the top, left-most cell that changed

  • row2 (non-negative int) – row index of the bottom, right-most cell that changed

  • column1 (non-negative int) – column index of the top, left-most cell that changed

  • column2 (non-negative int) – column index of the bottom, right-most cell changed

initializeValueMatrix(reset_row_labels=True, reset_column_labels=False)

Resets all the cells to values of None and resets the row labels (by default)

Parameters
  • reset_row_labels (bool) – if True, all row labels are reset to simple numbers, if False, they are not. This is True by default.

  • reset_column_labels (bool) – if True, all column labels are reset to simple numbers, if False, they are not. This is False by default.

setToolTip(row, column, value)

Sets the tooltip for the cell located at row, column

Parameters
  • row (int) – row the cell is in (0-indexed)

  • column (int) – column the cell is in (0-indexed)

  • value (type that can be set in a tooltip) – value for the tooltip in the cell at (row, column)

insertColumn(column, index=None, renumber_headers=False)

Insert a column into the model and table

Parameters
  • column (int) – the column index to insert a new column at

  • index (QModelIndex()) – unused

  • renumber_headers (bool) – True if all the column headers should be renumbered, false if not (leave as default if custom column headers have been used)

insertColumns(place, columns, index=None, renumber_headers=False)

Insert columns into the model and table at index place

Parameters
  • place (int) – the index to insert the columns at

  • columns (int) – the number of columns to insert

  • index (QModelIndex()) – unused

  • renumber_headers (bool) – True if all the column headers should be renumbered, false if not (leave as default if custom column headers have been used)

removeColumn(column, index=None, renumber_headers=False)

Remove a column from the model and table

Parameters
  • column (int) – the column index to remove

  • index (QModelIndex()) – unused

removeColumns(place, columns, index=None, renumber_headers=False)

Remove columns from the model and table starting at index place

Parameters
  • place (int) – the index to begin removing columns at

  • columns (int) – the number of columns to remove

  • index (QModelIndex()) – unused

insertRow(row, index=None, renumber_headers=False)

Insert a row into the model and table

Parameters
  • row (int) – the row index to insert a new row at

  • index (QModelIndex()) – unused

  • renumber_headers (bool) – True if all the row headers should be renumbered, false if not (leave as default if custom row headers have been used)

insertRows(place, rows, index=None, renumber_headers=False)

Insert rows into the model and table at index place

Parameters
  • place (int) – the index to insert the rows at

  • rows (int) – the number of rows to insert

  • index (QModelIndex()) – unused

  • renumber_headers (bool) – True if all the row headers should be renumbered, false if not (leave as default if custom row headers have been used)

removeRow(row, index=None, renumber_headers=False)

Remove a row from the model and table

Parameters
  • row (int) – the row index to remove

  • index (QModelIndex()) – unused

removeRows(place, rows, index=None, renumber_headers=False)

Remove rows from the model and table starting at index place

Parameters
  • place (int) – the index to begin removing rows at

  • rows (int) – the number of rows to remove

  • index (QModelIndex()) – unused

sortKey(myitem)

Returns the key to sort item by

Parameters

myitem (model item) – base class expects an iterable with the sort data of interest as the second item

Returns

The second item in myitem, or NO_ITEM if myitem does not have at least 2 items.

sortKeyUnsorted(myitem)

Returns the key to sort item by. In this case, it returns the cur_id of the data, allowing the sort to acheive the original data order.

Parameters

myitem (model item) – base class expects an iterable with the sort data of interest as the second item

Returns

The first item in myitem, or NO_ITEM if myitem does not have at least 2 items.

setVerticalHeadersSortable(state)

Sets vertical header labels to be sortable

Parameters

state (bool) – True if vertical headers should move with a column sort, or False if they should not (False for simple row numbers, for example)

sort(column, order=SortOrder.AscendingOrder)

This functions exists so that we can transition away from sorting directly in the model.

If you are writing a new table, this function should in called a QSortFilterProxyModel, not in the source model.

sortByColumn(column, order=SortOrder.AscendingOrder)

Sort by data by column

Parameters
  • column (int) – the index of the column to sort by

  • order (Qt.SortOrder) – Qt.AscendingOrder (0), Qt.DescendingOrder (1) or -1 for returning to original data order

sortHeaderKey(myitem)

Returns the key to sort item by, which in this case is the Header

Parameters

myitem (model item) – base class expects an iterable with the sort data of interest as the second item

Returns

The second item in myitem, or NO_ITEM if myitem does not have at least 2 items.

sortHeaderKeyUnsorted(myitem)

Returns the key to sort item by. In this case, it returns the cur_id of the data, allowing the sort to acheive the original data order.

Parameters

myitem (model item) – base class expects an iterable with the sort data of interest as the second item

Returns

The second item in myitem, or NO_ITEM if myitem does not have at least 2 items.

sortByVerticalHeader(order=SortOrder.AscendingOrder)

Sort by data by the Vertical Header values

Parameters

order (Qt.SortOrder) – Qt.AscendingOrder (0) or Qt.DescendingOrder (1)

setCellValue(row, column, value, timer=None)

Sets the data for the cell located at row, column

Parameters
  • row (int) – row the cell is in (0-indexed)

  • column (int) – column the cell is in (0-indexed)

  • value – value to store in the cell at (row, column) value can be either a structure or numerical/string data

Deprecated timer

This variable is no longer necessary. Formerly, we would perform a full scale update with 300ms timer. This caused an unnecessary race condition when updating cells. Now we implement the dataChanged signal for individual modelindexes, which should not have a performance penalty.

setHeaderData(section, orientation, label, role=ItemDataRole.DisplayRole)

Changes the label of the row or column for the table to draw

Parameters
  • section (int) – the index of the row or column header of interest

  • orientation (int) – QtCore.Qt.Horizontal (columns) or QtCore.Qt.Vertical (rows)

  • label (string) – text for the label

  • role (int) – should be 0 for the actual label text, unused - this method only sets the label text

headerData(section, orientation, role=ItemDataRole.DisplayRole)

Returns the label of the row or column for the table to draw

Parameters
  • section (int) – the index of the row or column header of interest

  • orientation (int) – 0 = horizontal (columns), 1 = vertical (rows)

  • role (int) – should be 0 for the actual label text

getCellValue(row, column)

Returns the value of the cell in the cell at row, column

Parameters
  • row (int) – the row of the cell of interest (0-indexed)

  • row – the column of the cell of interest (0-indexed)

Return type

Any

Returns

data or object stored in the model at row, column

setSize(numrows, numcolumns, reset_row_labels=True, reset_column_labels=False)

Sets the size of the table

Parameters
  • numrows (int) – the number of rows the table should have

  • numcolumns (int) – the number of columns the table should have

  • reset_row_labels (bool) – if True, all row labels are reset to simple numbers, if False, they are not

  • reset_column_labels (bool) – if True, all column labels are reset to simple numbers, if False, they are not

data(index, role=ItemDataRole.DisplayRole)

Returns the data (either Display or ToolTip) if requested.

The tooltips for structures are a different class, and handled manually by the StructureToolTip class.

Parameters
  • index (QModelIndex) – index of the cell for which data is requested

  • role (Qt.ItemDataRole) – role of the data requested. Currently only responds to Qt.ToolTipRole

clearTable()

Resets all the data in the table to None

class schrodinger.ui.qt.table.GenericViewerDelegate(tableview, tablemodel=None)

Bases: PyQt6.QtWidgets.QItemDelegate

This is the class that handles the actual drawing of data. This doesn’t handle any actual data, so you’ll have to subclass it to get it to work. For your own widget table, you should subclass this class, add any data input you need into the __init__, and reimplement the _paint class for your needs, using your data.

An example of this is the StructureReaderDelegate in this file.

__init__(tableview, tablemodel=None)
Parameters
  • tableview (ViewerTable) – Table this delegate paints to

  • tablemodel (StructureDataViewerModel) – DEPRECATED Model containing the data this delegate paints This parameter should not be used, because a delegate should only get information from a QModelIndex, not a model directly

paint(painter, option, index)

This handles the logic behind painting/not-painting when the scrollbar is being dragged.

setPaintWait(val)

Use this function to turn on/off delaying drawing of cells until the scrollbar is not being used. This may be useful in CPU intensive cell-drawing delegates.

paintWait()

Returns if we are drawing during while the scrollbar is dragged.

class schrodinger.ui.qt.table.StructureDataViewerDelegate(tableview, tablemodel=None, structure_class=None, max_scale=0.5, elide=TextElideMode.ElideRight, alignment=None)

Bases: schrodinger.ui.qt.table.GenericViewerDelegate

A table that can display both 2-D structures and data.

This Delegate should be used with the StructureDataViewerModel

Much of this class is built off of the StructureViewerDelegate class. Structures are cached for quicker drawing of the table while keeping memory use low. Data is not cached.

__init__(tableview, tablemodel=None, structure_class=None, max_scale=0.5, elide=TextElideMode.ElideRight, alignment=None)

Intialize the StructreDataViewerDelegate

Parameters
  • tableview (ViewerTable) – Table this delegate paints to

  • tablemodel (StructureDataViewerModel) – DEPRECATED Model containing the data this delegate paints This parameter should not be used, because a delegate should only get information from a QModelIndex, not a model directly

  • structure_class (class) – class (or superclass) of the objects that should be displayed in the table as 2D pictures - usually schrodinger.structure.Structure (the default)

  • max_scale (float) – restricts the maximum scale-up of 2D structure images so that very small molecules don’t look so large.

  • elide (int) – Determines where ‘…’ should occur in strings that are too large to fit in the table cell. Common values are Qt.ElideLeft, Qt.ElideRight, Qt.ElideMiddle, Qt.ElideNone

  • alignment (Qt.AlignmentFlag object) – The alignment of text in the cells.

To put a structure in a cell, store a structure_class object in that cell of the model. To put any other type of data in a cell, store that data in that cell of the model.

sizeHint(option, index, actual_column_width=False, actual_size=False, actual_row_height=False)

Returns the sizeHint for the data in the cell at index. If the data is a structure, returns the default cell size for the table.

Parameters
  • option (QStyleOptionViewItem) – the style options for this item

  • index (QModelIndex) – The index of the cell being examimed

  • actual_column_width (bool) – True if the column widths and row heights should be calculated from the width of the data as a string. Normally, sizeHint seems to return 0 for the width of text and an acceptable constant for the height, so actual_column_width is the better option.

  • actual_column_width – True if the row heights should be calculated from the height of the data as a string. Normally, sizeHint returns an acceptable constant for the row height, so this is not usually needed.

  • actual_column_width – True if the column widths should be calculated from the width of the data as a string. Normally, sizeHint seems to return 0 for the width of text.

clearCache()

Will clear all QPictures that are cached.

isStructure(object)

Returns true if object is the type given as a structure

generatePicture(struct)

Generates a 2D chemical structure of the object

If object is a chemical structure, returns the picture is a 2D rendering of that structure; None otherwise.

Parameters

struct (Object of type StructureDataViewerDelegate.structure_class) – The structure object

Return type

QPicture or None

Returns

QPicture of struct or None

paintStructure(painter, option, pic, index=None)

Draws the given QPicture (typically a 2D structure image) into the specified painter. Called from the paint() method of the delegate. Adds a bit of padding all around the cell, then passes the data on to the proper drawing routine.

Parameters
  • option – Appears to be the part of the gui that contains the cell

  • pic (QPicture) – the picture to be painted

  • index (QModelIndex) – Model index for the cell which is being painted. Not used in default implementation, but may be used in subclass implementations.

paintCell(painter, option, data)

Adds a bit of padding all around the cell, then passes the data on to the proper drawing routine.

Parameters
  • option – Appears to be the part of the gui that contains the cell

  • data (type convertable to string) – the data to be painted into the cell as a string

drawDataIntoRect(painter, data, rect, selected_brush=False)

Draws string data onto a cell

Parameters
  • painter (QtGui.QPainter) – The painter that is drawing the table

  • data (string, int, or float) – the information to be drawn on the table

  • rect (QtCore.Qrect) – The rectangle that defines the current cell of the table

class schrodinger.ui.qt.table.ToolTipFilter(view)

Bases: PyQt6.QtCore.QObject

__init__(view)
eventFilter(self, a0: Optional[QObject], a1: Optional[QEvent]) bool
class schrodinger.ui.qt.table.SEasySDTable(**table_args)

Bases: schrodinger.ui.qt.table.DataViewerTable

A simple class that automatically sets up the table/model/delegate trio for a table object

__init__(**table_args)

Creates an SEasySDTable class object. __init__ Keywords for the model, delegate and table objects can be passed in and will be passed on as appropriate.

By default, this will set up a sortable table using a proxymodel.

The sourcemodel should be used when need to add/remove data.

The proxymodel should be used when you need to reference data from the view.

class schrodinger.ui.qt.table.VStackedDataViewerTable(model, model2, scrollbar_at_bottom=True, bottom_table=None, **kwarg)

Bases: schrodinger.ui.qt.table.DataViewerTable

__init__(model, model2, scrollbar_at_bottom=True, bottom_table=None, **kwarg)

Two DataViewerTables stacked on top of each other. They share a single horizontal header and a single scrollbar. The object returned when this class is created is the upper table. The lower table is accessed via VStackedDataViewerTable.table2.

The VStackedDataViewerTable has a layout property .mylayout which is what should be added to the GUI to properly place this widget.

Parameters
  • model (QAbstractTableModel) – The model for the upper table. The typical class to use with this table is the StructureDataViewerModel class.

  • model – The model for the lower table. The typical class to use with this table is the StructureDataViewerModel class.

  • model – The class for the lower table. If not supplied, a VSubDataViewerTable object will be used.

Keyword arguments are documented in the DataViewerTable class

headerClicked(col)
enforceScrollBarPolicies()

Sets the scrollbar policies as required by the sizing policies

setColumnWidth(column, width)

Sets column to width in both tables

Parameters
  • column (int) – the index of the column to change

  • width (int) – the new width of the column

resizeRowsToContents()

Resizes all the rows according to all the resize properties

setFixedWidth(width)

Sets the viewport size to width

Parameters

width (int) – new viewport size in pixels

fitColumnToData(column, include_header=False)

Resizes column to the largest sizeHint of any of its cells. Uses the sizeHint of the delegate.

Parameters

column (int) – the column of interest

resizeEvent(event)

Called when the viewport changes size. Changes the size of any cells that need to be changed in response to this - typically because fill has been set on rows or columns.

Parameters

event (QEvent) – the event that occured

sizeHintForRow(row)

This method gives the size hints for rows - its existance means that the resizeRowsToContents() method uses this hint rather than hints from the delegate.

Parameters

row (int) – the row we want a size hint for

Return type

int

Returns

the size hint for row

class schrodinger.ui.qt.table.VSubDataViewerTable(model, master_table, **kwarg)

Bases: schrodinger.ui.qt.table.DataViewerTable

__init__(model, master_table, **kwarg)

Sub-table for a vertically stacked table.

Parameters

master_table (DataViewerTable) – the table that controls this one (the upper table in a vertically stacked pair of tables).

All other parameters are documented in DataViewerTable class.

initiateCellSizes(rows=True, columns=True)

Sets all the cells to their intial default size

Parameters
  • rows (bool) – whether to set the rows to their default height

  • columns (bool) – whether to set the columns to their default width

columnsInserted(index, start, end)

Slot that receives a signal when columns are inserted in the model. Make sure our column_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the columns inserted

  • end (int) – The ending index of the columns inserted (inclusive)

columnsRemoved(index, start, end)

Slot that receives a signal when columns are removed in the model. Make sure our column_is_ganged list stays current.

Parameters
  • index (QModelIndex) – unused

  • start (int) – The starting index of the columns removed

  • end (int) – The ending index of the columns removed (inclusive)

columnCountChanged(old_count, new_count)

Called when a column is added or deleted, and sets the columns to their initial size.

Parameters
  • old_count (int) – the old number of columns

  • new_count (int) – the num number of columns

rowResized(row, old_size, new_size)

Resizes any cells that need to be resized when a row size is changed

Parameters
  • row (int) – the row number that changed

  • old_size (int) – the old size of the row

  • new_size (int) – the new size of the row

columnResized(column, old_size, new_size)

Doesn’t do anything - let the master table take care of this

Parameters
  • column (int) – the column number that changed

  • old_size (int) – the old size of the column

  • new_size (int) – the new size of the column

fitToRows()

Fits the viewport to exactly show all the rows - master table does this

fitToColumns()

Fits the viewport to exactly show all the columns - master table does this

scrollBarChanged(orientation)

A scrollbar has changed appearance, make sure we have the proper size

fixSize()

Resize everything as the user and program desires

fitCellsToData()

Resizes rows and columns to fit the data they contain using the sizeHint from the delegate

fitRowsToData()

Resizes all the rows to fit the data they contain using the sizeHint from the delegate.

fitRowToData(row)

Resizes row to the largest sizeHint of any of its cells. Uses the sizeHint of the delegate.

Parameters

row (int) – the row of interest

fitColumnsToData()

Resizes all the columns to fit the data they contain using the sizeHint from the delegate. Master table does this.

fitColumnToData(column)

Resizes column to the largest sizeHint of any of its cells. Uses the sizeHint of the delegate. Master table does this.

Parameters

column (int) – the column of interest

resizeRowsToContents()

Resizes all the rows according to all the resize properties

resizeColumnsToContents()

Resizes all the columns according to all the resize properties. Master table does this.

resizeEvent(event)

Called when the viewport changes size. Changes the size of any cells that need to be changed in response to this - typically because fill has been set on rows or columns.

Parameters

event (QEvent) – the event that occured

sizeHintForColumn(column)

This method gives the size hints for columns - its existance means that the resizeColumnsToContents() method uses this hint rather than hints from the delegate.

Parameters

column (int) – the column we want a size hint for

Return type

int

Returns

the size hint for column

sizeHintForRow(row)

This method gives the size hints for rows - its existance means that the resizeRowsToContents() method uses this hint rather than hints from the delegate.

Parameters

row (int) – the row we want a size hint for

Return type

int

Returns

the size hint for row

class schrodinger.ui.qt.table.ExportableProxyModel

Bases: PyQt6.QtCore.QSortFilterProxyModel

A proxy model that allows data to be exported to a CSV file

exportToCsv(filename, role=ItemDataRole.DisplayRole, header_role=ItemDataRole.DisplayRole, unicode_output=False)

Export the contents of the model to a CSV file.

Parameters
  • filename (str) – The filename to write the CSV file to

  • role (int) – The data role to export for the table contents

  • header_role – The data role to export for the table headers

  • header_role – int

  • unicode_output (bool) – If True, Unicode characters are allowed. The CSV file will contain a tag (UTF-8 BOM) that allows Excel and LibreOffice to recognize the file as Unicode. (This tag will be added regardless of whether the output contains any Unicode characters.) If False, the CSV file will not contain the tag and Unicode characters will lead to an exception.

getRowData(role=ItemDataRole.DisplayRole, header_role=ItemDataRole.DisplayRole)

Extract row data from table model.

Parameters
  • role (int) – The data role to export for the table contents

  • header_role – The data role to export for the table headers

  • header_role – int

Returns

a list of row data, where the first item in the list contains the headers

Return type

list[list[object]]

schrodinger.ui.qt.table.get_row_data(model, role=ItemDataRole.DisplayRole, header_role=ItemDataRole.DisplayRole)

Extract row data from table model.

Parameters
  • model (QtCore.QAbstractItemModel) – a table model or proxy

  • role (int) – The data role to export for the table contents

  • header_role – The data role to export for the table headers

  • header_role – int

Returns

a list of lists, where each list represents the row of a table

Return type

list[list[object]]

schrodinger.ui.qt.table.write_row_data(file_path, rows, unicode_output=False)

Write row data to a CSV file.

Parameters
  • file_path (str) – the path for the .csv file

  • rows (list[list[object]]) – a list of row data lists, where the first element of the list should contain the headers

  • unicode_output (bool) – If True, Unicode characters are allowed. The CSV file will contain a tag (UTF-8 BOM) that allows Excel and LibreOffice to recognize the file as Unicode. (This tag will be added regardless of whether the output contains any Unicode characters.) If False, the CSV file will not contain the tag and Unicode characters will lead to an exception.

schrodinger.ui.qt.table.export_to_csv(model, filename, role=ItemDataRole.DisplayRole, header_role=ItemDataRole.DisplayRole, unicode_output=False)

Export the contents of the specified model to a CSV file

Parameters
  • model (PyQt5.QtCore.QAbstractItemModel) – The model (or proxy model) to export

  • filename (str) – The filename to write the CSV file to

  • role (int) – The data role to export for the table contents

  • header_role – The data role to export for the table headers

  • header_role – int

  • unicode_output (bool) – If True, Unicode characters are allowed. The CSV file will contain a tag (UTF-8 BOM) that allows Excel and LibreOffice to recognize the file as Unicode. (This tag will be added regardless of whether the output contains any Unicode characters.) If False, the CSV file will not contain the tag and Unicode characters will lead to an exception.

schrodinger.ui.qt.table.export_to_csv_with_dialog(model, parent, caption='Export', dialog_id=None, role=ItemDataRole.DisplayRole, header_role=ItemDataRole.DisplayRole, unicode_output=False)

Open a dialog prompting the user for a CSV export file and then export the contents of the specified model to the selected file.

Parameters
  • model (PyQt5.QtCore.QAbstractItemModel) – The model (or proxy model) to export

  • parent (PyQt5.QtWidgets.QWidget) – The parent widget of the export dialog

  • caption (str) – The title of the export dialog

  • dialog_id (str, int, or float) – The id for the filedialog. Dialogs with the same identifier will remember the last directory chosen by the user with any dialog of the same id and open in that directory.

  • role (int) – The data role to export for the table contents

  • header_role – The data role to export for the table headers

  • header_role – int

  • unicode_output (bool) – If True, Unicode characters are allowed. The CSV file will contain a tag (UTF-8 BOM) that allows Excel and LibreOffice to recognize the file as Unicode. (This tag will be added regardless of whether the output contains any Unicode characters.) If False, the CSV file will not contain the tag and Unicode characters will lead to an exception.

class schrodinger.ui.qt.table.PerColumnSortableTableView(parent=None)

Bases: PyQt6.QtWidgets.QTableView

A table view that prevents sorting on certain columns. Subclasses should override UNSORTABLE_COLS.

Variables

UNSORTABLE_COLS (set) – A set of columns to be made unsortable. This variable should be overridden in subclasses.

UNSORTABLE_COLS = {}
__init__(parent=None)
class schrodinger.ui.qt.table.PerColumnSortableHeaderView(unclickable_cols, parent=None)

Bases: PyQt6.QtWidgets.QHeaderView

A horizontal table header that ignores clicks on certain columns, which prevents sorting on these columns.

__init__(unclickable_cols, parent=None)
mousePressEvent(event)

If the user has pressed on an unsortable column, then make the header non-clickable so the table won’t be sorted and won’t have a new sort indicator drawn. If the user pressed on any other column, then make the header clickable so things behave normally.

Parameters

event (QtGui.QMouseEvent) – The mouse press event

mouseReleaseEvent(event)

Make the header clickable after processing the mouse release. This ensures that column headers will always respond properly to hovering, even if the user just clicked on an unclickable column.

Parameters

event (QtGui.QMouseEvent) – The mouse release event