Gnome 小程序应该如何存储其配置数据?

发布于 2024-09-05 22:02:25 字数 208 浏览 1 评论 0原文

我有一个用 Python 编写的 Gnome 小程序。为了保存配置数据/设置,它创建一个文件 ~/.appname

但是,这会阻止将小程序的多个实例添加到面板中,因为每个实例都不能有自己的设置。

如何以允许每个实例拥有自己独特设置的方式存储设置?

更新:我特别想知道如何存储每个实例的设置。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我太投入 2024-09-12 22:02:25

小程序的推荐方法是使用 GConf 来存储首选项并为每个实例使用一个密钥,以便您可以存储单独的设置。来自面板小程序 GConf 实用程序:

Applet 通常定义一组
使用模式文件的首选项和
panel_applet_add_preferences()。这样的
偏好仅适用于
单独的小程序实例。为了
例如,您可以添加两个时钟小程序
到面板并配置它们
不同。

为了使首选项仅
适用于单个小程序,每个小程序
必须有一个单独的 GConf 密钥
这些偏好中的每一个。方法
下面的描述提供了方便
常见 GConfClient 的包装
函数并对其进行操作
每个小程序的密钥。

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.

奢华的一滴泪 2024-09-12 22:02:25

带小程序的 Python 示例:

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

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文