schrodinger.ui.qt.filter_list module

Module for widgets that allow for dynamic filtering of a list.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.ui.qt.filter_list.FilterCheckBox(label_text, filter_func, parent=None, on_by_default=False)

Bases: PyQt6.QtWidgets.QCheckBox

A checkbox that applies a predefined filter to items in a QtWidgets.QListWidget.

__init__(label_text, filter_func, parent=None, on_by_default=False)
Parameters
  • label_text (str) – Label text to be shown for this checkbox.

  • filter_func (callable) – Filter function to be applied to the list items.

  • parent (QtWidgets.QWidget) – Parent widget.

  • on_by_default (bool) – Whether the filter is on by default.

setDefault()

Reset the checkbox to it’s default state.

applyFilter(list_items)

Apply the filter for this checkbox to the specified list items. Note that items will not be unhidden, so any allowed items should be explicitly unhidden before being passed here.

Parameters

list_items (iterable(QtWidgets.QListWidgetItem)) – List items to be filtered

class schrodinger.ui.qt.filter_list.PredefinedFiltersPopUp(parent, filter_cbs, toggle_filtering_text=None, match_msg=None, no_match_msg=None)

Bases: schrodinger.ui.qt.appframework2.settings.SettingsMixin, schrodinger.ui.qt.pop_up_widgets.PopUp

Class for a popup containing predefined filter checkboxes.

__init__(parent, filter_cbs, toggle_filtering_text=None, match_msg=None, no_match_msg=None)
Parameters
  • parent (QtWidgets.QWidget) – Parent widget.

  • filter_cbs (iterable(FilterCheckBox)) – tuple of filter checkboxes for this popup.

  • toggle_filtering_text (str) – Text to show for a group box checkbox to turn filtering on and off. If not specified, no group box checkbox will be shown.

  • match_msg (str) – Label message to display when items match

  • no_match_msg (str) – Text to show when no items match filters

setup()

Set up the filters and lay them out in the pop up widget.

hasActiveFilters()

Return whether there are currently active filters.

Returns

Whether there are active filters.

Return type

bool

applyFilters(list_items)

Apply all active filters to the specified list items. Note that this function will not unhide any items, so all allowed items should be explicitly shown before being passed here.

Parameters

list_items (iterable(QtWidgets.QListWidgetItem)) – List items to be filtered.

clearFilters()

Clear all predefined filters.

getSettings(**kwargs)

Get the current filter settings.

Returns

Map of the current filter settings

Return type

dict

applySettings(settings)

Apply the specified settings to the filters.

Parameters

settings (dict) – Settings to be applied.

class schrodinger.ui.qt.filter_list.FilterListPopUp(parent, list_items=(), filter_cbs=(), toggle_filtering_text=None, match_msg=None, no_match_msg=None)

Bases: schrodinger.ui.qt.appframework2.settings.SettingsMixin, schrodinger.ui.qt.pop_up_widgets.PopUp

This class implements a group of widgets that can be used to dynamically filter the contents of a list in a popup that can be associated with another widget.

Variables

filtersChanged – Signal emitted when filters are toggled. emits a dict of current filter settings.

filtersChanged

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__(parent, list_items=(), filter_cbs=(), toggle_filtering_text=None, match_msg=None, no_match_msg=None)
Parameters
  • parent (QtWidgets.QWidget) – Parent widget.

  • list_items (iterable(QtWidget.QListWidgetItem)) – Items to populate in the filtered list

  • filter_cbs (tuple(FilterCheckBox)) – tuple of filter checkboxes for this popup.

  • toggle_filtering_text (str) – Text to show for a group box checkbox to turn filtering on and off. If not specified, no group box checkbox will be shown.

  • match_msg (str) – Label message to display when items match

  • no_match_msg (str) – Text to show when no items match filters

setup()

Sets up the widget’s UI and connections.

applyFilters()

Apply the current filter text and predefined filters to the list contents.

clearFilters()

Clear all item filters.

isItemHidden(item_txt)
Returns

True if the item with the specified text is in the list and hidden, False otherwise.

Return type

bool

onDataChanged()

Emit the dataChanged signal when a new item is selected.

onReturnPressed()

Check if an item has been selected and, if so, set that item as the current item. If a current item has been set, hide the popup.

keyPressEvent(event)

Close the popup if enter/return is pressed.

See Qt documentation for argument documentation.

subWidgetHasFocus()

Return True if any widget within the pop up has focus. False otherwise.

Note

Note that combo boxes have various list view and frame children that can receive focus (and which of these widgets can receive focus varies by OS). As a result, we check the full ancestry of the focus widget here rather than just checking it’s parent. Also note that we can’t use Qt’s isAncestorOf() function to check ancestry, since combo box drop downs are considered to be their own window and isAncestorOf() requires ancestors to be part of the same window.

class schrodinger.ui.qt.filter_list.ToolButtonWithFilterListPopUp(parent)

Bases: schrodinger.ui.qt.pop_up_widgets.ToolButtonWithPopUp

Custom toolbutton with a filter list popup.

Variables

filtersChanged – Signal emitted when filters are toggled. emits a dict of current filter settings.

POP_UP_CLASS

alias of schrodinger.ui.qt.filter_list.FilterListPopUp

filtersChanged

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__(parent)
Parameters
  • parent (PyQt5.QtWidgets.QWidget) – The Qt parent widget

  • pop_up_class (type) – The class of the pop up widget. Should be a subclass of PopUp.

  • arrow_type (Qt.ArrowType) – Type of arrow to display in the button

  • text (str) – Text to set for this button. If not specified, only an icon will be shown.

setPopUp(pop_up)

Set the pop up widget to the specified pop up widget instance.

isItemHidden(item_txt)

Return whether the specified item text is hidden.

Parameters

item_txt (str) – Item text to check

Returns

True if item is n list and is hidden, False otherwise

Return type

bool

clearFilters()

Clear all pop up filters

getSettings(**kwargs)

Get the current filter settings.

Returns

Map of the current filter settings

Return type

dict

applySettings(settings)

Apply the specified settings to the filters.

Parameters

settings (dict) – Settings to be applied.