Handling Preferences #
How to retrieve and update user preferences.
user.cfg XML file contains a hierarchical list of all the preferences used by FreeCAD.
Each module has its own branch of the hierarchy starting under Preferences/Mod.
There are two ways of updating preferences:
- the Tools > Edit parameters menu entry
- this is a general purpose preference editor that can change any parameter in the hierarchy. This editor does not perform any validation or suggest valid values.
- custom preference dialogs
- a sample dialog
- these dialogs use custom FreeCAD widgets to update preference values. Each preference widget has two special properties: prefEntry and prefPath. prefPath is the identifies the branch of the preference hierarchy and prefEntry identifies the leaf node to be updated.
- two entries are needed in the dialog for each preference value - onSave() in saveSettings and onRestore() in loadSettings().
Preference values are retrieved (and sometimes set) using functions from Base/Parameter.cpp.
Good examples of retrieving parameters can be found in:
- Python: get_param() in /Mod/Draft/draftutils/util.py
- C++: various methods in /Mod/TechDraw/App/Preferences.cpp