Commit 8beec1e8 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Merge branch 'hotfix/1.6.2'

parents c81b80b3 2fecb550
# ChangeLog # ChangeLog
## version 1.6.2 - 2018-11-08
- dtkScriptInterpreterPython enables release method (for real).
## version 1.6.1 - 2018-11-08 ## version 1.6.1 - 2018-11-08
- dtkScriptInterpreterPython enables release method. - dtkScriptInterpreterPython enables release method.
## version 1.6.0 - 2018-11-07 ## version 1.6.0 - 2018-11-07
......
...@@ -24,7 +24,7 @@ project(dtk) ...@@ -24,7 +24,7 @@ project(dtk)
set(dtk_VERSION_MAJOR 1) set(dtk_VERSION_MAJOR 1)
set(dtk_VERSION_MINOR 6) set(dtk_VERSION_MINOR 6)
set(dtk_VERSION_PATCH 1) set(dtk_VERSION_PATCH 2)
set(dtk_VERSION set(dtk_VERSION
${dtk_VERSION_MAJOR}.${dtk_VERSION_MINOR}.${dtk_VERSION_PATCH}) ${dtk_VERSION_MAJOR}.${dtk_VERSION_MINOR}.${dtk_VERSION_PATCH})
......
...@@ -57,9 +57,9 @@ public: ...@@ -57,9 +57,9 @@ public:
dtkScriptInterpreterPython *dtkScriptInterpreterPython::instance(void) dtkScriptInterpreterPython *dtkScriptInterpreterPython::instance(void)
{ {
if(!s_instance) if (!s_instance) {
s_instance = new dtkScriptInterpreterPython; s_instance = new dtkScriptInterpreterPython;
}
return s_instance; return s_instance;
} }
...@@ -68,85 +68,82 @@ dtkScriptInterpreterPython *dtkScriptInterpreterPython::s_instance = nullptr; ...@@ -68,85 +68,82 @@ dtkScriptInterpreterPython *dtkScriptInterpreterPython::s_instance = nullptr;
dtkScriptInterpreterPython::dtkScriptInterpreterPython(void) : dtkScriptInterpreter(), d(new dtkScriptInterpreterPythonPrivate) dtkScriptInterpreterPython::dtkScriptInterpreterPython(void) : dtkScriptInterpreter(), d(new dtkScriptInterpreterPythonPrivate)
{ {
Py_Initialize();
// PyRun_SimpleString(dtkScriptInterpreterPythonRedirector_declare.toUtf8().constData());
QString paths;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "inria", "dtk-script");
settings.beginGroup("modules");
paths = settings.value("path").toString();
settings.endGroup();
PyRun_SimpleString("import sys");
foreach(QString path, paths.split(":", QString::SkipEmptyParts))
PyRun_SimpleString(QString("sys.path.append('%1')").arg(path).toUtf8().constData());
} }
dtkScriptInterpreterPython::~dtkScriptInterpreterPython(void) dtkScriptInterpreterPython::~dtkScriptInterpreterPython(void)
{ {
Py_Finalize();
delete d; delete d;
d = nullptr;
d = NULL;
} }
void dtkScriptInterpreterPython::init(void) void dtkScriptInterpreterPython::init(void)
{ {
Py_Initialize();
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "inria", "dtk-script"); QSettings settings(QSettings::IniFormat, QSettings::UserScope, "inria", "dtk-script");
settings.beginGroup("modules");
QString paths = settings.value("path").toString();
settings.endGroup();
PyRun_SimpleString("import sys");
auto path_list = paths.split(":", QString::SkipEmptyParts);
for (QString path : path_list) {
PyRun_SimpleString(qPrintable(QString("sys.path.append('%1')").arg(path)));
}
settings.beginGroup("init"); settings.beginGroup("init");
QString init = settings.value("script").toString(); QString init = settings.value("script").toString();
settings.endGroup(); settings.endGroup();
if (!init.isEmpty()) { if (!init.isEmpty()) {
PyRun_SimpleString(QString("execfile('%1')").arg(init).toUtf8().constData()); PyRun_SimpleString(qPrintable(QString("execfile('%1')").arg(init)));
} else { } else {
dtkWarn() << "no init function " ; dtkWarn() << Q_FUNC_INFO << "No init function";
} }
} }
void dtkScriptInterpreterPython::release(void)
{
Py_Finalize();
}
QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat) QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat)
{ {
QString statement = command; QString statement = command;
if (command.endsWith(":")) { if (command.endsWith(":")) {
if(!d->buffer.isEmpty()) if (!d->buffer.isEmpty()) {
d->buffer.append("\n"); d->buffer.append("\n");
}
d->buffer.append(command); d->buffer.append(command);
return QString();
return "";
} }
if (!command.isEmpty() && command.startsWith(" ")) { if (!command.isEmpty() && command.startsWith(" ")) {
if(!d->buffer.isEmpty()) if (!d->buffer.isEmpty()) {
d->buffer.append("\n"); d->buffer.append("\n");
}
d->buffer.append(command); d->buffer.append(command);
return QString();
return "";
} }
if (command.isEmpty() && !d->buffer.isEmpty()) { if (command.isEmpty() && !d->buffer.isEmpty()) {
if(!d->buffer.isEmpty()) if (!d->buffer.isEmpty()) {
d->buffer.append("\n"); d->buffer.append("\n");
}
statement = d->buffer; statement = d->buffer;
d->buffer.clear(); d->buffer.clear();
} }
if (statement.isEmpty()) if (statement.isEmpty()) {
return ""; return QString();
}
PyObject *module = PyImport_AddModule("__main__"); PyObject *module = PyImport_AddModule("__main__");
// PyRun_SimpleString(dtkScriptInterpreterPythonRedirector_define.toUtf8().constData()); switch (PyRun_SimpleString(qPrintable(statement))) {
switch (PyRun_SimpleString(statement.toUtf8().constData())) {
case 0: *stat = Status_Ok; break; case 0: *stat = Status_Ok; break;
case -1: *stat = Status_Error; break; case -1: *stat = Status_Error; break;
default: break; default: break;
...@@ -154,11 +151,6 @@ QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat) ...@@ -154,11 +151,6 @@ QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat)
PyErr_Print(); PyErr_Print();
// PyObject *redtor = PyObject_GetAttrString(module, "redirector");
// PyObject *result = PyObject_GetAttrString(redtor, "data");
// return QString(PyString_AsString(result)).simplified();
return QString(); return QString();
} }
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
#pragma once #pragma once
#include "dtkScriptInterpreter.h" #include <dtkScriptExport>
class dtkScriptInterpreterPythonPrivate; #include "dtkScriptInterpreter.h"
class DTKSCRIPT_EXPORT dtkScriptInterpreterPython : public dtkScriptInterpreter class DTKSCRIPT_EXPORT dtkScriptInterpreterPython : public dtkScriptInterpreter
{ {
...@@ -31,13 +31,14 @@ protected: ...@@ -31,13 +31,14 @@ protected:
public slots: public slots:
QString interpret(const QString& command, int *stat); QString interpret(const QString& command, int *stat);
void init(void); void init(void);
void release(void);
private: private:
dtkScriptInterpreterPython(void); dtkScriptInterpreterPython(void);
~dtkScriptInterpreterPython(void); ~dtkScriptInterpreterPython(void);
private: private:
dtkScriptInterpreterPythonPrivate *d; class dtkScriptInterpreterPythonPrivate *d;
}; };
// //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment