Dear list, I'm trying to create a simple document-based app in Python and Cocoa. I'm not using PyObjC but another library called "cocoapy" ( http://code.google.com/p/cocoa-python/source/browse/). So far I really like but I ran into one issue. When I write the app in Objective C it works but when I translate it into Python it breaks. I thought it might have something to do with "NSDocumentClass" from Info.plist not being recognized by sharedDocumentController but I'm not sure. Please, would you be so kind and look at the following code, I'm very new into all this so perhaps I'm missing something.
# Info.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" " http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>simple</string> </array> <key>CFBundleTypeName</key> <string>simple</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>NSDocumentClass</key> <string>SimpleDocument</string> </dict> </array> <key>CFBundleExecutable</key> <string>simple</string> <key>CFBundleName</key> <string>Simple</string> </dict> </plist> # simple # ... some setup from bundlebuilder.py os.execve(executable, sys.argv, os.environ) # simple.py from cocoapy import * class SimpleDocumentImplementation(object): SimpleDocument = ObjCSubclass('NSDocument', 'SimpleDocument') @SimpleDocument.method('@') def init(self): self = ObjCInstance(send_super(self, 'init')) window = initWithContentRect_styleMask_backing_defer(NSMakeRect(100, 100, 480, 320), NSTitledWindowMask, NSBackingStoreBuffered, True) window.makeKeyAndOrderFront_(None) return self if __name__ == '__main__': NSAutoreleasePool = ObjCClass('NSAutoreleasePool') NSApplication = ObjCClass('NSApplication') NSWindow = ObjCClass('NSWindow') NSDocumentController = ObjCClass('NSDocumentController') SimpleDocument = ObjCClass('SimpleDocument') pool = NSAutoreleasePool.alloc().init() app = NSApplication.sharedApplication() controller = NSDocumentController.sharedDocumentController() controller.openUntitledDocumentAndDisplay_error_(True, None) # Here it breaks with "The (null) type doesn't map to any NSDocumentClass." Without it it still wont open the first default window. app.run() I expect it to open one window at start up, this is what the Objectve C app does by default. Here it doesn't show anything and when I try to force open it, it breaks. Thank you for any kind of help! Ecir Hana
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG