Reading and writing defaults ↩
Application defaults
RoboFont’s default settings can be edited manually using the Preferences Window or the Preferences Editor.
The application defaults can also be edited with a script:
from mojo.UI import getDefault, setDefault, preferencesChanged
# get current value
value = getDefault("glyphViewGridx")
print(f"previous value: {value}")
# set a new value
setDefault("glyphViewGridx", 40)
value = getDefault("glyphViewGridx")
print(f"new value: {value}")
# tell the app that preferences were changed
preferencesChanged()
To find out how a default value is named, look at the keys in the Preferences Editor.
Validation
Values can be validated when saving preferences with setDefault
:
setDefault("glyphViewGridx", 40, validate=True)
Use validation to make sure that no bad values are stored in the defaults.
Extension defaults
Your own tools and extensions can also store defaults using a separate API.
Value names (keys) should be created using the reverse domain name scheme.
from mojo.extensions import getExtensionDefault, setExtensionDefault
key = 'com.mydomain.mytool.avalue'
value = getExtensionDefault(key, fallback=10)
print(f"previous value: {value}")
setExtensionDefault(key, 50)
value = getExtensionDefault(key)
print(f"new value: {value}")