Source code for schrodinger.ui.qt.filter_dialog

"""
Filter dialog for the FEP+ and Enumeration GUIs.
"""

from schrodinger.ui.qt.appframework2 import af2
from schrodinger.ui.qt.appframework2 import settings as af2_settings
from schrodinger.ui.qt.filter_dialog_dir import filter_widgets

from . import filter_dialog_ui

NO_NAME_ERROR = "Please specify a name for this filter."
UNIQUE_NAME_ERROR = "Please specify a unique name for this filter."
NO_FILTER_ERROR = "Please specify at least one property to filter by."
NO_CHECKED_ERROR = "At least one property filter should be checked."

DEFAULT_TITLE = 'Filter by Properties'


[docs]class FilterDialog(af2_settings.BaseOptionsPanel): """ Dialog allowing the user to select filter criteria - for displaying only ligands that match the specified rules. """
[docs] def __init__(self, parent=None, dialog_title=DEFAULT_TITLE, use_dual_slider=True, show_matches=True, show_filter_name=True, allow_empty_filter=False, **kwargs): """ Class initializer. :param parent: parent widget of this dialog. :type parent: QWidget :param use_dual_slider: indicates whether dual slider widget should be shown for 'between (inclusive)' type. :type use_dual_slider: bool :param show_matches: determines whether label showing number of matches should be shown. We need to hide it when using filter dialog and no structures are available yet. For example, Custom R-group Enumeration GUI. :type show_matches: bool :param show_filter_name: determines whether filter name field should be shown. It is needed for filters that can be saved in the preferences (FEP+) and should be hidden for filters that can not be saved. :type show_filter_name: bool :param allow_empty_filter: whether to allow the user to save the filter even if no filter criteria are defined :type allow_empty_filter: bool """ self.dialog_title = dialog_title self.show_matches = show_matches self.show_filter_name = show_filter_name self.use_dual_slider = use_dual_slider self._allow_empty_filter = allow_empty_filter super(FilterDialog, self).__init__(parent=parent, **kwargs)
[docs] def setPanelOptions(self): """ Set the panel options for this dialog. """ super(FilterDialog, self).setPanelOptions() self.title = self.dialog_title self.ui = filter_dialog_ui.Ui_Dialog() self.help_topic = 'R_GROUP_FILTER'
[docs] def setup(self): """ See base class for documentation. """ super(FilterDialog, self).setup() self.ui.filter_frame.setVisible(self.show_filter_name) self.filter_widget = filter_widgets.FilterWidget( use_dual_slider=self.use_dual_slider, show_matches=self.show_matches) self.ui.filter_layout.addWidget(self.filter_widget)
[docs] def getFilterName(self): """ Returns name of this filter. :return: filter name :rtype: str """ return self.ui.filter_name_le.text()
[docs] def display(self, filter_obj, props_for_ligs, used_filter_names=None): """ Open the dialog for the given filter object, properties present in the ligands, and filter names that are already used. Returns True if OK was pressed and filter_obj was updated; False otherwise. :param filter_obj: filter object :type filter_obj: filter_core.Filter :param props_for_ligs: list of property dictionaries use to construct filters for this dialog :type props_for_ligs: list(dict(str, object)) :param used_filter_names: list of used filter names, if applicable :type used_filter_names: list(str) or None :return: returns True if filter was applied and False if user clicked 'Cancel' button. :rtype: bool """ used_filter_names = used_filter_names or [] self.ui.filter_name_le.setText(filter_obj.name) self.used_filter_names = used_filter_names self.filter_widget.updateWidget(filter_obj, props_for_ligs) if self.run(): # OK pressed filter_obj.name = self.getFilterName() self.filter_widget.updateFilterObj() return True else: # Cancel pressed return False
@af2.validator() def validateSettings(self): """ Do not allow the user to accept the dialog if anything is invalid. """ name = self.getFilterName() if not name.strip(): return False, NO_NAME_ERROR if name != self.filter_widget.filter_obj.name and \ name in self.used_filter_names: # If renaming the filter, ensure that a unique name is used. return False, UNIQUE_NAME_ERROR return True