本文整理汇总了Python中PyObjCTools.KeyValueCoding.setKeyPath方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValueCoding.setKeyPath方法的具体用法?Python KeyValueCoding.setKeyPath怎么用?Python KeyValueCoding.setKeyPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyObjCTools.KeyValueCoding
的用法示例。
在下文中一共展示了KeyValueCoding.setKeyPath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cocoa_set
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [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')
示例2: test_accessor
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [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})
示例3: test_attr_set
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [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')
示例4: testMixedGraph2
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [as 别名]
def testMixedGraph2(self):
arr = objc.lookUpClass('NSMutableArray').alloc().init()
d1 = objc.lookUpClass('NSMutableDictionary').alloc().init()
d2 = objc.lookUpClass('NSMutableDictionary').alloc().init()
d3 = {}
root = objc.lookUpClass('NSMutableDictionary').dictionaryWithDictionary_({ 'a': arr, 'd': d2 })
arr.addObject_(d1)
arr.addObject_(d3)
d1['k'] = 1
d3['k'] = 2
KeyValueCoding.setKeyPath(root, 'd.a', 'the letter A')
self.assertEqual(d2, {'a': 'the letter A', })
self.assertEqual(KeyValueCoding.getKeyPath(root, 'd.a'), 'the letter A')
self.assertEqual(KeyValueCoding.getKeyPath(arr, 'k'), [1, 2])
self.assertEqual(KeyValueCoding.getKeyPath(root, 'a.k'), [1, 2])
示例5: test_dict_set
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [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'} })
示例6: test_none_set
# 需要导入模块: from PyObjCTools import KeyValueCoding [as 别名]
# 或者: from PyObjCTools.KeyValueCoding import setKeyPath [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)