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); }
void PythonEngineAgros::addCustomFunctions() { addFunctions(readFileContent(datadir() + "/resources/python/functions_agros2d.py")); }
// // bool setFunctions(f) // Last modified: 28Aug2006 // // Attempts to set the set of functions // to the parameterized set of functions, // returning true if successful, false otherwise. // // Returns: true if successful, false otherwise // Parameters: // f in/out the set of functions to be set to // bool Formation::setFunctions(const LinkedList<Function> &f) { clear(); return addFunctions(f); } // setFunctions(const LinkedList<Function> &)
bool generateFileContents(QStringList &header, QStringList &source, const QString &originalClassName, const QString &className, const QStringList &dependencyIncludes, const QStringList &buildIncludes, const QString &headerName, const ClassParserInformation &info) { // Add header and source file contents to strings. QString upper = className.toUpper() + "_H"; header << "#if !defined(" + upper + ")"; header << "#define " + upper; // Add necessary includes. // Trick so that qmake finds dependences but files are not included. header << "#if !defined(_QMCTYPELIBBUILD)"; foreach (const QString &inc, dependencyIncludes) header << "#include \"" + inc + "\""; // Takes care of class name appearing in parameters and return types. header << "#else"; header << "#define " + originalClassName + " " + className; header << "#endif"; // Some of these could be in <> but as long as it works... foreach (const QString &inc, buildIncludes) header << "#include \"" + inc + "\""; source << "#include \"" + headerName + "\""; // Add all parent classes. QString parents; if (!info.m_listChildClass.isEmpty()) parents = " : "; EClassParserMemberType previous = FUNCTION_TYPE_NONE; if (info.m_strClassType == "class") previous = FUNCTION_TYPE_PRIVATE; else if (info.m_strClassType == "struct") previous = FUNCTION_TYPE_PUBLIC; else { qWarning() << "Do not know how to handle:" << info.m_strClassType; return false; } // In plain "class Foo : Bar" what is the type listed as? for (int k = 0; k < info.m_listChildClass.size(); ++k) { const SClassParserChildClass &parent = info.m_listChildClass[k]; if (previous != parent.m_pType) { switch (parent.m_pType) { case FUNCTION_TYPE_PUBLIC: parents += "public "; break; case FUNCTION_TYPE_PRIVATE: parents += "private "; break; case FUNCTION_TYPE_PROTECTED: parents += "protected "; break; default: // What is the type for Bar in "public Foo, Bar"? qWarning() << "Unexpected class inheritance type:" << parent.m_pType; continue; } previous = parent.m_pType; } else if (k && k < info.m_listChildClass.size() - 1) { // Uses same inheritance as previous (or default if first). parents += ", "; } parents += parent.m_strName; if (k != info.m_listChildClass.size() - 1) parents += ", "; } header << info.m_strClassType + " " + className + parents + " {"; if (!addProperties(header, info)) return false; // Anything seemingly recognized as macros is probably needed. // This includes Q_CLASSINFO, for example. foreach (const SClassParserPossibleMacroWithoutKnownledge& m, info.m_listPossibleMacroWithoutKnownledge) { header << m.m_strMacroLine; } if (!addFunctions(header, source, originalClassName, className, info)) return false; header << "};"; header << "#endif"; return true; }
ChildObjBgGettersModule::ChildObjBgGettersModule() : MappedRLModule(childObjMappingFun, "ChildObjBgGetters", 2, 85) { addFunctions(*this); setProperty(P_FGBG, OBJ_BG); }
ObjBgGettersModule::ObjBgGettersModule() : RLModule("ObjBgGetters", 1, 85) { addFunctions(*this); setProperty(P_FGBG, OBJ_BG); }
ScriptEngine::ScriptEngine(QObject *parent) : QScriptEngine(parent) { addFunctions(); }
// Attempts to set the set of functions // to the parameterized set of functions, // returning true if successful, false otherwise. bool Formation::setFunctions(const vector<Function> &f) { clear(); return addFunctions(f); }