Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should a Gnome applet store its configuration data?

I have a Gnome applet written in Python. In order to save configuration data/settings, it creates a file ~/.appname.

However, this prevents multiple instances of the applet from being added to the panel because each cannot have its own settings.

How can I store the settings in a way that allows each instance to have its own unique settings?

Update: I specifically want to know how to store settings per instance.

like image 582
Nathan Osman Avatar asked Jun 10 '10 20:06

Nathan Osman


2 Answers

The recommend way for an applet would be to use GConf to store preferences and to use one key per instance so that you can store individual settings. From Panel Applet GConf Utilities:

Applets typically define a set of preferences using a schemas file and panel_applet_add_preferences(). Such preferences apply only to an individual applet instance. For example, you may add two clock applets to the panel and configure them differently.

In order for the preferences to only apply to a single applet, each applet must have a seperate GConf key for each of these preferences. The methods described below provide convient wrappers around the usual GConfClient functions and operate on these per-applet keys.

like image 78
Pascal Thivent Avatar answered Nov 12 '22 02:11

Pascal Thivent


Python example with the applet:

import gconf
client = gconf.client_get_default()
gconf_root_key = applet.get_preferences_key()

client.set_string( gconf_root_key + "/myvar", "foobar")
myvar = client.get_string( gconf_root_key + "/myvar")
like image 36
Joonas Avatar answered Nov 12 '22 02:11

Joonas