On 11 Jul, 2010, at 1:18, Georg Seifert wrote:

> Hi Ronald,
> 
> Thanks for your response.
> 
> I did tried this:
> 
>       class PathNodesProxy (object):
>               def __init__(self, owner):
>                       self._ower = owner
>               def __getitem__(self, i):
>                       print "__getitem__", i
>                       return self.nodeAtIndex_(i)
>               def __setitem__(self, i, Node):
>                       print "__setitem__", i, Node
>                       self.setNode_atIndex_(Node, i)
>               def __delitem__(self, i):
>                       print "__delitem__", i
>                       self.removeNodeAtIndex_(i)
>               def append(self, Node):
>                       print "append", Node
>                       self.addNode_(Node)
>               def count(self):
>                       print "count"
>                       return self.nodes().count()
> 
>       del GSPath.__dict__['nodes']
>       GSPath.__dict__['nodes'] = lambda self: PathNodesProxy(self)
> 
> the next to last line gives this error:
>       TypeError: 'dictproxy' object does not support item deletion
> and the last (if I remove the first):
>       TypeError: 'dictproxy' object does not support item assignment
> 
> If I used:
>       GSPath.nodes = lambda self: PathNodesProxy(self)
> It worked somehow, but it actually removed the nodes property from the cocoa 
> object. And I still had to use the parenthesis.

This should work:

     GSPath.nodes = property(lambda self: PathNodesProxy(self))

I've tested this with the count property on an array:

:>>> from Foundation import NSArray
:>>> b = NSArray.arrayWithArray_([1,2])
:>>> type(b).count = property(lambda self: id(self))
:>>> b.pyobjc_instanceMethods.count()
2
:>>> b.count
4359092688
:>>> 

(The convoluted way to change the count property is because NSArray is a class 
cluster and is not relevant for your problem)

Ronald

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to