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. Best Regards Georg On 08.07.2010, at 23:16, Ronald Oussoren wrote: > > On 8 Jul, 2010, at 23:00, Georg Seifert wrote: > >> Hi, >> >> In my app I will access my cocoa data classes from a python script (run from >> within the app). This works fine, I can access all the methods and >> properties. For some of the array properties I use dedicated getter and >> setter (getItemAtIndex: , setItemAtIndex: ...). >> >> I have a cocoa object: >> >> @interface myObject : NSObject { >> NSMutableArray *_items; >> } >> @property(retain) NSArray * items; >> - (void) setItem:(id) Item atIndex: (int) Index; >> - (id) itemAtIndex: (int) Index; >> @end >> >> Is it possible to access like: >> object.items()[i] # it would be even better to get rid of the >> parenthesis. >> or >> object.items.append(NewItem) >> >> Calling from python should call the cocoa accessors instead of accessing the >> list directly. (I need to set some values and implemented undo in the >> accessors.) >> >> My users are used to plain python scripting environments and don’t like the >> cocoa method names. >> >> Is it somehow possible to tell python what accessors to use or is there a >> way to supply python wrappers? Or could I build a bridgesupport file? > > Not easily. I've implemented code for the upcoming 2.3 release of pyobjc that > will generate the accessors for you when you create a property in Python, but > haven't gotten around to implementing the other direction. > > Something that likely works (but I haven't tested this): > > class ItemProxy (object): > def __init__(self, owner): > self._ower = owner > > def __getitem__(self, i): > return self.itemAtIndex_(i) > > ... > > del myClass.__dict__['items'] > myClass.__dict__['items'] = lambda self: ItemProxy(self) > > A future version of PyObjC will allow you to configure ObjC properties in > native classes using bridgesupport files and/or function in the objc module. > > Ronald > > P.S. I want to release PyObjC 2.3 this saturday, but need to squash a couple > of bugs in the 64-bit support before I do the release. > > P.P.S. The major feature in PyObjC 2.3 is support for Python 3. _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG