[Pyobjc-dev] NSUserDefaultsController
Brought to you by:
ronaldoussoren
From: Paul D. <pa...@do...> - 2004-04-12 23:21:47
|
Hi, I'm trying to use the new NSUserDefaultsController (part of Cocoa Bindings). I've got some example code in Obj-C (from http://homepage.mac.com/mmalc/CocoaExamples/controllers.html), but I'm having trouble converting it to PyObjC. The original Obj-C code is: // Get font name and size from user defaults NSDictionary *values = [[NSUserDefaultsController sharedUserDefaultsController] values]; NSString *fontName = [values valueForKey:@"FontName"]; So I've converted it to this: prefs = NSUserDefaultsController.sharedUserDefaultsController().values() print prefs print prefs['FontName'] Results in: <_NSControllerObjectProxy: 0x1123830> 2004-04-13 00:12:22.453 Test[19056] An exception has occured: Traceback (most recent call last): File "/Users/pauld/Projects/Test/build/Test.app/Contents/Resources/ __main__.py", line 18, in ? AppHelper.runEventLoop(argv=[]) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/PyObjC/PyObjCTools/AppHelper.py", line 71, in runEventLoop NSApplicationMain(argv) File "/Users/pauld/Projects/Test/build/Test.app/Contents/Resources/ RatingsModel.py", line 46, in awakeFromNib self.makeLibrary(file) File "/Users/pauld/Projects/Test/build/Test.app/Contents/Resources/ RatingsModel.py", line 29, in makeLibrary print prefs['FontName'] TypeError: unsubscriptable object I'm not sure why the type of 'prefs' is an NSControllerObjectProxy. I was expecting it to be an NSDictionary* (and hence a python dictionary). I have an instance of an NSUserDefaultsController in my nib file, so I'm a bit stuck at this point. I'm using pyobjc from anonymous CVS as of a couple of days ago, on 10.3.3. Cheers, Paul |