Fix calling GUI methods from script thread
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -235,3 +236,31 @@ void BatchProcessing::newMessage(const QString &message, bool error)
|
|||||||
else _ui->log->setTextColor(_textColor);
|
else _ui->log->setTextColor(_textColor);
|
||||||
_ui->log->append(message);
|
_ui->log->append(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJSValue BatchProcessing::getString(const QString &label, const QString &text)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
QString ret = QInputDialog::getText(this, tr("Enter text"), label, QLineEdit::Normal, text, &ok);
|
||||||
|
return ok ? ret : QJSValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue BatchProcessing::getInt(const QString &label, int value)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
int ret = QInputDialog::getInt(this, tr("Enter integer number"), label, value, INT_MIN, INT_MAX, 1, &ok);
|
||||||
|
return ok ? ret : QJSValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue BatchProcessing::getFloat(const QString &label, double value, int decimals)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
double ret = QInputDialog::getDouble(this, tr("Enter float number"), label, value, -INFINITY, INFINITY, decimals, &ok);
|
||||||
|
return ok ? ret : QJSValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue BatchProcessing::getItem(const QStringList &items, const QString &label, int current)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
QString ret = QInputDialog::getItem(this, tr("Select item"), label, items, current, false, &ok);
|
||||||
|
return ok ? ret : QJSValue();
|
||||||
|
}
|
||||||
|
|||||||
+6
-1
@@ -9,6 +9,7 @@ namespace Ui { class BatchProcessing; }
|
|||||||
|
|
||||||
class BatchProcessing : public QDialog
|
class BatchProcessing : public QDialog
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
Ui::BatchProcessing *_ui;
|
Ui::BatchProcessing *_ui;
|
||||||
QString _scriptBasePath;
|
QString _scriptBasePath;
|
||||||
QFileSystemWatcher _fileWatcher;
|
QFileSystemWatcher _fileWatcher;
|
||||||
@@ -22,7 +23,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
public slots:
|
public slots:
|
||||||
void scriptDirChanged();
|
|
||||||
void addFiles();
|
void addFiles();
|
||||||
void addDir();
|
void addDir();
|
||||||
void removePath();
|
void removePath();
|
||||||
@@ -33,6 +33,11 @@ public slots:
|
|||||||
void stopScript();
|
void stopScript();
|
||||||
void scriptFinished();
|
void scriptFinished();
|
||||||
void newMessage(const QString &message, bool error);
|
void newMessage(const QString &message, bool error);
|
||||||
|
|
||||||
|
QJSValue getString(const QString &label, const QString &text);
|
||||||
|
QJSValue getInt(const QString &label, int value);
|
||||||
|
QJSValue getFloat(const QString &label, double value, int decimals);
|
||||||
|
QJSValue getItem(const QStringList &items, const QString &label, int current);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BATCHPROCESSING_H
|
#endif // BATCHPROCESSING_H
|
||||||
|
|||||||
+5
-3
@@ -615,7 +615,7 @@ void ConvertRunable::run()
|
|||||||
|
|
||||||
if(rawimage)
|
if(rawimage)
|
||||||
{
|
{
|
||||||
if(m_format == "XISF")
|
if(m_format == "xisf")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -674,9 +674,10 @@ void ConvertRunable::run()
|
|||||||
{
|
{
|
||||||
qDebug() << "Failed to save XISF image" << err.what();
|
qDebug() << "Failed to save XISF image" << err.what();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_format == "FITS")
|
if(m_format == "fits")
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
fitsfile *fw;
|
fitsfile *fw;
|
||||||
@@ -691,9 +692,10 @@ void ConvertRunable::run()
|
|||||||
}
|
}
|
||||||
writeFITSImage(fw, rawimage, imageinfo);
|
writeFITSImage(fw, rawimage, imageinfo);
|
||||||
fits_close_file(fw, &status);
|
fits_close_file(fw, &status);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_format == "QIMAGE")
|
// if nothing else try QImage
|
||||||
{
|
{
|
||||||
QImage::Format format = QImage::Format_Invalid;
|
QImage::Format format = QImage::Format_Invalid;
|
||||||
int width = rawimage->widthBytes();
|
int width = rawimage->widthBytes();
|
||||||
|
|||||||
+15
-14
@@ -6,13 +6,14 @@
|
|||||||
#include "loadrunable.h"
|
#include "loadrunable.h"
|
||||||
#include "rawimage.h"
|
#include "rawimage.h"
|
||||||
#include "loadrunable.h"
|
#include "loadrunable.h"
|
||||||
|
#include "batchprocessing.h"
|
||||||
#include <fitsio2.h>
|
#include <fitsio2.h>
|
||||||
#include "libXISF/libxisf.h"
|
#include "libXISF/libxisf.h"
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
{
|
{
|
||||||
|
|
||||||
ScriptEngine::ScriptEngine(QDialog *parent)
|
ScriptEngine::ScriptEngine(BatchProcessing *parent)
|
||||||
: _jsEngine(new QJSEngine(this))
|
: _jsEngine(new QJSEngine(this))
|
||||||
, _database(new Database(this))
|
, _database(new Database(this))
|
||||||
, _parent(parent)
|
, _parent(parent)
|
||||||
@@ -91,30 +92,30 @@ void ScriptEngine::sync()
|
|||||||
|
|
||||||
QJSValue ScriptEngine::getString(const QString &label, const QString &text) const
|
QJSValue ScriptEngine::getString(const QString &label, const QString &text) const
|
||||||
{
|
{
|
||||||
bool ok = false;
|
QJSValue ret;
|
||||||
QString ret = QInputDialog::getText(_parent, tr("Enter text"), label, QLineEdit::Normal, text, &ok);
|
QMetaObject::invokeMethod(_parent, "getString", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(QString, text));
|
||||||
return ok ? ret : QJSValue();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJSValue ScriptEngine::getInt(const QString &label, int value)
|
QJSValue ScriptEngine::getInt(const QString &label, int value)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
QJSValue ret;
|
||||||
int ret = QInputDialog::getInt(_parent, tr("Enter integer number"), label, value, INT_MIN, INT_MAX, 1, &ok);
|
QMetaObject::invokeMethod(_parent, "getInt", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(int, value));
|
||||||
return ok ? ret : QJSValue();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJSValue ScriptEngine::getFloat(const QString &label, double value, int decimals) const
|
QJSValue ScriptEngine::getFloat(const QString &label, double value, int decimals) const
|
||||||
{
|
{
|
||||||
bool ok = false;
|
QJSValue ret;
|
||||||
double ret = QInputDialog::getDouble(_parent, tr("Enter float number"), label, value, -INFINITY, INFINITY, decimals, &ok);
|
QMetaObject::invokeMethod(_parent, "getFloat", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(double, value), Q_ARG(int, decimals));
|
||||||
return ok ? ret : QJSValue();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJSValue ScriptEngine::getItem(const QStringList &items, const QString &label, int current) const
|
QJSValue ScriptEngine::getItem(const QStringList &items, const QString &label, int current) const
|
||||||
{
|
{
|
||||||
bool ok = false;
|
QJSValue ret;
|
||||||
QString ret = QInputDialog::getItem(_parent, tr("Select item"), label, items, current, false, &ok);
|
QMetaObject::invokeMethod(_parent, "getItem", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QStringList, items), Q_ARG(QString, label), Q_ARG(int, current));
|
||||||
return ok ? ret : QJSValue();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async)
|
bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async)
|
||||||
@@ -565,7 +566,7 @@ QJSValue File::stats()
|
|||||||
return _stats;
|
return _stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngineThread::ScriptEngineThread(QDialog *parent) : QObject(parent)
|
ScriptEngineThread::ScriptEngineThread(BatchProcessing *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
_thread = new QThread();
|
_thread = new QThread();
|
||||||
_thread->setObjectName("ScriptEngine");
|
_thread->setObjectName("ScriptEngine");
|
||||||
|
|||||||
+5
-3
@@ -10,6 +10,8 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "imageinfo.h"
|
#include "imageinfo.h"
|
||||||
|
|
||||||
|
class BatchProcessing;
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -20,14 +22,14 @@ class ScriptEngine : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QJSEngine *_jsEngine;
|
QJSEngine *_jsEngine;
|
||||||
Database *_database;
|
Database *_database;
|
||||||
QDialog *_parent;
|
BatchProcessing *_parent;
|
||||||
QThreadPool *_pool;
|
QThreadPool *_pool;
|
||||||
QSemaphore _semaphore;
|
QSemaphore _semaphore;
|
||||||
QString _scriptPath;
|
QString _scriptPath;
|
||||||
QString _outputDir;
|
QString _outputDir;
|
||||||
QList<QPair<QString, QString>> _paths;
|
QList<QPair<QString, QString>> _paths;
|
||||||
public:
|
public:
|
||||||
explicit ScriptEngine(QDialog *parent = nullptr);
|
explicit ScriptEngine(BatchProcessing *parent = nullptr);
|
||||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||||
void reportError(const QString &message);
|
void reportError(const QString &message);
|
||||||
const QString& outputDir() const;
|
const QString& outputDir() const;
|
||||||
@@ -59,7 +61,7 @@ class ScriptEngineThread : public QObject
|
|||||||
QThread *_thread;
|
QThread *_thread;
|
||||||
ScriptEngine *_engine;
|
ScriptEngine *_engine;
|
||||||
public:
|
public:
|
||||||
ScriptEngineThread(QDialog *parent = nullptr);
|
ScriptEngineThread(BatchProcessing *parent = nullptr);
|
||||||
~ScriptEngineThread();
|
~ScriptEngineThread();
|
||||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||||
void start();
|
void start();
|
||||||
|
|||||||
Reference in New Issue
Block a user