1 /****************************************************************************
2 ** $Id: rs_python.cpp 1741 2003-09-30 22:50:17Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_python.h"
32 // This is exported from the Boost::Python library declarations
33 // that are declared inside rs_python_wrappers.cpp.
35 extern "C" void initqcad();
38 * The unique instance of the Python scripting engine
40 RS_Python* RS_Python::uniqueInstance = NULL;
45 RS_Python::RS_Python()
53 * Gets the one and only RS_Python instance
54 * (creates a new one on first call only)
56 * @return Pointer to the single instance of this
59 RS_Python* RS_Python::instance() {
60 if(uniqueInstance==NULL) {
61 uniqueInstance = new RS_Python;
63 return uniqueInstance;
68 * Launches the given script.
70 int RS_Python::launch(const RS_String& script) {
71 PyObject *modname, *mod, *mdict, *func, *rslt;
72 //Py_SetProgramName(argv[0]);
74 modname = PyString_FromString(script);
75 mod = PyImport_Import(modname);
78 mdict = PyModule_GetDict(mod);
80 // Borrowed reference to start function
81 func = PyDict_GetItemString(mdict, "start");
84 if (PyCallable_Check(func)) {
85 //printf("calling..\n");
86 rslt = PyObject_CallFunction(func, "(s)", "noparam");
87 //printf("calling ok\n");
89 // The result value is currently not used
93 // Give user some feed back what went wrong
94 printf("*** PYTHON RUNTIME ERROR ***\n");
99 printf("no such function: start\n");
103 printf("*** ERROR LOADING SCRIPT '%s' ***\n", script.latin1());