-// Copyright (C) 2016 CEA/DEN, EDF R&D
+// Copyright (C) 2016-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// Author : Anthony Geay (EDF R&D)
+#include "Python.h"
#include "YDFXGUISeqInit.hxx"
#include <QFile>
#include <QFileDialog>
#include <QApplication>
-#include "Python.h"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "YDFXGUIWrap.hxx"
#include "YDFXGUIPyThreadSaver.hxx"
const char YDFXGUIStatus::OK_STR[]="OK !";
-class AutoPyRef
-{
-public:
- AutoPyRef(PyObject *pyobj=0):_pyobj(pyobj) { }
- ~AutoPyRef() { release(); }
- AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); }
- AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; }
- operator PyObject *() { return _pyobj; }
- void set(PyObject *pyobj) { if(pyobj==_pyobj) return ; release(); _pyobj=pyobj; }
- PyObject *get() { return _pyobj; }
- bool isNull() const { return _pyobj==0; }
- PyObject *retn() { if(_pyobj) Py_XINCREF(_pyobj); return _pyobj; }
-private:
- void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=0; }
-private:
- PyObject *_pyobj;
-};
-
////////////////////////////
void YDFXGUIDoubleVectHolder::applyOnInput(YACSEvalInputPort *inp) const
//
if(_fileName.isEmpty())
{
- emit problemDetected(QString("For \"%1\" : no file defined !").arg(zeBossc->getName()));
+ Q_EMIT problemDetected(QString("For \"%1\" : no file defined !").arg(zeBossc->getName()));
return false;
}
QFile file(_fileName);
double v(line2.toDouble(&isOK));
if(!isOK)
{
- emit problemDetected(QString("For \"%1\" : At line %2 it is not a float !").arg(zeBossc->getName()).arg(i));
+ Q_EMIT problemDetected(QString("For \"%1\" : At line %2 it is not a float !").arg(zeBossc->getName()).arg(i));
return false;
}
_vect.push_back(v);
std::string txt(toPlainText().toStdString());
YDFXGUIPyThreadSaver::SaveContext(QApplication::instance()->thread());
{
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
AutoPyRef code(Py_CompileString(txt.c_str(),TMP_FILENAME, Py_file_input));
if(code.get() == NULL)
{
- emit problemDetected(QString("For \"%1\" : python code is invalid !").arg(zeBossc->getName()));
+ Q_EMIT problemDetected(QString("For \"%1\" : python code is invalid !").arg(zeBossc->getName()));
return false;
}
AutoPyRef context(PyDict_New());
PyDict_SetItemString( context, "__builtins__", PyEval_GetBuiltins() );
- AutoPyRef res(PyEval_EvalCode((PyCodeObject *)code.get(), context, context));
+ AutoPyRef res(PyEval_EvalCode(code.get(), context, context));
PyObject *item(PyDict_GetItemString(context,name.c_str()));
//
if(!item)
{
- emit problemDetected(QString("For \"%1\" : Py var %1 is not defined !").arg(zeBossc->getName()));
+ Q_EMIT problemDetected(QString("For \"%1\" : Py var %1 is not defined !").arg(zeBossc->getName()));
return false;
}
if(!PyList_Check(item))
{
- emit problemDetected(QString("For \"%1\" : Py var %1 must be a list !").arg(zeBossc->getName()));
+ Q_EMIT problemDetected(QString("For \"%1\" : Py var %1 must be a list !").arg(zeBossc->getName()));
return false;
}
sz=PyList_Size(item);
PyObject *val(PyList_GetItem(item,i));
if(!PyFloat_Check(val))
{
- emit problemDetected(QString("For \"%1\" : At pos %2 of python list, it is not a float !").arg(zeBossc->getName()).arg(i));
+ Q_EMIT problemDetected(QString("For \"%1\" : At pos %2 of python list, it is not a float !").arg(zeBossc->getName()).arg(i));
return false;
}
_vect[i]=PyFloat_AS_DOUBLE(val);
QVBoxLayout *verticalLayout(new QVBoxLayout(this));
_textEdit=new YDFXGUISeqSetterT(this); verticalLayout->addWidget(_textEdit);
_push=new YDFXGUISeqSetterP(this); verticalLayout->addWidget(_push);
- _textEdit->setText(QString("import math\n%1=[math.sqrt(float(elt)+0.) for elt in xrange(4)]").arg(name));
+ _textEdit->setText(QString("import math\n%1=[math.sqrt(float(elt)+0.) for elt in range(4)]").arg(name));
_textEdit->hide();
_push->hide();
}
connect(_combo,SIGNAL(currentIndexChanged(int)),this,SLOT(typeOfAssignmentChanged(int)));
horizontalLayout->addWidget(_setter);
_combo->setCurrentIndex(0);
- emit _combo->currentIndexChanged(0);//to be sure to sync widgets
+ Q_EMIT _combo->currentIndexChanged(0);//to be sure to sync widgets
}
void YDFXGUISeqLine::loadState(const QMap<QString,QString>& state)
{
int sz;
bool verdict(checkConsistency(sz));
- emit configurationIsOK(verdict);
+ Q_EMIT configurationIsOK(verdict);
}
void YDFXGUISeqInitEff::applyOnEFX()
refSz=locSz;
if(locSz!=refSz)
{
- emit line->setter()->problemDetected(QString("Var %1 does not have the same number of elts than others !").arg(line->getName()));
+ Q_EMIT line->setter()->problemDetected(QString("Var %1 does not have the same number of elts than others !").arg(line->getName()));
return false;
}
}