From af4be850cb12c2049a652d1a26fb33c0e9d498a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Sun, 16 Jun 2024 00:14:51 +0200 Subject: [PATCH] Embeded scripts --- CMakeLists.txt | 1 + batchprocessing.cpp | 11 ++++++++++- scripts/convert to XISF | 16 ++++++++++++++++ scripts/example script | 29 +++++++++++++++++++++++++++++ scripts/scripts.qrc | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 scripts/convert to XISF create mode 100644 scripts/example script create mode 100644 scripts/scripts.qrc diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b76e38..c727415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ endif(COLOR_MANAGMENT) qt_add_resources(TENMON_SRC resources/resources.qrc) qt_add_resources(TENMON_SRC shaders/shaders.qrc) +qt_add_resources(TENMON_SRC scripts/scripts.qrc) if(WIN32) list(APPEND TENMON_SRC resources/icon.rc) set(tenmon_ICON "") diff --git a/batchprocessing.cpp b/batchprocessing.cpp index 53e2eb2..f0aa0d3 100644 --- a/batchprocessing.cpp +++ b/batchprocessing.cpp @@ -57,7 +57,10 @@ void BatchProcessing::scanScriptDir() _ui->scriptsList->clear(); QDir dir(_scriptBasePath); + QDir embededDir(":/scripts"); QStringList scripts = dir.entryList(QDir::Files | QDir::Readable); + scripts.append(embededDir.entryList(QDir::Files)); + scripts.removeDuplicates(); _ui->scriptsList->addItems(scripts); int idx = scripts.indexOf(current); @@ -207,7 +210,13 @@ void BatchProcessing::runScript() QFileInfo outDir(_ui->outputPath->text()); if(outDir.exists() && outDir.isWritable()) { - _engineThread->setParams(_scriptBasePath + selectedItems.first()->text(), scanDirectories(paths), _ui->outputPath->text()); + QString script = selectedItems.first()->text(); + if(QDir(_scriptBasePath).exists(script)) + script = _scriptBasePath + script; + else + script = ":/scripts/" + script; + + _engineThread->setParams(script, scanDirectories(paths), _ui->outputPath->text()); _engineThread->start(); _ui->startButton->setEnabled(false); _ui->stopButton->setEnabled(true); diff --git a/scripts/convert to XISF b/scripts/convert to XISF new file mode 100644 index 0000000..5c02c34 --- /dev/null +++ b/scripts/convert to XISF @@ -0,0 +1,16 @@ +if(files.length == 0) +{ + core.files("No files"); + throw ""; +} + +let compression = {"compressionType": "zstd+sh"}; + +for(file of files) +{ + if(file.suffix() == "fits" || file.suffix() == "fit") + { + core.log("Converting " + file.fileName()); + convertedFiles.push(file.convertAsync(file.relativeFilePath(), "XISF", compression)); + } +} diff --git a/scripts/example script b/scripts/example script new file mode 100644 index 0000000..93d886f --- /dev/null +++ b/scripts/example script @@ -0,0 +1,29 @@ +// how to get input from user +let d = core.getFloat("Getting float value"); +let i = core.getInt("Getting integer value"); +let s = core.getString("Getting string value"); + +// print user input +core.log("Your input " + d + " " + i + " " + s); + +for(file of files) +{ + if(file.suffix() == "fits" || file.suffix() == "fit" || file.suffix() == "xisf") + { + let keywords = file.fitsKeywords(); + let item = core.getItem(keywords); + core.log("You selected keyword " + item); core.log(file.fitsKeywords()); + + // some sample files + core.log("fileName() " + file.fileName()); + core.log("absoluteFilePath() " + file.absoluteFilePath()); + core.log("absolutePath() " + file.absolutePath()); + core.log("relativeFilePath() " + file.relativeFilePath()); + core.log("relativePath() " + file.relativePath()); + core.log("baseName() " + file.baseName()); + core.log("completeBase() " + file.completeBaseName()); + core.log("suffix() " + file.suffix()); + core.log("size() " + file.size()); + break; + } +} diff --git a/scripts/scripts.qrc b/scripts/scripts.qrc new file mode 100644 index 0000000..ba5272c --- /dev/null +++ b/scripts/scripts.qrc @@ -0,0 +1,6 @@ + + + example script + convert to XISF + +