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


Python KeyValueCoding.setKey方法代码示例

本文整理汇总了Python中PyObjCTools.KeyValueCoding.setKey方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValueCoding.setKey方法的具体用法?Python KeyValueCoding.setKey怎么用?Python KeyValueCoding.setKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyObjCTools.KeyValueCoding的用法示例。


在下文中一共展示了KeyValueCoding.setKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cocoa_set

# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKey [as 别名]
    def test_cocoa_set(self):
        o = objc.lookUpClass('NSMutableDictionary').alloc().init()
        KeyValueCoding.setKey(o, 'attr', 'value')
        self.assertEqual(o, {'attr': 'value'})

        KeyValueCoding.setKeyPath(o, 'attr', 'value2')
        self.assertEqual(o, {'attr': 'value2'})

        o = objc.lookUpClass('NSObject').alloc().init()
        self.assertRaises(KeyError, KeyValueCoding.setKey, o, 'description', 'hello')
        self.assertRaises(KeyError, KeyValueCoding.setKeyPath, o, 'description', 'hello')
开发者ID:BMXE,项目名称:music-player,代码行数:13,代码来源:test_keyvaluecoding.py

示例2: test_dict_set

# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKey [as 别名]
    def test_dict_set(self):
        v = {'a': 42, 'c':{} }

        KeyValueCoding.setKey(v, 'a', 43)
        KeyValueCoding.setKey(v, 'b', 'B')
        self.assertEqual(v, {'a': 43, 'b': 'B', 'c':{} })

        KeyValueCoding.setKeyPath(v, 'a', 44)
        KeyValueCoding.setKeyPath(v, 'b', 'C')
        KeyValueCoding.setKeyPath(v, 'c.a', 'A')
        self.assertEqual(v, {'a': 44, 'b': 'C', 'c':{'a': 'A'} })
开发者ID:BMXE,项目名称:music-player,代码行数:13,代码来源:test_keyvaluecoding.py

示例3: test_accessor

# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKey [as 别名]
    def test_accessor(self):
        class Record (object):
            def __init__(self):
                self._attr1 = 1
                self._attr2 = 2
                self._attr3 = 3

            def attr1(self):
                return self._attr1

            def setAttr1_(self, value):
                self._attr1 = (1, value)

            def setAttr1(self, value):
                self._attr1 = (2, value)

            def set_attr1(self, value):
                self._attr1 = (3, value)

            def setAttr2(self, value):
                self._attr2 = (2, value)

            def set_attr2(self, value):
                self._attr2 = (3, value)

            def set_attr3(self, value):
                self._attr3 = (3, value)
            
            set_no_attr = 4

        o = Record()
        self.assertEqual(o._attr1, 1)
        self.assertEqual(o._attr2, 2)
        self.assertEqual(o._attr3, 3)
        self.assertEqual(o.set_no_attr, 4)

        KeyValueCoding.setKey(o, 'attr1', 9)
        KeyValueCoding.setKey(o, 'attr2', 10)
        KeyValueCoding.setKey(o, 'attr3', 11)
        KeyValueCoding.setKey(o, 'no_attr', 12)

        
        self.assertEqual(o._attr1, (1, 9))
        self.assertEqual(o._attr2, (2, 10))
        self.assertEqual(o._attr3, (3, 11))
        self.assertEqual(o.no_attr, 12)

        KeyValueCoding.setKeyPath(o, 'attr1', 29)
        KeyValueCoding.setKeyPath(o, 'attr2', 210)
        KeyValueCoding.setKeyPath(o, 'attr3', 211)
        
        self.assertEqual(o._attr1, (1, 29))
        self.assertEqual(o._attr2, (2, 210))
        self.assertEqual(o._attr3, (3, 211))

        o._attr1 = {'a': 'b'}
        KeyValueCoding.setKeyPath(o, 'attr1.a', 30)
        self.assertEqual(o._attr1, {'a': 30})
开发者ID:BMXE,项目名称:music-player,代码行数:60,代码来源:test_keyvaluecoding.py

示例4: test_attr_set

# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKey [as 别名]
    def test_attr_set(self):
        class R (object):
            @property
            def attr3(self):
                return self._attr3

            @attr3.setter
            def attr3(self, v):
                self._attr3 = v * 2

            @property
            def attr4(self):
                return self._attr4

            def attr6(self):
                return self._attr6

        r = R()
        r._attr1 = 42
        r._attr4 = 43
        r.attr5 = {}
        r._attr6 = 9

        KeyValueCoding.setKey(r, 'attr1', 1)
        KeyValueCoding.setKey(r, 'attr2', 2)
        KeyValueCoding.setKey(r, 'attr3', 3)
        self.assertRaises(KeyError, KeyValueCoding.setKey, r, 'attr4', 4)
        KeyValueCoding.setKey(r, 'attr6', 7)

        self.assertEqual(r._attr1, 1)
        self.assertEqual(r.attr2, 2)
        self.assertEqual(r.attr3, 6)
        self.assertEqual(r._attr3, 6)
        self.assertEqual(r._attr6, 7)

        KeyValueCoding.setKeyPath(r, 'attr1', 'one')
        KeyValueCoding.setKeyPath(r, 'attr2', 'two')
        KeyValueCoding.setKeyPath(r, 'attr3', 'three')
        KeyValueCoding.setKeyPath(r, 'attr5.sub1', 3)
        KeyValueCoding.setKeyPath(r, 'attr6', 'seven')

        self.assertEqual(r._attr1, 'one')
        self.assertEqual(r.attr2, 'two')
        self.assertEqual(r.attr3, 'threethree')
        self.assertEqual(r._attr3, 'threethree')
        self.assertEqual(r.attr5, {'sub1': 3})
        self.assertEqual(r._attr6, 'seven')
开发者ID:BMXE,项目名称:music-player,代码行数:49,代码来源:test_keyvaluecoding.py

示例5: test_none_set

# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKey [as 别名]
 def test_none_set(self):
     # setKey(None, 'any', 'value') is documented as a no-op
     # check that this doesn't raise an exception.
     v = None
     KeyValueCoding.setKey(v, 'a', 42)
     KeyValueCoding.setKeyPath(v, 'a', 42)
开发者ID:BMXE,项目名称:music-player,代码行数:8,代码来源:test_keyvaluecoding.py


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