Because storing preferences can be important for a Plugin, I have designed a new python launcher preferences class and integrated it right into the *container classes, so persistent preferences storage is easily available for all plugins.
To illustrate how to create and use these settings, I've designed two simple plugins that demonstrate how the interface should be used.
See the attached "PrefsExampleGroups_v0.0.2.zip" and "PrefsExampleSimple_v0.0.2.zip".
Important
In order to use this new preferences interface, you will need to be using
Sigil v0.8.3 or greater.
Install them, use them, and inspect the code in plugin.py
In a nutshell:
From within the run method of plugin.py
Code:
# Get preferences from json file
prefs = bk.getPrefs() # a dictionary
Code:
# Set some defaults (used only when no preferences exist yet--like first run).
prefs.defaults['lastDir'] = os.path.expanduser('~')
prefs.defaults['lastFile'] = ''
Code:
# Use a preference variable
print ('Last directory opened = ', prefs['lastDir'])
Code:
# Set/change preference variable
prefs['lastDir'] = os.path.dirname(inpath)
Code:
# Save prefs back to json file
bk.savePrefs(prefs)