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

Merge branch 'hotfix/1.6.2'

parents c81b80b3 2fecb550
# ChangeLog
## version 1.6.2 - 2018-11-08
- dtkScriptInterpreterPython enables release method (for real).
## version 1.6.1 - 2018-11-08
- dtkScriptInterpreterPython enables release method.
## version 1.6.0 - 2018-11-07
......
......@@ -24,7 +24,7 @@ project(dtk)
set(dtk_VERSION_MAJOR 1)
set(dtk_VERSION_MINOR 6)
set(dtk_VERSION_PATCH 1)
set(dtk_VERSION_PATCH 2)
set(dtk_VERSION
${dtk_VERSION_MAJOR}.${dtk_VERSION_MINOR}.${dtk_VERSION_PATCH})
......
......@@ -57,9 +57,9 @@ public:
dtkScriptInterpreterPython *dtkScriptInterpreterPython::instance(void)
{
if(!s_instance)
if (!s_instance) {
s_instance = new dtkScriptInterpreterPython;
}
return s_instance;
}
......@@ -68,85 +68,82 @@ dtkScriptInterpreterPython *dtkScriptInterpreterPython::s_instance = nullptr;
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)
{
Py_Finalize();
delete d;
d = NULL;
d = nullptr;
}
void dtkScriptInterpreterPython::init(void)
{
Py_Initialize();
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");
QString init = settings.value("script").toString();
settings.endGroup();
if (!init.isEmpty()) {
PyRun_SimpleString(QString("execfile('%1')").arg(init).toUtf8().constData());
PyRun_SimpleString(qPrintable(QString("execfile('%1')").arg(init)));
} 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 statement = command;
if (command.endsWith(":")) {
if(!d->buffer.isEmpty())
if (!d->buffer.isEmpty()) {
d->buffer.append("\n");
}
d->buffer.append(command);
return "";
return QString();
}
if (!command.isEmpty() && command.startsWith(" ")) {
if(!d->buffer.isEmpty())
if (!d->buffer.isEmpty()) {
d->buffer.append("\n");
}
d->buffer.append(command);
return "";
return QString();
}
if (command.isEmpty() && !d->buffer.isEmpty()) {
if(!d->buffer.isEmpty())
if (!d->buffer.isEmpty()) {
d->buffer.append("\n");
}
statement = d->buffer;
d->buffer.clear();
}
if (statement.isEmpty())
return "";
if (statement.isEmpty()) {
return QString();
}
PyObject *module = PyImport_AddModule("__main__");
// PyRun_SimpleString(dtkScriptInterpreterPythonRedirector_define.toUtf8().constData());
switch (PyRun_SimpleString(statement.toUtf8().constData())) {
switch (PyRun_SimpleString(qPrintable(statement))) {
case 0: *stat = Status_Ok; break;
case -1: *stat = Status_Error; break;
default: break;
......@@ -154,11 +151,6 @@ QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat)
PyErr_Print();
// PyObject *redtor = PyObject_GetAttrString(module, "redirector");
// PyObject *result = PyObject_GetAttrString(redtor, "data");
// return QString(PyString_AsString(result)).simplified();
return QString();
}
......
......@@ -14,9 +14,9 @@
#pragma once
#include "dtkScriptInterpreter.h"
#include <dtkScriptExport>
class dtkScriptInterpreterPythonPrivate;
#include "dtkScriptInterpreter.h"
class DTKSCRIPT_EXPORT dtkScriptInterpreterPython : public dtkScriptInterpreter
{
......@@ -31,13 +31,14 @@ protected:
public slots:
QString interpret(const QString& command, int *stat);
void init(void);
void release(void);
private:
dtkScriptInterpreterPython(void);
~dtkScriptInterpreterPython(void);
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