Saving settings for extensions

Geert Janssens geert.gnucash at kobaltwit.be
Sat May 23 05:16:06 EDT 2015


On Monday 11 May 2015 10:29:17 Christoph Holtermann wrote:
> Dear developers,
> 
> I have been wondering for some while if it is possible
> for extensions like in the python bindings to save settings
> in the place gnucash does.
> 
> regards,
> 
> Christoph Holtermann

Hi Christoph,

That's a short question which requires a long answer.

To start there are several places where gnucash stores settings 
depending on the scope of these settings.

Settings that affect all the user's books are stored via the gsettings 
mechanism (which has different backends depending on the OS).

Settings that are related to a book are stored in a file in 
.gnucash/books. These settings mostly save gui state so as such they may 
be of less interest.

The gsettings interface is wrapped via the gnc_prefs api in gnucash. The 
gnc_prefs api is described here:
http://code.gnucash.org/docs/HEAD/group__Preferences.html

Via this api it should be relatively easy to read or modify any setting 
that is defined in the gnucash code.

And there's the catch. Only settings that are defined can easily be 
manipulated. That's a limitation of the underlying gsettings interface.

Nothing however is stopping you from defining your own set of 
preferences in an extension written using the python bindings. It will 
likely be more complicated to write such an extension, mainly due to the 
way gsettings works.

New preference options are defined as a "schema" in an xml file. You 
will find several such schema files in the gnucash source tree in the 
various gchemas directories (for example: src/gnome-utils/gschemas).

This schema file then has to be compiled and installed in a place where 
the gsettings library can find it. If you don't want to or can't install 
the compiled schema in the system libraries, you can also install it in 
a non-standard location and set the XDG_DATA_DIRS environment variable 
properly so your schema file will be found. GnuCash uses this mechanism 
itself when it's configured to be installed in a directory other than 
the default (/usr/bin). An example can be found in 
$PREFIX/etc/gnucash/environment in such a case. Note that this file is 
not using shell script notation, so if you want to set the environment 
variable, you will have to transliterate the example (; -> : and adding 
$ signs for inclusion of other environment variables).

So depending on the build system surrounding your python extension, 
wanting to use the gnc preferences system suddenly adds quite a bit of 
overhead. I have no idea if gsettings has some useful python bindings 
itself that may simplify this.

The above is a rough overview only. If you need more details or 
specifics feel free to ask.

Regards,

Geert


More information about the gnucash-devel mailing list