Package schrodinger :: Package ui :: Package qt :: Module filedialog
[hide private]
[frames] | no frames]

Module filedialog

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.

Classes [hide private]
  CustomSideBarMixin
  FileDialog
File browser dialog with custom sidebar.
  OpenDirAsFileDialog
A file dialog tailored to allow the user to "open" directories such as projects or phase databases as if they were files.
  PhaseDatabaseIconProvider
Class to ensure that projects get the proper icon in the file open dialog, and also are labeled as type "Project"
  PhaseDatabaseOpenDialog
A file dialog tailored to opening Phase databases.
  ProjectOpenDialog
A file dialog tailored to opening Projects.
  QFileDialog
File browser dialog with custom sidebar.
  _CustomIconProvider
Class to ensure that Schrodinger file (and directory) types get a proper icon in the QFileDialog.
Functions [hide private]
list
_add_extension_if_necessary(files, filter)
Attach the first extension in filter to each filename in files that does not already have an extension
 
_get_standard_loc(standard_loc)
Get the specified location in a way that works on Qt4 and Qt5.
list or None
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=0, file_mode=1, confirm=True, custom_sidebar=True, sidebar_links=None, id=None)
Convenience function that creates a highly customizable file dialog
str
filter_string_from_formats(formats=['maestro'])
Create a Qt file dialog filter string from a list of structure formats.
 
fix_splitter(dialog)
Alters the splitter between the file pane and the directory pane so that both sides are visible.
str or None
get_existing_directory(parent='', caption='Choose Directory', dir=None, accept_label='Choose', file_mode=4, **kwargs)
Convenience function that returns a directory name as selected by the user
str or None
get_existing_phase_database(*args, **kwargs)
Convenience function to open an Open Project dialog and return the path the user selects.
str or None
get_existing_project_name(*args, **kwargs)
Convenience function to open a Open Project dialog and return the path the user selects.
str or None
get_last_selected_directory(idval)
Return the last directory selected by a user in a dialog with the given id value.
str or None
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
list of str or None
get_open_file_names(parent='', caption='Open Files', dir=None, filter='All Files (*)', accept_label='Open', file_mode=3, **kwargs)
Convenience function that returns a list of filenames as selected by the user
str or None
get_open_wm_file_name(parent='', dir=None, **kwargs)
Convenience function that returns a single WaterMap file as selected by the user.
str or None
get_save_file_name(parent='', caption='Save File', dir=None, filter='All Files (*)', accept_label='Save', accept_mode=1, file_mode=0, **kwargs)
Convenience function that returns a filename as selected by the user
dict
get_windows_drive_sidebar_links()
Returns: dictionary of attached drives.
bool
has_phasedb_ending(path)
Detect whether path ends in one of the recognized valid endings that indicate a Phase database.
bool
has_project_ending(path)
Detect whether path ends in one of the recognized valid endings that indicate a project
Variables [hide private]
  IS_PYQT4 = True
hash(x)
  MAESTRO_FILTER = 'Maestro files (*.bld *.cms *.cms.gz *.cmsgz ...
  MAESTRO_SD_FILTER = 'All supported files (*.bld *.cms *.cms.gz...
  PDB_FILTER = 'PDB files (*.pdb *.ent *.pdb.gz *.pdbgz *.ent.gz...
  PHASEDB_FILTER = 'Phase Databases (*_phasedb *.phdb)'
  PHASEDB_SUFFIXES = ['_phasedb', '.phdb']
  PROJECTS_FILTER = 'Projects (*.prj *.prjzip *.prj.zip)'
  PROJECT_SUFFIXES = ['.prj', '.prjzip', '.prj.zip']
  SD_FILTER = 'SD files (*.sd *.sdf *.mol *.sdf.gz *.sdfgz *.sd....
  __package__ = 'schrodinger.ui.qt'
  _last_selected_directory = {}
  _last_selected_filter = None
hash(x)
  x = '.phdb'
Function Details [hide private]

_add_extension_if_necessary(files, filter)

 

Attach the first extension in filter to each filename in files that does not already have an extension

Parameters:
  • files (list) - list of filenames
  • filter (str) - the list of filters that can be applied. The first extension is used. The format is "filetype1 (*.ex1);; filetype2 (*.ex2, *.ex3)". examples:
    • "image files (*.png *.jpg *.bmp)"
    • "images (*.png *.xpm *.jpg);;text files (*.txt);;all files (*)"
Returns: list
list of filenames in the same order as files. Each item in the returned list is unchanged if it had an extension, or has an extension added to it if it did not. The added extension is the first one in the selected filter list of dialog.

_get_standard_loc(standard_loc)

 

Get the specified location in a way that works on Qt4 and Qt5. Once we've fully switched to Qt5, this code can be inlined and this function can be removed.

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=0, file_mode=1, confirm=True, custom_sidebar=True, sidebar_links=None, id=None)

 

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
  • filter (str) - the list of filters that can be applied to this directory. the format is "filetype1 (*.ex1);; filetype2 (*.ex2, *.ex3)". examples:
    • "image files (*.png *.jpg *.bmp)"
    • "images (*.png *.xpm *.jpg);;text files (*.txt);;all files (*)"
  • 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.
Returns: list or None
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.

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: str
Filter string

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:

get_existing_directory(parent='', caption='Choose Directory', dir=None, accept_label='Choose', file_mode=4, **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). Note that despite what the PyQt documentation states, it appears that QFileDialog.DirectoryOnly is needed to only display directores - it is not sufficient to use QFileDialog.Directory and setOptions(ShowDirsOnly). Use QFileDialog.Directory to have the dialog also show the files in each directory.
Returns: str or None
full pathname of the file selected by the user, or None if Cancel was pressed

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)
Returns: str or None
The path to the project if the user selects one, or None if the user cancels the dialog

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)
Returns: str or None
The path to the project if the user selects one, or None if the user cancels the dialog

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
Returns: str or None
The last directory opened by a dialog with the given id value, or None if no entry exists for the id value.

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.

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

get_open_file_names(parent='', caption='Open Files', dir=None, filter='All Files (*)', accept_label='Open', file_mode=3, **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.

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

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: str or None
Full pathname of the WaterMap file selected by the user or None if cancel was pressed.

get_save_file_name(parent='', caption='Save File', dir=None, filter='All Files (*)', accept_label='Save', accept_mode=1, file_mode=0, **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.

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

get_windows_drive_sidebar_links()

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

has_phasedb_ending(path)

 

Detect whether path ends in one of the recognized valid endings that indicate a Phase database.

Parameters:
  • path (str) - Path to a file or directory that should be checked to see if it is a Phase database.
Returns: bool
True if path points to a Phase database, False if not

has_project_ending(path)

 

Detect whether path ends in one of the recognized valid endings that indicate a project

Parameters:
  • path (str) - Path to a file or directory that should be checked to see if it is a project
Returns: bool
True if path points to a project, False if not

Variables Details [hide private]

MAESTRO_FILTER

Value:
'Maestro files (*.bld *.cms *.cms.gz *.cmsgz *.mae *.mae.gz *.maegz)'

MAESTRO_SD_FILTER

Value:
'All supported files (*.bld *.cms *.cms.gz *.cmsgz *.mae *.mae.gz *.ma\
egz *.sd *.sdf *.mol *.sdf.gz *.sdfgz *.sd.gz *.mol.gz);;Maestro files\
 (*.bld *.cms *.cms.gz *.cmsgz *.mae *.mae.gz *.maegz);;SD files (*.sd\
 *.sdf *.mol *.sdf.gz *.sdfgz *.sd.gz *.mol.gz)'

PDB_FILTER

Value:
'PDB files (*.pdb *.ent *.pdb.gz *.pdbgz *.ent.gz *.entgz)'

SD_FILTER

Value:
'SD files (*.sd *.sdf *.mol *.sdf.gz *.sdfgz *.sd.gz *.mol.gz)'