Source code for schrodinger.ui.qt.forcefield.pathselectorwidget

from schrodinger.ui.qt import filedialog
from schrodinger.ui.qt.recent_completer import BrowsePlaceholderRecentCombo
from schrodinger.Qt import QtCore


[docs]class PathSelectorWidget(BrowsePlaceholderRecentCombo): """ This class provides widget to add locations with 'Browse...' as the last item. Clicking on it will allow user to add more directories from directory selector. Note: if user selects/adds some directory, it will be moved to top of list. :cvar newLocationSelected: signal indication that new path is added and selected. :vartype newLocationSelected: QtCore.pyqtSignal """ newLocationSelected = QtCore.pyqtSignal(str)
[docs] def __init__(self, parent, suggestion_limit): """ :param suggestion_limit: It is count of maximum items that can be displayed in the widget. """ super().__init__(parent, suggestion_limit=suggestion_limit) self.currentTextChanged.connect(self._onLocationItemChanged)
def _onLocationItemChanged(self, current_item): """ Function called when currentText is changed in widget """ last_selected_item = self.getTopLocationItem() if not current_item or last_selected_item == current_item: return new_location_item = self._browseNewLocationItem( ) if current_item == self.model().BROWSE else current_item if not new_location_item: self.setCurrentText(last_selected_item) else: self.addAndSelectLocationItem(new_location_item) def _browseNewLocationItem(self): """ Opens existing directory selector to allow user to select new directory. :rtype : str :return : new directory if user selected any, else returns last selected item. """ return filedialog.get_existing_directory( parent=self, caption="Custom Parameters Location", dir=self.getTopLocationItem(), accept_label='Select')
[docs] def addAndSelectLocationItem(self, location_item): """ Adds location item to the list and selects it. :param location_item: name of item to be added. """ self.addSuggestion(location_item) self.setCurrentText(location_item) self.newLocationSelected.emit(location_item)
[docs] def getLocationItems(self): """ Returns list of location items present in list. :rtype: list[str] :return: list of user added items. """ return self.model().stringList()
[docs] def getTopLocationItem(self): """ Returns empty string if no item is present, top item in list otherwise. :rtype: str :return: Combobox first item. """ item_list = self.getLocationItems() return item_list[0] if item_list else ''