void AgrosSolver::runSuite() { // log stdout if (m_enableLog) m_log = new LogStdOut(); // silent mode setSilentMode(true); connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString))); QString testSuite = QString("from test_suite.scenario import run_suite; run_suite(test_suite.test_%1)").arg(m_suiteName); qDebug() << testSuite; bool successfulRun= currentPythonEngineAgros()->runScript(testSuite); if (successfulRun) { Agros2D::scene()->clear(); Agros2D::clear(); QApplication::exit(0); } else { ErrorResult result = currentPythonEngineAgros()->parseError(); Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n"). arg(result.error()). arg(result.line()). arg(result.traceback())); QApplication::exit(-1); } }
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 AgrosSolver::runScript() { // log stdout if (m_enableLog) m_log = new LogStdOut(); if (!QFile::exists(m_fileName)) { Agros2D::log()->printMessage(tr("Scripting Engine"), tr("Python script '%1' not found").arg(m_fileName)); QApplication::exit(-1); } QTime time; time.start(); // silent mode setSilentMode(true); connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString))); bool successfulRun= currentPythonEngineAgros()->runScript(readFileContent(m_fileName), m_fileName); if (successfulRun) { Agros2D::log()->printMessage(tr("Solver"), tr("Problem was solved in %1").arg(milisecondsToTime(time.elapsed()).toString("mm:ss.zzz"))); Agros2D::scene()->clear(); Agros2D::clear(); QApplication::exit(0); } else { ErrorResult result = currentPythonEngineAgros()->parseError(); Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n"). arg(result.error()). arg(result.line()). arg(result.traceback())); QApplication::exit(-1); } }
void PythonEngine::pythonShowMessageCommand(const QString &message) { if (message != "\n\n") emit pythonShowMessage(message); }
void PythonEngine::pythonShowMessageCommand(const QString &message) { emit pythonShowMessage(message); }