void PythonEngine::init() { m_isRunning = false; m_stdOut = ""; // connect stdout connect(this, SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); // init python Py_Initialize(); // read functions m_functions = readFileContent(datadir() + "/functions.py"); m_dict = PyDict_New(); PyDict_SetItemString(m_dict, "__builtins__", PyEval_GetBuiltins()); // init engine extensions Py_InitModule("pythonlab", pythonEngineFuntions); addCustomExtensions(); // custom modules PyRun_String(QString("import sys; sys.path.insert(0, \"" + datadir() + "/resources/python" + "\")").toStdString().c_str(), Py_file_input, m_dict, m_dict); // functions.py PyRun_String(m_functions.toStdString().c_str(), Py_file_input, m_dict, m_dict); }
void PythonEngine::init() { m_isScriptRunning = false; m_isExpressionRunning = false; // init python PyEval_InitThreads(); Py_Initialize(); // args /// \todo Better int argc = 1; char ** argv = new char*[1]; argv[0] = new char[1](); PySys_SetArgv(argc, argv); delete [] argv[0]; delete [] argv; // read pythonlab functions addFunctions(readFileContent(datadir() + "/resources/python/functions_pythonlab.py")); addCustomFunctions(); // m_dict = PyDict_New(); // PyDict_SetItemString(m_dict, "__builtins__", PyEval_GetBuiltins()); PyObject *main = PyImport_ImportModule("__main__"); Py_INCREF(main); m_dict = PyModule_GetDict(main); Py_INCREF(m_dict); // init engine extensions Py_InitModule("pythonlab", pythonEngineFuntions); addCustomExtensions(); // custom modules PyObject *import = PyRun_String(QString("import sys; sys.path.insert(0, \"" + datadir() + "/resources/python" + "\")").toLatin1().data(), Py_file_input, m_dict, m_dict); Py_XDECREF(import); // functions.py PyObject *func = PyRun_String(m_functions.toLatin1().data(), Py_file_input, m_dict, m_dict); Py_XDECREF(func); }