[Pyobjc-dev] Class OC_PythonObject: no such selector: _cfTypeID
Brought to you by:
ronaldoussoren
|
From: <jon...@mu...> - 2010-06-10 22:43:38
|
My ObjC app loads user generated PyObjC scripts using a Python NSObject subclass (see below)
In general, errors in the Python scripts are generating application level exceptions.
For instance, consider the following source file Boo.py.
def funcBoo():
return result
Dynamically loading Boo.py and calling funcBoo using the class below generates an ObjC NSException in the host app:
Class OC_PythonObject: no such selector: _cfTypeID
Assigning a value to the result variable resolves the problem.
Is there a way of determining or reporting the underlying Python issue that is causing the NSException?
# py executor
from Foundation import *
from AppKit import *
import imp
import sys
class MGSPythonScriptExecutor(NSObject):
@classmethod
def loadModuleAtPath_functionName_arguments_(self, path, func, args):
f = open(path)
try:
theResult = None
realfunc = None
taskObject = None
# load code at path as a module
modBoo = imp.load_module('modBoo', f, path, (".py", "r", imp.PY_SOURCE))
try:
taskObject = modBoo.objBoo.alloc().init()
except:
taskObject = None
# get function from object
if taskObject is not None:
# get function
realfunc = getattr(taskObject, func, None)
# get function from module
if realfunc is None:
# get function
realfunc = getattr(modBoo, func, None)
# if we have a function than call it
if realfunc is not None:
# call the function with our arguments
# we make a tuple from our list and then unpack it
theResult = realfunc(*tuple(args))
except Exception:
theResult = "exception in python script executor: ", sys.exc_info()
except:
theResult = "error in python script executor: ", sys.exc_info()
finally:
f.close()
return theResult
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com
|