Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the description.json alongside the script #2201

Merged
merged 3 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tomviz/FxiWorkflowWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,13 @@ class FxiWorkflowWidget::Internal : public QObject
QJsonValueRef parameterNode = parameters[i];
QJsonObject parameterObject = parameterNode.toObject();
QJsonValueRef nameValue = parameterObject["name"];
auto tagValue = parameterObject["tag"];
if (knownParameters.contains(nameValue.toString())) {
// This parameter is already known. Remove it.
parameters.removeAt(i);
} else if (tagValue.toString("") != "") {
// Not the right tag. Remove it.
parameters.removeAt(i);
} else {
i += 1;
}
Expand Down
49 changes: 47 additions & 2 deletions tomviz/operators/OperatorPython.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QMessageBox>
#include <QPointer>
#include <QtDebug>

Expand Down Expand Up @@ -127,15 +128,59 @@ class EditPythonOperatorWidget : public tomviz::EditOperatorWidget
}

if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "Failed to open file: " << name;
auto msg = QString("Failed to open file: %1").arg(name);
QMessageBox::critical(this, "Failed to save script", msg);
qDebug() << msg;
return;
}

if (file.write(m_ui.script->toPlainText().toLatin1()) == -1) {
qDebug() << "Failed to write to file: " << name;
auto msg = QString("Failed to write to file: %1").arg(name);
QMessageBox::critical(this, "Failed to save script", msg);
qDebug() << msg;
file.close();
return;
}

file.close();

// If there is a JSON description, and the file does not exist,
// write that out too.
if (m_op->JSONDescription().isEmpty()) {
return;
}

// Use the same name with a ".json" extension.
QFileInfo info(name);
auto descriptionFilename = info.path() + "/" + info.baseName() + ".json";
QFile descriptionFile(descriptionFilename, this);
if (descriptionFile.exists()) {
// Check if the user wants to overwrite it.
auto title = QString("Overwrite description file?");
auto msg =
QString("%1 exists.\n\nOverwrite it?").arg(descriptionFilename);
auto response = QMessageBox::question(this, title, msg);
if (response == QMessageBox::No) {
// Do not overwrite
return;
}
}

if (!descriptionFile.open(QIODevice::WriteOnly)) {
auto msg = QString("Failed to open %1").arg(descriptionFilename);
QMessageBox::critical(this, "Failed to save description", msg);
qDebug() << msg;
return;
}

if (descriptionFile.write(m_op->JSONDescription().toLatin1()) == -1) {
auto msg =
QString("Failed to write to file: %1").arg(descriptionFilename);
QMessageBox::critical(this, "Failed to save description", msg);
qDebug() << msg;
};

descriptionFile.close();
}

private:
Expand Down