Commit cf327700 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

add init function in interpreter api. use it in python interpreter to

read python script defined in settings
parent 6b047bc9
......@@ -48,6 +48,7 @@ public:
public slots:
virtual QString interpret(const QString& command, int *stat) = 0;
virtual void init(void) {} ;
private:
dtkScriptInterpreterPrivate *d;
......
......@@ -69,6 +69,7 @@ dtkScriptInterpreterPython::dtkScriptInterpreterPython(QObject *parent) : dtkScr
foreach(QString path, paths.split(":", QString::SkipEmptyParts))
PyRun_SimpleString(QString("sys.path.append('%1')").arg(path).toUtf8().constData());
}
dtkScriptInterpreterPython::~dtkScriptInterpreterPython(void)
......@@ -80,6 +81,20 @@ dtkScriptInterpreterPython::~dtkScriptInterpreterPython(void)
d = NULL;
}
void dtkScriptInterpreterPython::init(void)
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "inria", "dtk-script");
settings.beginGroup("init");
QString init = settings.value("script").toString();
settings.endGroup();
if (!init.isEmpty()) {
PyRun_SimpleString(QString("execfile('%1')").arg(init).toUtf8().constData());
} else {
dtkWarn() << "no init function " ;
}
}
QString dtkScriptInterpreterPython::interpret(const QString& command, int *stat)
{
QString statement = command;
......
......@@ -28,6 +28,7 @@ public:
public slots:
DTKSCRIPT_EXPORT QString interpret(const QString& command, int *stat);
DTKSCRIPT_EXPORT void init(void);
private:
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