mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4528 Fix script paths and adding new scripts
This commit is contained in:
parent
7c30af62c2
commit
92bc71d934
@ -5,7 +5,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicDeleteScriptPathFeature.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicEditScriptFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicEditScriptFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptForCasesFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptForCasesFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicNewScriptFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicNewOctaveScriptFeature.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicNewPythonScriptFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicScriptFeatureImpl.h
|
${CMAKE_CURRENT_LIST_DIR}/RicScriptFeatureImpl.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicRefreshScriptsFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicRefreshScriptsFeature.h
|
||||||
)
|
)
|
||||||
@ -16,7 +17,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicDeleteScriptPathFeature.cpp
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicEditScriptFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicEditScriptFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptForCasesFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicExecuteScriptForCasesFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicNewScriptFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicNewOctaveScriptFeature.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicNewPythonScriptFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicScriptFeatureImpl.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicScriptFeatureImpl.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicRefreshScriptsFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicRefreshScriptsFeature.cpp
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RicNewScriptFeature.h"
|
#include "RicNewOctaveScriptFeature.h"
|
||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
@ -38,20 +38,30 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
CAF_CMD_SOURCE_INIT(RicNewOctaveScriptFeature, "RicNewOctaveScriptFeature");
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RicNewScriptFeature::isCommandEnabled()
|
bool RicNewOctaveScriptFeature::isCommandEnabled()
|
||||||
{
|
{
|
||||||
return true;
|
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
||||||
|
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
||||||
|
if (calcScripts.size() == 1u && calcScripts.front()->scriptType() == RimCalcScript::OCTAVE)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (calcScriptCollections.size() == 1u && !calcScriptCollections.front()->directory().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
void RicNewOctaveScriptFeature::onActionTriggered(bool isChecked)
|
||||||
{
|
{
|
||||||
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
||||||
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
||||||
@ -132,7 +142,7 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicNewScriptFeature::setupActionLook(QAction* actionToSetup)
|
void RicNewOctaveScriptFeature::setupActionLook(QAction* actionToSetup)
|
||||||
{
|
{
|
||||||
actionToSetup->setText("New");
|
actionToSetup->setText("New Octave Script");
|
||||||
}
|
}
|
@ -26,7 +26,7 @@
|
|||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicNewScriptFeature : public caf::CmdFeature
|
class RicNewOctaveScriptFeature : public caf::CmdFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
@ -0,0 +1,155 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2019- Equinor ASA
|
||||||
|
// Copyright (C) 2015- Ceetron Solutions AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicNewPythonScriptFeature.h"
|
||||||
|
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
|
#include "RicRefreshScriptsFeature.h"
|
||||||
|
#include "RicScriptFeatureImpl.h"
|
||||||
|
|
||||||
|
#include "RimCalcScript.h"
|
||||||
|
#include "RimScriptCollection.h"
|
||||||
|
|
||||||
|
#include "Riu3DMainWindowTools.h"
|
||||||
|
#include "RiuTools.h"
|
||||||
|
|
||||||
|
#include "cafUtils.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
CAF_CMD_SOURCE_INIT(RicNewPythonScriptFeature, "RicNewPythonScriptFeature");
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicNewPythonScriptFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
||||||
|
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
||||||
|
if (calcScripts.size() == 1u && calcScripts.front()->scriptType() == RimCalcScript::PYTHON)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (calcScriptCollections.size() == 1u && !calcScriptCollections.front()->directory().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicNewPythonScriptFeature::onActionTriggered(bool isChecked)
|
||||||
|
{
|
||||||
|
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
||||||
|
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
||||||
|
|
||||||
|
RimCalcScript* calcScript = calcScripts.size() > 0 ? calcScripts[0] : nullptr;
|
||||||
|
RimScriptCollection* scriptColl = calcScriptCollections.size() > 0 ? calcScriptCollections[0] : nullptr;
|
||||||
|
|
||||||
|
QString fullPathNewScript;
|
||||||
|
|
||||||
|
if (calcScript)
|
||||||
|
{
|
||||||
|
QFileInfo existingScriptFileInfo(calcScript->absoluteFileName());
|
||||||
|
fullPathNewScript = existingScriptFileInfo.absolutePath();
|
||||||
|
}
|
||||||
|
else if (scriptColl)
|
||||||
|
{
|
||||||
|
fullPathNewScript = scriptColl->directory();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString fullPathFilenameNewScript;
|
||||||
|
|
||||||
|
fullPathFilenameNewScript = fullPathNewScript + "/untitled.py";
|
||||||
|
int num = 1;
|
||||||
|
while (caf::Utils::fileExists(fullPathFilenameNewScript))
|
||||||
|
{
|
||||||
|
fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".py";
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
fullPathFilenameNewScript = QInputDialog::getText(nullptr,
|
||||||
|
"Specify new script file",
|
||||||
|
"File name",
|
||||||
|
QLineEdit::Normal,
|
||||||
|
fullPathFilenameNewScript,
|
||||||
|
&ok,
|
||||||
|
RiuTools::defaultDialogFlags());
|
||||||
|
|
||||||
|
if (ok && !fullPathFilenameNewScript.isEmpty())
|
||||||
|
{
|
||||||
|
QFile file(fullPathFilenameNewScript);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(
|
||||||
|
Riu3DMainWindowTools::mainWindowWidget(), "Script editor", "Failed to create file\n" + fullPathFilenameNewScript);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RicRefreshScriptsFeature::refreshScriptFolders();
|
||||||
|
|
||||||
|
if (calcScript)
|
||||||
|
{
|
||||||
|
Riu3DMainWindowTools::selectAsCurrentItem(calcScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
QString scriptEditor = app->scriptEditorPath();
|
||||||
|
if (!scriptEditor.isEmpty())
|
||||||
|
{
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << fullPathFilenameNewScript;
|
||||||
|
|
||||||
|
QProcess* myProcess = new QProcess(this);
|
||||||
|
myProcess->start(scriptEditor, arguments);
|
||||||
|
|
||||||
|
if (!myProcess->waitForStarted(1000))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
|
||||||
|
"Script editor",
|
||||||
|
"Failed to start script editor executable\n" + scriptEditor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicNewPythonScriptFeature::setupActionLook(QAction* actionToSetup)
|
||||||
|
{
|
||||||
|
actionToSetup->setText("New Python Script");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2019- Equinor ASA
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafCmdFeature.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicNewPythonScriptFeature : public caf::CmdFeature
|
||||||
|
{
|
||||||
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Overrides
|
||||||
|
bool isCommandEnabled() override;
|
||||||
|
void onActionTriggered(bool isChecked) override;
|
||||||
|
void setupActionLook(QAction* actionToSetup) override;
|
||||||
|
};
|
@ -427,13 +427,19 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
|||||||
{
|
{
|
||||||
menuBuilder << "RicEditScriptFeature";
|
menuBuilder << "RicEditScriptFeature";
|
||||||
menuBuilder << "Separator";
|
menuBuilder << "Separator";
|
||||||
menuBuilder << "RicNewScriptFeature";
|
menuBuilder << "RicNewOctaveScriptFeature";
|
||||||
|
#ifdef ENABLE_GRPC
|
||||||
|
menuBuilder << "RicNewPythonScriptFeature";
|
||||||
|
#endif
|
||||||
menuBuilder << "Separator";
|
menuBuilder << "Separator";
|
||||||
menuBuilder << "RicExecuteScriptFeature";
|
menuBuilder << "RicExecuteScriptFeature";
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<RimScriptCollection*>(uiItem))
|
else if (dynamic_cast<RimScriptCollection*>(uiItem))
|
||||||
{
|
{
|
||||||
menuBuilder << "RicNewScriptFeature";
|
menuBuilder << "RicNewOctaveScriptFeature";
|
||||||
|
#ifdef ENABLE_GRPC
|
||||||
|
menuBuilder << "RicNewPythonScriptFeature";
|
||||||
|
#endif
|
||||||
menuBuilder << "Separator";
|
menuBuilder << "Separator";
|
||||||
menuBuilder << "RicAddScriptPathFeature";
|
menuBuilder << "RicAddScriptPathFeature";
|
||||||
menuBuilder << "RicRefreshScriptsFeature";
|
menuBuilder << "RicRefreshScriptsFeature";
|
||||||
|
Loading…
Reference in New Issue
Block a user