#include <Python.h>
-#define PY_ARRAY_UNIQUE_SYMBOL CURVEPLOT_ARRAY_API // see initializeCurvePlot()
+// see https://docs.scipy.org/doc/numpy/reference/c-api.array.html?highlight=import_array
+// and https://docs.scipy.org/doc/numpy-1.15.0/reference/c-api.deprecations.html
+#define PY_ARRAY_UNIQUE_SYMBOL CURVEPLOT_ARRAY_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/ndarraytypes.h>
#include <numpy/ndarrayobject.h>
/**
* To be called before doing anything
*/
- void InitializeCurvePlot()
+ void* InitializeCurvePlot()
{
PyLockWrapper lock;
// TODO: discuss where the below should really happen:
// doc: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#importing-the-api
- import_array(); // a macro really!
+ import_array(); // a macro really which contains a return
+ return NULL;
}
class ColumnVector::Internal
PyObject_CallMethod((PyObject *)_impl->_npArray, (char *)"__str__", NULL)
);
// Now extract the returned string
- if(!PyString_Check(ret_py))
+ if(!PyUnicode_Check(ret_py))
throw Exception("CurvePlot::toStdString(): Unexpected returned type!");
- ret_str = std::string(PyString_AsString(ret_py));
+ Py_ssize_t size;
+ char *ptr = PyUnicode_AsUTF8AndSize(ret_py, &size);
+ ret_str = std::string(ptr);
}
return ret_str;
}
CurvePlot::CurvePlot(bool test_mode)
{
- // TODO: do use an intermediate variable '__cont', but use directly Py***CallMethod()
+ // TODO: do not use an intermediate variable '__cont', but use directly Py***CallMethod()
_impl = new Internal();
{
PyLockWrapper lock;
std::string code;
if (test_mode)
- code = std::string("import curveplot; from SalomePyQt_MockUp import SalomePyQt;") +
+ code = std::string("import curveplot; from curveplot.SalomePyQt_MockUp import SalomePyQt;") +
std::string("__cont=curveplot.PlotController.GetInstance(sgPyQt=SalomePyQt())");
else
code = std::string("import curveplot;")+
if(!PyTuple_Check(ret))
throw Exception("CurvePlot::AddCurve(): Unexpected returned type!");
PyObject * o1 = PyTuple_GetItem(ret, 0);
- if (!PyInt_Check(o1))
+ if (!PyLong_Check(o1))
throw Exception("CurvePlot::AddCurve(): Unexpected returned type!");
- PlotID curveId = PyInt_AsLong(o1);
+ PlotID curveId = PyLong_AsLong(o1);
PyObject * o2 = PyTuple_GetItem(ret, 1);
- if (!PyInt_Check(o2))
+ if (!PyLong_Check(o2))
throw Exception("CurvePlot::AddCurve(): Unexpected returned type!");
- plot_set_id = PyInt_AsLong(o2);
+ plot_set_id = PyLong_AsLong(o2);
return curveId;
}
// Author : Adrien BRUNETON
//
+#include <PyInterp_Utils.h> // GUI - must come first to avoid conflict on the token "slots" defined in both Qt and Python ...
+
#include "test_curveplot.hxx"
-#include <PyInterp_Utils.h> // GUI
#include <iostream>
#include <vector>
#include "CurvePlot.hxx"
std::cout << "setting X label " << CurvePlot::SetXLabel("tôtô") << std::endl;
}
+/*!
+ * Similar to: SUIT_PYTHON::init_python() from GUI
+ * or KERNEL_PYTHON::init_python() from KERNEL
+ */
void initPython()
{
if (!Py_IsInitialized()){
// Python is not initialized
Py_Initialize(); // Initialize the interpreter
- PyEval_InitThreads(); // Create (and acquire) the Python global interpreter lock (GIL)
- PyEval_ReleaseLock();
+ PyRun_SimpleString("import threading\n");
+
+ PyThreadState *pts = PyGILState_GetThisThreadState();
+ PyEval_ReleaseThread(pts);
}
}
mw.resize((int)(dw->width()*0.25), (int)(dw->height()*0.7));
mw.show();
- initPython();
+ initPython(); // mimic SALOME Python's initialisation.
InitializeCurvePlot();
{