How should a Gnome applet store its configuration data?

流过昼夜 提交于 2020-01-12 21:24:08

问题


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.


回答1:


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.




回答2:


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")


来源:https://stackoverflow.com/questions/3018287/how-should-a-gnome-applet-store-its-configuration-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!