Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 02-01-2015, 04:22 PM   #1
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,535
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Sample Plugins demonstrating retrieving/saving preferences

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)
Attached Files
File Type: zip PrefsExampleSimple_v0.0.2.zip (1.6 KB, 870 views)
File Type: zip PrefsExampleGroups_v0.0.2.zip (2.0 KB, 889 views)

Last edited by DiapDealer; 02-01-2015 at 08:16 PM.
DiapDealer is offline   Reply With Quote
Old 02-02-2015, 01:53 AM   #2
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
Where will the JSON file be stored and what will it be called?
Toxaris is offline   Reply With Quote
Advert
Old 02-02-2015, 07:18 AM   #3
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,535
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
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.
DiapDealer is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferences -> Saving books to disk -> Format dates as steje Library Management 4 08-15-2011 03:01 PM
Preferences -> Plugins does not exist ?? net-buoy Plugins 2 02-20-2011 04:49 PM
Preferences - Plugins, Tweaks Missing Ruffy Calibre 2 02-16-2011 01:13 AM
Journal Not Saving Writing When Moving to a New Page or Saving it eberhardt333 enTourage Archive 5 11-24-2010 12:47 AM
Found good blog demonstrating pdf ability of kindle 3 Ncage1974 Amazon Kindle 0 08-31-2010 12:54 AM


All times are GMT -4. The time now is 08:30 AM.


MobileRead.com is a privately owned, operated and funded community.