So when doing GUIs in with PyObjC you'll realize that the IBOutlet for tying objects to variables have a few limitations. The one I hit was that a single outlet can only be connected to one object. So I read up on Key-value coding. So to do this you have to add two functions per variable:
def name(self):
return self.var
def setName(self, x):
self.var = x
You can imagine that this becomes tedious really fast. Luckily there is a solution. As an example:
from PyObjCTools.KeyValueCoding import kvc
class controller(NSWindowController, kvc):
title = ""
artist = ""
album = ""
So this ties __getattr__ and __setattr__ to valueForKey: and setValue:forKey. Making every class variable available for Key-value coding. Very handy.
> anyKVCCompliantObject = NSMutableDictionary.alloc().init()
> anyKVCCompliantObject._.someKey = 'any value'
> anyKVCCompliantObject.valueForKey_('someKey')
'hello'
> anyKVCCompliantObject._.hello
'hello'


If you have PyObjC 2.0 (i.e. OS X 10.5) you can do this by using the
_property, no multiple inheritance required: