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.general['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):
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.
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.general['audioLib'] = ['pyo','pygame'] print(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.
Load the user prefs and the application data
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)
removes userPrefs.cfg, does not touch appData.cfg
result = result of validate
Save the various setting to the appropriate files (or discard, in some cases)
Validate and save the various setting to the appropriate files (or discard, in some cases)
Validate (user) preferences and reset invalid settings to defaults