schrodinger.ui.qt.filedialog module

Schrodinger version of the QFileDialog class of the QtGui module.

Defines a FileDialog class that mimics the Maestro’s file dialogs.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.ui.qt.filedialog.use_native_file_dialog()
schrodinger.ui.qt.filedialog.filter_string_from_formats(formats=['maestro'])

Create a Qt file dialog filter string from a list of structure formats.

Parameters

formats (list of str) – List of formats, see schrodinger.utils.fileutils module for available format string constants.

Returns

Filter string

Return type

str

schrodinger.ui.qt.filedialog.filter_string_from_extensions(extensions, add_all=False)

Create a filter string for the given extensions

Parameters
  • extensions (dict) – Keys are descriptive file types (‘Image file’), values are an iterable of associated extension(s). If there is only one extension it can be given as a simple string rather than an iterable of length 1 ([‘.png’, ‘.jpg’] or just ‘-2d.png’).

  • add_all (bool) – Whether to add an additional “All files” filter

Return type

str

Returns

A string formatted for the file dialog filter keyword

class schrodinger.ui.qt.filedialog.CustomSideBarMixin

Bases: object

schrodinger.ui.qt.filedialog.get_existing_directory(parent='', caption='Choose Directory', dir=None, accept_label='Choose', file_mode=FileMode.Directory, *, show_dirs_only=True, **kwargs)

Convenience function that returns a directory name as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Parameters
  • file_mode (QFileDialog.FileMode) – What the user can select. See the PyQt documentation for QFileDialog.FileMode (currently AnyFile, ExistingFile, Directory and ExistingFiles are the options).

  • show_dirs_only (bool) – Whether we should show only directories in the file dialog. If False, both files and directories will be shown.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

schrodinger.ui.qt.filedialog.get_save_file_name(parent='', caption='Save File', dir=None, filter='All Files (*)', accept_label='Save', accept_mode=AcceptMode.AcceptSave, file_mode=FileMode.AnyFile, **kwargs)

Convenience function that returns a filename as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

schrodinger.ui.qt.filedialog.get_open_file_names(parent='', caption='Open Files', dir=None, filter='All Files (*)', accept_label='Open', file_mode=FileMode.ExistingFiles, **kwargs)

Convenience function that returns a list of filenames as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

list of str or None

Returns

list of full file pathnames selected by the user, or None if Cancel was pressed.

schrodinger.ui.qt.filedialog.get_open_file_name(parent='', caption='Open File', dir=None, filter='All Files (*)', **kwargs)

Convenience function that returns a single filename as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

schrodinger.ui.qt.filedialog.get_open_wm_file_name(parent='', dir=None, **kwargs)

Convenience function that returns a single WaterMap file as selected by the user.

See base_file_dialog for documentation.

Returns

Full pathname of the WaterMap file selected by the user or None if cancel was pressed.

Return type

str or None

schrodinger.ui.qt.filedialog.get_last_selected_directory(idval)

Return the last directory selected by a user in a dialog with the given id value. If there is no entry for the given id value, None is returned.

Parameters

idval (str, int or float) – The value passed to a filedialog using the id keyword argument

Return type

str or None

Returns

The last directory opened by a dialog with the given id value, or None if no entry exists for the id value.

schrodinger.ui.qt.filedialog.base_file_dialog(parent='', caption='Open File', dir=None, filter='All Files (*)', selectedFilter=None, options=None, default_suffix=None, default_filename=None, accept_label='Open', accept_mode=AcceptMode.AcceptOpen, file_mode=FileMode.ExistingFile, confirm=True, custom_sidebar=True, sidebar_links=None, id=None, *, show_dirs_only=False)

Convenience function that creates a highly customizable file dialog

Parameters
  • parent (qwidget) – the widget over which this dialog should be shown.

  • caption (str) – the name that appears in the titlebar of this dialog.

  • dir (str) – the initial directory displayed in this dialog. If id keyword is also supplied, subsequent calls will open in the last opened directory, which can be different from dir.

  • filter (str) – the list of filters that can be applied to this directory. the format is "Filetype1 (*.ex1);;Filetype2 (*.ex2 *.ex3)".

  • selectedFilter (str) – the filter used by default. if not specified, the first filter in the filters string is used.

  • options (qfiledialog.option enum) – see the qfiledialog.option and qfiledialog.setoptions documentation

  • default_suffix (str) – the suffix applied to a filename if the user does supply one. the suffix will have a leading ‘.’ appended to it.

  • default_filename (str) – A default base filename to use to save files in save dialogs. By default, the filename field of the dialog is blank.

  • accept_label (str) – the text on the ‘accept’ button

  • accept_mode (qfiledialog.acceptmode) – whether the dialog is in open or save mode. see the pyqt documentation for qfiledialog.acceptmode (currently acceptopen and acceptsave are the two options)

  • file_mode (qfiledialog.filemode) – what the user can select. see the pyqt documentation for qfiledialog.filemode (currently anyfile, existingfile, directory and existingfiles are the options)

  • confirm (bool) – true if a confirmation dialog should be used if the user selects an existing file, false if not

  • custom_sidebar (bool) – True if the Schrodinger sidebar should be used, False if the default PyQt sidebar should be used.

  • sidebar_links (dict) – Used to create extra links in the left-hand sidebar of the dialog. The keys of the dictionary are a unique identifier for each link (note that ‘home’ and ‘working’ are already used), and the values are tuples of the form (path, name) where path and name are str, path indicates the path the sidebar link points to, and name is the name displayed for the link.

  • id (str, int or float) – The identifier used for this dialog. 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. The dir keyword parameter can be used to override the initial directory the dialog opens in, but the chosen directory will still be stored for the next time a dialog with the same identifier opens. The default (no id given) is to not remember the chosen directory. Additionally, the id is used to keep track of recent places for the given file dialog.

  • show_dirs_only (bool) – Whether we should show only directories in the file dialog. If False, both files and directories will be shown.

Return type

list or None

Returns

list of full file pathnames selected by the user, or none if cancel was pressed. Note that all pathnames are strings, and have been converted to platform-consistent pathnames via os.path.normpath.

schrodinger.ui.qt.filedialog.fix_splitter(dialog)

Alters the splitter between the file pane and the directory pane so that both sides are visible. Because Qt saves the state of the dialog, if the users moves the splitter all the way to one side or the other, all future dialogs will show up that way, and it can be very confusing if the file side isn’t shown.

Parameters

dialog (maestro_ui.FileDialog) – The dialog to check & fix if necessary

class schrodinger.ui.qt.filedialog.FileDialog(parent=None, caption='', directory='', filter='All Files (*)', custom_sidebar=True, sidebar_links=None)

Bases: schrodinger.ui._maestro_ui.FileDialog, schrodinger.ui.qt.filedialog.CustomSideBarMixin

File browser dialog with custom sidebar.

This class name was changed from QFileDialog to FileDialog because PyQt on the Mac OS uses Mac native dialogs instead of the class object if the class name is QFileDialog.

Note: maestro_ui.FileDialog is a QFileDialog with a custom icon provider. Without this icon provider, file dialogs can be very laggy on Linux

static getExistingDirectory(parent='', caption='Choose Directory', dir=None, accept_label='Choose', file_mode=FileMode.Directory, *, show_dirs_only=True, **kwargs)

Convenience function that returns a directory name as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Parameters
  • file_mode (QFileDialog.FileMode) – What the user can select. See the PyQt documentation for QFileDialog.FileMode (currently AnyFile, ExistingFile, Directory and ExistingFiles are the options).

  • show_dirs_only (bool) – Whether we should show only directories in the file dialog. If False, both files and directories will be shown.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

static getSaveFileName(parent='', caption='Save File', dir=None, filter='All Files (*)', accept_label='Save', accept_mode=AcceptMode.AcceptSave, file_mode=FileMode.AnyFile, **kwargs)

Convenience function that returns a filename as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

static getOpenFileNames(parent='', caption='Open Files', dir=None, filter='All Files (*)', accept_label='Open', file_mode=FileMode.ExistingFiles, **kwargs)

Convenience function that returns a list of filenames as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

list of str or None

Returns

list of full file pathnames selected by the user, or None if Cancel was pressed.

static getOpenFileName(parent='', caption='Open File', dir=None, filter='All Files (*)', **kwargs)

Convenience function that returns a single filename as selected by the user

The base class base_file_dialog documents the keyword arguments for this class.

Return type

str or None

Returns

full pathname of the file selected by the user, or None if Cancel was pressed

__init__(parent=None, caption='', directory='', filter='All Files (*)', custom_sidebar=True, sidebar_links=None)
Parameters
  • parent (qwidget) – the widget over which this dialog should be shown. If not given, the Dialog will be placed by PyQt.

  • caption (str) – the name that appears in the titlebar of this dialog. If not given the title will be the default PyQt caption.

  • directory (str) – the initial directory displayed in this dialog, default is the current directory.

  • filter (str) – the list of filters that can be applied to this directory the format is "Filetype1 (*.ex1);;Filetype2 (*.ex2 *.ex3)". Default is all files.

  • custom_sidebar (bool) – True if the Schrodinger sidebar should be used, False if the default PyQt sidebar should be used.

  • sidebar_links (dict) – Use to create extra links in the left-hand sidebar of the dialog. the keys of the dictionary are a unique identifier for each link (note that ‘home’ and ‘working’ are already used), and the values are tuples of the form (path, name) where path and name are str, path indicates the path the sidebar link points to, and name is the name displayed for the link.

exec(self) int
schrodinger.ui.qt.filedialog.QFileDialog

alias of schrodinger.ui.qt.filedialog.FileDialog

class schrodinger.ui.qt.filedialog.CustomFileDialog(*args, num_free_rows=1, **kwargs)

Bases: schrodinger.ui.qt.filedialog.FileDialog

A File Dialog that has all contents below the file view (File name and File type fields) shifted down a row so that custom controls can be placed.

__init__(*args, num_free_rows=1, **kwargs)
Parameters
  • parent (qwidget) – the widget over which this dialog should be shown. If not given, the Dialog will be placed by PyQt.

  • caption (str) – the name that appears in the titlebar of this dialog. If not given the title will be the default PyQt caption.

  • directory (str) – the initial directory displayed in this dialog, default is the current directory.

  • filter (str) – the list of filters that can be applied to this directory the format is "Filetype1 (*.ex1);;Filetype2 (*.ex2 *.ex3)". Default is all files.

  • custom_sidebar (bool) – True if the Schrodinger sidebar should be used, False if the default PyQt sidebar should be used.

  • sidebar_links (dict) – Use to create extra links in the left-hand sidebar of the dialog. the keys of the dictionary are a unique identifier for each link (note that ‘home’ and ‘working’ are already used), and the values are tuples of the form (path, name) where path and name are str, path indicates the path the sidebar link points to, and name is the name displayed for the link.

Return type

dict

Returns

dictionary of attached drives. Keys are text names of the drive, values are tuples of (path, text name).

class schrodinger.ui.qt.filedialog.OpenDirAsFileDialog(parent=None, caption='Open Project', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_MAESTRO, label='Project:')

Bases: schrodinger.ui._maestro_ui.MM_QProjS

A file dialog tailored to allow the user to “open” directories such as projects or phase databases as if they were files. Usage:

dlg = OpenDirAsFileDialog()
project_path = dlg.getFilename()
if project_path:
    # User accepted the dialog with a directory selection.
__init__(parent=None, caption='Open Project', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_MAESTRO, label='Project:')
Parameters
  • parent (QWidget) – Dialog parent.

  • caption (str) – Dialog

  • directory (str) – Directory to open in the dialog.

  • accept (str) – Text for dialog accept button.

  • filter (Directory filter (MM_QPROJS_MAESTRO, MM_QPROJS_CANVAS, MM_QPROJS_PHDB).) – MM_QProjS.MMENUM_QPROJS_APP

  • label (str) – Text for dialog file name label.

getFilename()

Open the dialog, allow the user to choose the directory and return the path. :return: Path to directory if dialog accepted else None. :rtype: str or NoneType.

class schrodinger.ui.qt.filedialog.ProjectOpenDialog(parent=None, caption='Open Project', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_MAESTRO, label='Project:')

Bases: schrodinger.ui.qt.filedialog.OpenDirAsFileDialog

A file dialog tailored to opening Projects.

__init__(parent=None, caption='Open Project', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_MAESTRO, label='Project:')
Parameters
  • parent (QWidget) – Dialog parent.

  • caption (str) – Dialog

  • directory (str) – Directory to open in the dialog.

  • accept (str) – Text for dialog accept button.

  • filter (Directory filter (MM_QPROJS_MAESTRO, MM_QPROJS_CANVAS, MM_QPROJS_PHDB).) – MM_QProjS.MMENUM_QPROJS_APP

  • label (str) – Text for dialog file name label.

schrodinger.ui.qt.filedialog.get_existing_project_name(*args, **kwargs)

Convenience function to open a Open Project dialog and return the path the user selects.

Parameters are passed to and documented in the ProjectOpenDialog class.

Parameters

id (str, int or float) – The identifier used for this dialog. 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. The dir keyword parameter can be used to override the initial directory the dialog opens in, but the chosen directory will still be stored for the next time a dialog with the same identifier opens. The default (no id given) is to not remember the chosen directory.

Return type

str or None

Returns

The path to the project if the user selects one, or None if the user cancels the dialog

class schrodinger.ui.qt.filedialog.PhaseDatabaseOpenDialog(parent=None, caption='Open Phase database', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_PHDB, label='Project:')

Bases: schrodinger.ui.qt.filedialog.OpenDirAsFileDialog

A file dialog for opening phase databases.

__init__(parent=None, caption='Open Phase database', directory='.', accept='Open', filter=MMENUM_QPROJS_APP.MM_QPROJS_PHDB, label='Project:')
Parameters
  • parent (QWidget) – Dialog parent.

  • caption (str) – Dialog

  • directory (str) – Directory to open in the dialog.

  • accept (str) – Text for dialog accept button.

  • filter (Directory filter (MM_QPROJS_MAESTRO, MM_QPROJS_CANVAS, MM_QPROJS_PHDB).) – MM_QProjS.MMENUM_QPROJS_APP

  • label (str) – Text for dialog file name label.

schrodinger.ui.qt.filedialog.get_existing_phase_database(*args, **kwargs)

Convenience function to open an Open Project dialog and return the path the user selects.

All parameters are passed to and documented in the PhaseDatabaseOpenDialog class.

Parameters

id (str, int or float) – The identifier used for this dialog. 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. The dir keyword parameter can be used to override the initial directory the dialog opens in, but the chosen directory will still be stored for the next time a dialog with the same identifier opens. The default (no id given) is to not remember the chosen directory.

Return type

str or None

Returns

The path to the project if the user selects one, or None if the user cancels the dialog