Package schrodinger :: Package utils :: Module preferences
[hide private]
[frames] | no frames]

Module preferences

A module to make the interface to the mmpref library more Pythonic. It contains a single class that can be created once and then used to access preference data.

This class also provides data type-free .get(), .set() and .getAllPreferences() methods.

Simple script usage might look like this:

   import preferences

   # Initialize the preference handler
   pref_handler = preferences.Preferences(preferences.SCRIPTS)

   # Store and get all preferences from a group specific to this script
   pref_handler.beginGroup('my_script')

   # Set the preference 'hosts' to 5
   pref_handler.set('hosts', 5)

   # Get the value of the hosts preference
   num_hosts = pref_handler.get('hosts', default=8)

   # Get the value of the jobname preference, with myjob as the default
   # name if no preference is set
   jobname = pref_handler.get('jobname', default='myjob')

Slightly more complex script usage using groups might look like this:

   import preferences

   # Initialize the preference handler
   pref_handler = preferences.Preferences(preferences.SCRIPTS)

   # Store and get all preferences from a group specific to this script
   pref_handler.beginGroup('my_script')

   # Set the preference 'hosts' to 5
   pref_handler.set('hosts', 5)

   # Switch to the group 'my_script/dialogs'
   pref_handler.beginGroup('dialogs')
   # Set the value of the 'my_script/dialogs/import_directory preference
   pref_handler.set('import_directory', directory)

   # Reset the current group to the 'my_script' group
   pref_handler.resetGroup(retain=1)

   # Get the value of the hosts preference
   num_hosts = pref_handler.get('hosts', default=8)

   # Change the value of the 'my_script/dialogs/import_directory' preference
   pref_handler.set('dialogs/import_directory', directory2)

   # Switch to the group 'my_script/dialogs'
   pref_handler.beginGroup('dialogs')

   # Get the import directory
   imdir = pref_handler.get('import_directory')
Classes [hide private]
  Preferences
A class that allows Pythonic access to the mmpref library.
Variables [hide private]
  CANVAS = pymmlibs.CANVAS
  COMBIGLIDE = pymmlibs.COMBIGLIDE
  DESMOND = pymmlibs.DESMOND
  EPIK = pymmlibs.EPIK
  IMPACT = pymmlibs.IMPACT
  JAGUAR = pymmlibs.JAGUAR
  KNIME = pymmlibs.KNIME
  MACROMODEL = pymmlibs.MACROMODEL
  MAESTRO = pymmlibs.MAESTRO
  MCPRO = pymmlibs.MCPRO
  PHASE = pymmlibs.PHASE
  PSP = pymmlibs.PSP
  PYMOL = pymmlibs.PYMOL
  QIKPROP = pymmlibs.QIKPROP
  SCRIPTS = pymmlibs.SCRIPTS
  SHARED = pymmlibs.SHARED
  WATERMAP = pymmlibs.WATERMAP
  OK = pymmlibs.MMPREF_OK
  NO_OS = pymmlibs.MMPREF_NONE
  WINDOWS = pymmlibs.MMPREF_WINDOWS
  LINUX = pymmlibs.MMPREF_LINUX
  DARWIN = pymmlibs.MMPREF_DARWIN
  OS_TYPES = [NO_OS, WINDOWS, LINUX, DARWIN]
  NO_TYPE = pymmlibs.MMPREF_TYPE_NONE
  INT = pymmlibs.MMPREF_TYPE_INT
  STRING = pymmlibs.MMPREF_TYPE_STRING
  FLOAT = pymmlibs.MMPREF_TYPE_DOUBLE
  BOOL = pymmlibs.MMPREF_TYPE_BOOL
  DATA_TYPES = [BOOL, INT, STRING, FLOAT]
  ALL_TYPES = DATA_TYPES+ [NO_TYPE]
  NODEFAULT = object()