psychopy.preferences
- getting and setting preferences¶You can set preferences on a per-experiment basis. For example, if you would like to use a specific audio library, but don’t want to touch your user settings in general, you can import preferences and set the option audioLib accordingly:
from psychopy import prefs
prefs.hardware['audioLib'] = ['pyo']
from psychopy import sound
!!IMPORTANT!! You must import the sound module AFTER setting the preferences. To check that you are getting what you want (don’t do this in your actual experiment):
print sound.Sound
The output should be <class 'psychopy.sound.SoundPyo'>
for pyo, or <class 'psychopy.sound.SoundPygame'>
for pygame.
You can find the names of the preferences sections and their different options here.
Preferences
¶Class for loading / saving prefs
Users can alter preferences from the dialog box in the application, by editing their user preferences file (which is what the dialog box does) or, within a script, preferences can be controlled like this:
import psychopy
psychopy.prefs.hardware['audioLib'] = ['ptb', 'pyo','pygame']
print(psychopy.prefs)
# prints the location of the user prefs file and all the current vals
Use the instance of prefs, as above, rather than the Preferences class directly if you want to affect the script that’s running.
Get the paths to various directories and files used by PsychoPy.
If the paths are not found, they are created. Usually, this is only necessary on the first run of PsychoPy. However, if the user has deleted or moved the preferences directory, this method will recreate those directories.
load user prefs, if any; don’t save to a file because doing so will break easy_install. Saving to files within the psychopy/ is fine, eg for key-bindings, but outside it (where user prefs will live) is not allowed by easy_install (security risk)
Save the various setting to the appropriate files (or discard, in some cases)