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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/02/2010 Added this text. :-)
15 #include "rs_python.h"
20 // This is exported from the Boost::Python library declarations
21 // that are declared inside rs_python_wrappers.cpp.
23 extern "C" void initqcad();
26 * The unique instance of the Python scripting engine
28 RS_Python* RS_Python::uniqueInstance = NULL;
33 RS_Python::RS_Python()
41 * Gets the one and only RS_Python instance
42 * (creates a new one on first call only)
44 * @return Pointer to the single instance of this
47 RS_Python* RS_Python::instance() {
48 if(uniqueInstance==NULL) {
49 uniqueInstance = new RS_Python;
51 return uniqueInstance;
56 * Launches the given script.
58 int RS_Python::launch(const QString& script) {
59 PyObject *modname, *mod, *mdict, *func, *rslt;
60 //Py_SetProgramName(argv[0]);
62 modname = PyString_FromString(script);
63 mod = PyImport_Import(modname);
66 mdict = PyModule_GetDict(mod);
68 // Borrowed reference to start function
69 func = PyDict_GetItemString(mdict, "start");
72 if (PyCallable_Check(func)) {
73 //printf("calling..\n");
74 rslt = PyObject_CallFunction(func, "(s)", "noparam");
75 //printf("calling ok\n");
77 // The result value is currently not used
81 // Give user some feed back what went wrong
82 printf("*** PYTHON RUNTIME ERROR ***\n");
87 printf("no such function: start\n");
91 printf("*** ERROR LOADING SCRIPT '%s' ***\n", script.latin1());