Fix calling GUI methods from script thread
This commit is contained in:
+15
-14
@@ -6,13 +6,14 @@
|
||||
#include "loadrunable.h"
|
||||
#include "rawimage.h"
|
||||
#include "loadrunable.h"
|
||||
#include "batchprocessing.h"
|
||||
#include <fitsio2.h>
|
||||
#include "libXISF/libxisf.h"
|
||||
|
||||
namespace Script
|
||||
{
|
||||
|
||||
ScriptEngine::ScriptEngine(QDialog *parent)
|
||||
ScriptEngine::ScriptEngine(BatchProcessing *parent)
|
||||
: _jsEngine(new QJSEngine(this))
|
||||
, _database(new Database(this))
|
||||
, _parent(parent)
|
||||
@@ -91,30 +92,30 @@ void ScriptEngine::sync()
|
||||
|
||||
QJSValue ScriptEngine::getString(const QString &label, const QString &text) const
|
||||
{
|
||||
bool ok = false;
|
||||
QString ret = QInputDialog::getText(_parent, tr("Enter text"), label, QLineEdit::Normal, text, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getString", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(QString, text));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getInt(const QString &label, int value)
|
||||
{
|
||||
bool ok = false;
|
||||
int ret = QInputDialog::getInt(_parent, tr("Enter integer number"), label, value, INT_MIN, INT_MAX, 1, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getInt", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(int, value));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getFloat(const QString &label, double value, int decimals) const
|
||||
{
|
||||
bool ok = false;
|
||||
double ret = QInputDialog::getDouble(_parent, tr("Enter float number"), label, value, -INFINITY, INFINITY, decimals, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getFloat", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(double, value), Q_ARG(int, decimals));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getItem(const QStringList &items, const QString &label, int current) const
|
||||
{
|
||||
bool ok = false;
|
||||
QString ret = QInputDialog::getItem(_parent, tr("Select item"), label, items, current, false, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getItem", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QStringList, items), Q_ARG(QString, label), Q_ARG(int, current));
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async)
|
||||
@@ -565,7 +566,7 @@ QJSValue File::stats()
|
||||
return _stats;
|
||||
}
|
||||
|
||||
ScriptEngineThread::ScriptEngineThread(QDialog *parent) : QObject(parent)
|
||||
ScriptEngineThread::ScriptEngineThread(BatchProcessing *parent) : QObject(parent)
|
||||
{
|
||||
_thread = new QThread();
|
||||
_thread->setObjectName("ScriptEngine");
|
||||
|
||||
Reference in New Issue
Block a user