[Pyobjc-dev] PreferencePanes in python
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@xs...> - 2003-02-14 21:26:06
|
I think I have found a way to build preference panes in Python. The following code seems to work just fine for loading and initializing a Python interpreter. The attached archive contains a complete (and rather lame) preference pane, run the shell-script to compile the Objective-C file and copy the prefpane to ~/Library/PreferencePanes to test. Both the script and the ObjC code require a framework install of python, but modifying it for a normal python install is pretty trivial (as long as there is a libpython.{so,dylib,a}, Apple's python won't work). Did I mis anything important? I know the PYTHONPATH is not correct, I'll look into that later. BTW. I couldn't get bundlebuilder to build the bundle for me, it always adds the shell-script wrapper which isn't needed here. Furthermore the output always has a '.app' suffix. More to look into... Ronald #import <Foundation/Foundation.h> #include <Python/Python.h> #ifndef CLASSNAME #define CLASSNAME testbundle #endif @interface CLASSNAME { } +(void)load; @end @implementation CLASSNAME +(void)load { NSBundle* bundle; NSString* mainPath; FILE* fp; bundle = [NSBundle bundleForClass:self]; [bundle load]; mainPath = [bundle pathForResource:@"__main__" ofType:@"py"]; if (mainPath == NULL) { // TODO: Raise exception; abort(); } if (!Py_IsInitialized()) { Py_Initialize(); } fp = fopen([mainPath cString], "r"); if (fp == NULL) { abort(); } PyRun_SimpleFile(fp, [mainPath cString]); } @end |