Aid*_*ell 10
Python GConf,还可以在你的发行版包repo中查看python-gconf和/或gnome-python-gconf等软件包:
的/ usr /共享/ DOC /蟒-的gconf /示例/
或者在http://svn.gnome.org/viewvc/gnome-python/trunk/examples/gconf/上浏览svn以获取示例.
在Fedora12(我的发行版)上,它被称为gnome-python2-gconf-2.28.0-1.fc12.x86_64.rpm,但它可能在一个通用的gnome-python2包中.
Python中GConf键编辑(背景墙纸)的一个示例:
#! /usr/bin/python
import gtk
import gtk.glade
import gconf
class GConfExample:
def __init__(self):
self.client = gconf.client_get_default()
def get_key(self, key):
return client.get_string(key)
def set_key(self, key, val):
client.set_string(key, str(val))
Run Code Online (Sandbox Code Playgroud)
找到http://therning.org/magnus/archives/57,我修剪了GTK的东西.当然,这会使一些好的getitem和setitem用法来映射例如:
mygconf['/path/to/key'];
Run Code Online (Sandbox Code Playgroud)
此处还有一些关于使用API的好信息.当然,我的例子很差,但说明了API的简单性.以下是更多方法:
foo = self.gconf_client.get_string("/path/to/my/config/data/foo")
bar = self.gconf_client.get_int("/path/to/my/config/data/bar")
baz = self.gconf_client.get_bool("/path/to/my/config/data/baz")
Run Code Online (Sandbox Code Playgroud)
在大多数情况下,每个人get_*都有一个等效的设定者set_*.