如何使用 PyGObject 的密钥文件设置后端?
GIO(GLib 的 I/O 库)有一个使用密钥文件的 GSettings 后端。在 C 中,您可以使用 g_keyfile_settings_backend_new()
和 g_settings_new_with_backend()
创建此后端的实例,以强制使用密钥文件而不是系统注册表。但是,要执行此操作,您必须在代码中#define G_SETTINGS_ENABLE_BACKEND
,因为后端公共 API 不稳定。
我想使用 PyGObject 从 Python 执行此操作(需要明确的是,因为这个术语很令人困惑 - 这是与 GTK 3 一起使用的 GObject 自省库,而不是与 PyGTK 和 GTK 2 一起使用的 PyGObject。)我可以
>>> from gi.repository import Gio
>>> 'SettingsBackend' in dir(Gio)
True
但是,dir(Gio)
中没有与 g_keyfile_settings_backend_new()
对应的函数。如果我尝试实例化后端,
>>> Gio.SettingsBackend()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
那么有人有任何指示吗?或者也许 Python 模块不是用 G_SETTINGS_ENABLE_BACKEND
编译的,我运气不好?
GIO (GLib's I/O library) has a backend for GSettings that uses a keyfile. From C, you can create an instance of this backend in order to force use of a keyfile instead of the system registry, using g_keyfile_settings_backend_new()
and then g_settings_new_with_backend()
. However, to do this, you must #define G_SETTINGS_ENABLE_BACKEND
in your code, since the backend public API is unstable.
I would like to do this from Python, using PyGObject (just to be clear, since this term is confusing - this is the GObject introspection library that goes with GTK 3, not the PyGObject that goes with PyGTK and GTK 2.) I can do
>>> from gi.repository import Gio
>>> 'SettingsBackend' in dir(Gio)
True
However, there's no function corresponding to g_keyfile_settings_backend_new()
in dir(Gio)
. If I try instantiating a backend,
>>> Gio.SettingsBackend()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
So, does anybody have any pointers? Or maybe the Python module wasn't compiled with G_SETTINGS_ENABLE_BACKEND
and I'm out of luck?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论