3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/02/2010 Added this text. :-)
22 // This is exported from the Boost::Python library declarations
23 // that are declared inside rs_python_wrappers.cpp.
25 extern "C" void initqcad();
28 * The unique instance of the Python scripting engine
30 RS_Python* RS_Python::uniqueInstance = NULL;
35 RS_Python::RS_Python()
43 * Gets the one and only RS_Python instance
44 * (creates a new one on first call only)
46 * @return Pointer to the single instance of this
49 RS_Python* RS_Python::instance() {
50 if(uniqueInstance==NULL) {
51 uniqueInstance = new RS_Python;
53 return uniqueInstance;
58 * Launches the given script.
60 int RS_Python::launch(const QString& script) {
61 PyObject *modname, *mod, *mdict, *func, *rslt;
62 //Py_SetProgramName(argv[0]);
64 modname = PyString_FromString(script);
65 mod = PyImport_Import(modname);
68 mdict = PyModule_GetDict(mod);
70 // Borrowed reference to start function
71 func = PyDict_GetItemString(mdict, "start");
74 if (PyCallable_Check(func)) {
75 //printf("calling..\n");
76 rslt = PyObject_CallFunction(func, "(s)", "noparam");
77 //printf("calling ok\n");
79 // The result value is currently not used
83 // Give user some feed back what went wrong
84 printf("*** PYTHON RUNTIME ERROR ***\n");
89 printf("no such function: start\n");
93 printf("*** ERROR LOADING SCRIPT '%s' ***\n", script.latin1());