schrodinger.ui.qt.file_selector module¶
Module containing FileSelector. The widget’s file selection can be obtained by mapping the widget to a param or alternatively by connecting a slot to the fileSelectionChanged signal.
Mapping this widget to a param will depend on whether or not
support_multiple_files is True. E.g. with support_multiple_files = False
:
class WidgetModel(parameters.CompoundParam):
input_file: str
class Widget(mappers.MapperMixin, basewidgets.BaseWidget):
def initSetUp(self):
super().initSetUp()
self.file_selector = file_selector.FileSelector(self)
def defineMappings(self):
M = self.model_class
return [(self.file_selector, M.input_file)]
Alternatively, with support_multiple_files = True
, use:
class WidgetModel(parameters.CompoundParam):
input_files: List[str]
class Widget(mappers.MapperMixin, basewidgets.BaseWidget):
def initSetUp(self):
super().initSetUp()
self.file_selector = file_selector.FileSelector(self)
def defineMappings(self):
M = self.model_class
return [(self.file_selector, M.input_files)]
To use without mapping, hook up the fileSelectionChanged signal to a
slot that calls FileSelector.getFilePath()
or getFilePaths()
depending
on which is needed.
- class schrodinger.ui.qt.file_selector.FileSelector(parent: Optional[PyQt6.QtWidgets.QWidget] = None, filter_str: str = 'All Files (*)', support_multiple_files: bool = False, initial_dir: Optional[str] = None, file_dialog_title: Optional[str] = None, id: Optional[str] = None)¶
Bases:
schrodinger.models.mappers.TargetMixin
,schrodinger.ui.qt.basewidgets.BaseWidget
Widget for showing an entry field and a browse button to let the user specify a single file or optionally multiple files.
- Variables
fileSelectionChanged (QtCore.pyqtSignal) – Signal emitted when the file selection changes.
- fileSelectionChanged¶
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: Optional[PyQt6.QtWidgets.QWidget] = None, filter_str: str = 'All Files (*)', support_multiple_files: bool = False, initial_dir: Optional[str] = None, file_dialog_title: Optional[str] = None, id: Optional[str] = None)¶
- Parameters
parent – Parent widget.
filter_str – The filter to apply to the file dialog that will open upon clicking “Browse”. Must be a valid QFileDialog filter. E.g.
Image Files (*.png *.jpeg);;Text Files (*.txt)
support_multiple_files – Whether or not to allow the user to select multiple files at once from the file dialog.
initial_dir – Initial directory. Default is CWD.
file_dialog_title – File dialog title, if it’s empty then “Select Input File / Select Input File(S) is used depending on
support_multiple_files
paramid – An identifier to remember the recently browsed directories and show the last browsed directory. Set
None
(default) to not remember any history.
- initSetUp()¶
Creates widget from
ui
and stores itui_widget
.Suggested subclass use: create and initialize subwidgets, and connect signals.
- initLayOut()¶
Create a vertical layout for the widget (
widget_layout
) and populate it with two vertical sub-layouts:main_layout
andbottom_layout
.If the user has specified the
ui
data member, insert the resultantui_widget
intomain_layout
.If the widget already has a layout defined, this method will produce a warning (but not a traceback).
main_layout
andbottom_layout
will be inserted into the existing widget layout, which will not be the same aswidget_layout
. It is therefore recommended that this mixin is used only with widgets that do not already have a layout.Suggested subclass use: create, initialize, and populate layouts.
- setFileLabelText(text: str)¶
- getFilePath() str ¶
Return the currently selected file path. Allows access to target
- Raises
RuntimeError – If this method is called when supporting multiple files.
- setFilePath(file_path: str) None ¶
Set the currently selected file path.
- Parameters
file_path – The file path to set onto this object.
- Raises
RuntimeError – If this method is called when supporting multiple files
- getFilePaths() Union[list, str] ¶
Return the currently selected file paths.
- Raises
RuntimeError – If this method is called when not supporting multiple files.
- setFilePaths(file_paths: List[str]) str ¶
Set the currently selected file paths.
- Parameters
file_paths – The file paths to set onto this object.
- Raises
RuntimeError – If this method is called when not supporting multiple files
- targetGetValue() Union[str, list] ¶
If multiple files supported, split the file paths entered into the line edit by “,”. Otherwise, return the line edit text.
- targetSetValue(value: Union[str, list])¶
Set the line edit text based for a valid
value
and emit two signals: targetValueChanged for when this widget mapped to a param, and fileSelectionChanged for when it is not.- Parameters
value – The path(s) to set to the line edit. May be single path as a string or multliple paths in a list.
- class schrodinger.ui.qt.file_selector.SlimFileSelector(parent: Optional[PyQt6.QtWidgets.QWidget] = None, filter_str: str = 'All Files (*)', support_multiple_files: bool = False, initial_dir: Optional[str] = None, file_dialog_title: Optional[str] = None, id: Optional[str] = None)¶
Bases:
schrodinger.ui.qt.file_selector.FileSelector
A file selector variant that has no label or entry field, and is made up of a single widget: a “Browse…” button. Panels that use this widget are expected to display the loaded file in a separate UI.
- initLayOut()¶
Create a vertical layout for the widget (
widget_layout
) and populate it with two vertical sub-layouts:main_layout
andbottom_layout
.If the user has specified the
ui
data member, insert the resultantui_widget
intomain_layout
.If the widget already has a layout defined, this method will produce a warning (but not a traceback).
main_layout
andbottom_layout
will be inserted into the existing widget layout, which will not be the same aswidget_layout
. It is therefore recommended that this mixin is used only with widgets that do not already have a layout.Suggested subclass use: create, initialize, and populate layouts.