Sample Plugins demonstrating retrieving/saving preferences
#1  DiapDealer 02-01-2015, 04:22 PM
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 "" and "".

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

In a nutshell:

From within the run method of
# Get preferences from json file
prefs = bk.getPrefs() # a dictionary
# Set some defaults (used only when no preferences exist yet--like first run).
prefs.defaults['lastDir'] = os.path.expanduser('~')
prefs.defaults['lastFile'] = ''
# Use a preference variable
print ('Last directory opened = ', prefs['lastDir'])
# Set/change preference variable
prefs['lastDir'] = os.path.dirname(inpath)
# Save prefs back to json file
[zip] (1.6 KB, 357 views)
[zip] (2.0 KB, 366 views)

#2  Toxaris 02-02-2015, 01:53 AM
Where will the JSON file be stored and what will it be called?

#3  DiapDealer 02-02-2015, 07:18 AM
A "plugins_prefs" directory will be created in the Sigil user preferences folder (use the "Open Preferences Location" button from the Sigil preferences dialog). Each plugin will have it's own subdirectory there (plugin name) and the <plugin name>.json file will be in that subdirectory.

The directory structure won't be there until the plugin saves its preferences for the first time, though.

Today's Posts | Search this Thread | Login | Register