本文整理汇总了Python中AnyQt.QtCore.QSettings.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QSettings.clear方法的具体用法?Python QSettings.clear怎么用?Python QSettings.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QSettings
的用法示例。
在下文中一共展示了QSettings.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_settings
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import clear [as 别名]
def test_settings(self):
spec = [config_slot("foo", bool, True, "foo doc"),
config_slot("bar", int, 0, "bar doc"),
]
store = QSettings(QSettings.IniFormat, QSettings.UserScope,
"biolab.si", "Orange Canvas Unit Tests")
store.clear()
settings = Settings(defaults=spec, store=store)
self.assertEqual(settings["foo"], True)
self.assertEqual(settings.get("foo"), True)
self.assertEqual(settings.get("bar", 3), 0, "Defaults")
self.assertEqual(settings.get("bar"), settings["bar"])
self.assertEqual(settings.get("does not exist", "^&"), "^&",
"get with default")
self.assertIs(settings.get("does not exist"), None)
with self.assertRaises(KeyError):
settings["does not exist"]
self.assertTrue(settings.isdefault("foo"))
changed = []
settings.valueChanged.connect(
lambda key, value: changed.append((key, value))
)
settings["foo"] = False
self.assertEqual(changed[-1], ("foo", False), "valueChanged signal")
self.assertEqual(len(changed), 1)
self.assertEqual(settings["foo"], False, "updated value")
self.assertEqual(settings.get("foo"), False)
self.assertFalse(settings.isdefault("foo"))
settings["bar"] = 1
self.assertEqual(changed[-1], ("bar", 1), "valueChanged signal")
self.assertEqual(len(changed), 2)
self.assertEqual(settings["bar"], 1)
self.assertFalse(settings.isdefault("bar"))
del settings["bar"]
self.assertEqual(settings["bar"], 0)
self.assertEqual(changed[-1], ("bar", 0))
# Only str or unicode can be keys
with self.assertRaises(TypeError):
settings[1] = 3
# value type check
with self.assertRaises(TypeError):
settings["foo"] = []
self.assertEqual(len(changed), 3)
settings.add_default_slot(config_slot("foobar/foo", object, None, ""))
group = settings.group("foobar")
self.assertIs(group["foo"], None)
group["foo"] = 3
self.assertEqual(changed[-1], ("foobar/foo", 3))
group["foonew"] = 5
self.assertIn("foobar/foonew", settings)
settings["newkey"] = "newkeyvalue"
self.assertIn("newkey", settings)
group1 = group.group("bar")
group1["barval"] = "barval"
self.assertIn("foobar/bar/barval", settings)
settings["foobar/bar/barval"] = 5
self.assertEqual(changed[-1], ("foobar/bar/barval", 5))
settings.clear()
self.assertSetEqual(set(settings.keys()),
set(["foo", "bar", "foobar/foo"]))