如果 GSettings 模式存在并且已经编译,那么读取它通常没有问题。但是,如果它不存在,通常会抛出无法处理的错误。在 Python 文件或控制台中试试这个:
from gi.repository import Gio
try:
settings = Gio.Settings("com.example.doesnotexist")
except:
print "Couldn't load those settings!"
我尽可能广泛地使用except
,但这是引发的错误。
(进程:10248):GLib-GIO-ERROR **:未安装设置架构“com.example.doesnotexist”
我基本上想要做的是找出com.example.doesnotexist
模式是否存在;如果没有,那么告诉用户在使用我的应用程序之前运行我的设置脚本。任何其他关于这样做的建议都将受到欢迎。