[Pyobjc-dev] Best way to rectify attribute/method name conflation?
Brought to you by:
ronaldoussoren
From: Zachery B. <zb...@ur...> - 2004-03-28 15:14:20
|
In ObjC, as you all know, method names and attributes can share names. In Python, they can't. I'm trying to translate some code from ObjC to Python, and I'm having a hard time figuring out the proper way to untangle this mess. I've got a class called IconAndTextCell, which derives from NSTextFieldCell (and thence from NSActionCell and NSCell - which is far enough back for this example). NSCell provides both an attribute image and a selector image(), and I'm trying to provide for the copyWithZone_() selector of my new class. Using an example in ObjC, I have this: [orig ObjC] - copyWithZone:(NSZone *)zone { ImageAndTextCell *cell = (ImageAndTextCell *)[super copyWithZone:zone]; cell->image = [image retain]; return cell; } the second statement there looks like it's going to be a pain in the backside to translate. The immediate thing that looked reasonable to me was to generate a new accessor (getImage) and do this: def copyWithZone_(self, zone): cell = super(IconAndTextCell, self).copyWithZone_(zone) cell.image = self.getImage() return cell Now, which 'image' attribute did I just clobber in the copied cell? The attribute or the accessor? Surely one or the other is already clobbered by the bridge, owing to the fact that Python won't allow two attributes with the same name. So, even going the route of using NSCell's setImage_() mutator: def copyWithZone_(self, zone): cell = super(IconAndTextCell, self).copyWithZone_(zone) cell.setImage_(self.getImage()) return cell doesn't seem like it will help, as the underlying data structure (NSCell.image) will get clobbered. Either NSCell will lose an attribute or an accessor. Am I right? Zac |