// tracing int traceFunction(PyObject *obj, _frame *frame, int what, PyObject *arg) { PyObject *str = PyObject_Str(frame->f_code->co_filename); if (str) { QString fileName = QString::fromStdString(PyString_AsString(str)); Py_DECREF(str); if (!currentPythonEngine()->profilerFileName().isEmpty() && fileName.contains(currentPythonEngine()->profilerFileName())) { // catch line change events, print the filename and line number if (what == PyTrace_LINE) { currentPythonEngine()->profilerAddLine(frame->f_lineno); // qDebug() << "PyTrace_LINE: " << fileName << ": " << frame->f_lineno; } // catch line change events, print the filename and line number if (what == PyTrace_CALL) { // qDebug() << "PyTrace_CALL: " << fileName << ": " << frame->f_lineno; } // catch line change events, print the filename and line number if (what == PyTrace_RETURN) { // qDebug() << "PyTrace_RETURN: " << fileName << ": " << frame->f_lineno; } } } return 0; }
bool scriptIsRunning() { logMessage("scriptIsRunning()"); if (currentPythonEngine()) return currentPythonEngine()->isRunning(); else return false; }
// clear static PyObject* pythonClear(PyObject* self, PyObject* pArgs) { emit currentPythonEngine()->pythonClearCommand(); Py_RETURN_NONE; return NULL; }
// print html PyObject* pythonInsertHtml(PyObject* self, PyObject* pArgs) { char *str = NULL; if (PyArg_ParseTuple(pArgs, "s", &str)) { emit currentPythonEngine()->pythonShowHtmlCommand(QString(str)); Py_RETURN_NONE; } return NULL; }
// print stdout PyObject* pythonStdout(PyObject* self, PyObject* pArgs) { char *str = NULL; if (PyArg_ParseTuple(pArgs, "s", &str)) { emit currentPythonEngine()->pythonShowMessageCommand(QString(str) + "\n"); Py_RETURN_NONE; } return NULL; }
// show image PyObject* pythonShowFigure(PyObject* self, PyObject* pArgs) { char *str = NULL; int width = 0; int height = 0; if (PyArg_ParseTuple(pArgs, "s|ii", &str, &width, &height)) { emit currentPythonEngine()->pythonShowImageCommand(QString(str), width, height); Py_RETURN_NONE; } return NULL; }
QWidget *ProblemDialog::createControlsStartupScript() { logMessage("ProblemDialog::createControlsStartupScript()"); txtStartupScript = new ScriptEditor(currentPythonEngine(), this); QVBoxLayout *layoutStartup = new QVBoxLayout(); layoutStartup->addWidget(txtStartupScript); QWidget *widStartup = new QWidget(); widStartup->setLayout(layoutStartup); return widStartup; }
QWidget *ConfigDialog::createGlobalScriptWidget() { logMessage("ConfigDialog::createGlobalScriptWidget()"); QWidget *viewWidget = new QWidget(this); txtGlobalScript = new ScriptEditor(currentPythonEngine(), this); // layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(txtGlobalScript); viewWidget->setLayout(layout); return viewWidget; }
QWidget *ProblemWidget::createControlsScriptAndDescription() { // startup script txtStartupScript = new ScriptEditor(currentPythonEngine(), this); lblStartupScriptError = new QLabel(); QPalette palette = lblStartupScriptError->palette(); palette.setColor(QPalette::WindowText, QColor(Qt::red)); lblStartupScriptError->setPalette(palette); QVBoxLayout *layoutStartup = new QVBoxLayout(); layoutStartup->addWidget(txtStartupScript); layoutStartup->addWidget(lblStartupScriptError); QGroupBox *grpStartup = new QGroupBox(tr("Startup script")); grpStartup->setLayout(layoutStartup); // description txtDescription = new QTextEdit(this); txtDescription->setAcceptRichText(false); QVBoxLayout *layoutDescription = new QVBoxLayout(); layoutDescription->addWidget(txtDescription); QGroupBox *grpDescription = new QGroupBox(tr("Description")); grpDescription->setLayout(layoutDescription); // layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(grpStartup, 2); layout->addWidget(grpDescription, 1); layout->addStretch(); QWidget *widget = new QWidget(); widget->setLayout(layout); return widget; }
// current python engine agros AGROS_LIBRARY_API PythonEngineAgros *currentPythonEngineAgros() { return static_cast<PythonEngineAgros *>(currentPythonEngine()); }
// current python engine agros PythonEngineField *currentPythonEngineAgros() { return static_cast<PythonEngineField *>(currentPythonEngine()); }
void MaterialEditDialog::createControls() { lstProperties = new QListWidget(this); lstProperties->setMouseTracking(true); lstProperties->setMaximumWidth(200); connect(lstProperties, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(doPropertyChanged(QListWidgetItem *, QListWidgetItem *))); txtName = new QLineEdit(); txtDescription = new QLineEdit(); QGridLayout *layoutNameAndDescription = new QGridLayout(); layoutNameAndDescription->addWidget(new QLabel(tr("Name:")), 0, 0); layoutNameAndDescription->addWidget(txtName, 0, 1); layoutNameAndDescription->addWidget(new QLabel(tr("Description:")), 1, 0); layoutNameAndDescription->addWidget(txtDescription, 2, 0, 1, 3); QPushButton *btnAddProperty = new QPushButton(tr("Add...")); btnAddProperty->setDefault(false); QAction *actAddCustom = new QAction(tr("Custom property"), this); connect(actAddCustom, SIGNAL(triggered()), this, SLOT(addProperty())); // TODO: more general QAction *actAddThermalConductivity = new QAction(tr("Thermal conductivity"), this); connect(actAddThermalConductivity, SIGNAL(triggered()), this, SLOT(addPropertyThermalConductivity())); QAction *actAddSpecificHeat = new QAction(tr("Specific heat"), this); connect(actAddSpecificHeat, SIGNAL(triggered()), this, SLOT(addPropertySpecificHeat())); QAction *actAddDensity = new QAction(tr("Density"), this); connect(actAddDensity, SIGNAL(triggered()), this, SLOT(addPropertyDensity())); QAction *actAddMagneticPermeability = new QAction(tr("Magnetic permeability"), this); connect(actAddMagneticPermeability, SIGNAL(triggered()), this, SLOT(addPropertyMagneticPermeability())); QMenu *menu = new QMenu(); menu->addAction(actAddCustom); menu->addSeparator(); menu->addAction(actAddThermalConductivity); menu->addAction(actAddSpecificHeat); menu->addAction(actAddDensity); menu->addSeparator(); menu->addAction(actAddMagneticPermeability); btnAddProperty->setMenu(menu); btnDeleteProperty = new QPushButton(tr("Delete")); btnDeleteProperty->setDefault(false); connect(btnDeleteProperty, SIGNAL(clicked()), this, SLOT(deleteProperty())); QGridLayout *layoutList = new QGridLayout(); layoutList->addWidget(lstProperties, 0, 0, 1, 2); layoutList->addWidget(btnAddProperty, 1, 0); layoutList->addWidget(btnDeleteProperty, 1, 1); propertyGUI = createPropertyGUI(); QHBoxLayout *layoutNonlinearProperties = new QHBoxLayout(); layoutNonlinearProperties->addLayout(layoutList); layoutNonlinearProperties->addWidget(propertyGUI, 1); // table txtPropertyTableKeys = new QPlainTextEdit(); txtPropertyTableValues = new QPlainTextEdit(); QGridLayout *layoutTable = new QGridLayout(); layoutTable->addWidget(new QLabel(tr("Keys:")), 0, 0); layoutTable->addWidget(txtPropertyTableKeys, 1, 0); layoutTable->addWidget(new QLabel(tr("Values:")), 0, 1); layoutTable->addWidget(txtPropertyTableValues, 1, 1); widNonlinearTable = new QGroupBox(tr("Table")); widNonlinearTable->setLayout(layoutTable); // function txtPropertyFunction = new ScriptEditor(currentPythonEngine(), this); txtPropertyFunctionFrom = new LineEditDouble(0.0); txtPropertyFunctionTo = new LineEditDouble(0.0); QGridLayout *layoutFunction = new QGridLayout(); layoutFunction->addWidget(txtPropertyFunction, 0, 0, 1, 4); layoutFunction->addWidget(new QLabel(tr("From:")), 1, 0); layoutFunction->addWidget(txtPropertyFunctionFrom, 1, 1); layoutFunction->addWidget(new QLabel(tr("To:")), 1, 2); layoutFunction->addWidget(txtPropertyFunctionTo, 1, 3); layoutFunction->setRowStretch(0, 1); widNonlinearFunction = new QGroupBox(tr("Nonlinear function")); widNonlinearFunction->setLayout(layoutFunction); chartNonlinear = new QCustomPlot(); chartNonlinear->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); chartNonlinear->setMinimumHeight(120); chartNonlinear->addGraph(); chartNonlinear->graph(0)->setLineStyle(QCPGraph::lsLine); QHBoxLayout *layoutChartNonlinear = new QHBoxLayout(); layoutChartNonlinear->addWidget(chartNonlinear); widChartNonlinear = new QGroupBox(tr("Chart")); widChartNonlinear->setLayout(layoutChartNonlinear); layoutNonlinearType = new QStackedLayout(); layoutNonlinearType->addWidget(widNonlinearFunction); layoutNonlinearType->addWidget(widNonlinearTable); QHBoxLayout *layoutNonlinearChart = new QHBoxLayout(); layoutNonlinearChart->addLayout(layoutNonlinearType, 2); layoutNonlinearChart->addWidget(widChartNonlinear, 1); QVBoxLayout *layoutNonlinear = new QVBoxLayout(); layoutNonlinear->addLayout(layoutNonlinearProperties); layoutNonlinear->addLayout(layoutNonlinearChart, 1); // dialog buttons QPushButton *btnPlot = new QPushButton(tr("Plot")); connect(btnPlot, SIGNAL(clicked()), this, SLOT(drawChart())); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); buttonBox->addButton(btnPlot, QDialogButtonBox::ActionRole); connect(buttonBox, SIGNAL(accepted()), this, SLOT(doAccept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout *layout = new QVBoxLayout(); layout->addLayout(layoutNameAndDescription); layout->addLayout(layoutNonlinear, 1); layout->addStretch(); layout->addWidget(buttonBox); setLayout(layout); }
ExpressionResult runPythonExpression(const QString &expression, bool returnValue) { logMessage("runPythonExpression()"); return currentPythonEngine()->runPythonExpression(expression, returnValue); }
ScriptResult runPythonScript(const QString &script, const QString &fileName) { logMessage("runPythonScript()"); return currentPythonEngine()->runPythonScript(script, fileName); }