当前位置: 首页>>代码示例>>Python>>正文


Python QSettings.clear方法代码示例

本文整理汇总了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"]))
开发者ID:PrimozGodec,项目名称:orange3,代码行数:87,代码来源:test_settings.py


注:本文中的AnyQt.QtCore.QSettings.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。