mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4471 Implement python script running and editor in ResInsight GUI, same as Octave.
This commit is contained in:
@@ -899,7 +899,73 @@ QStringList RiaApplication::octaveArguments() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::launchProcess(const QString& program, const QStringList& arguments)
|
||||
QProcessEnvironment RiaApplication::octaveProcessEnvironment() const
|
||||
{
|
||||
QProcessEnvironment penv = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
#ifdef WIN32
|
||||
// Octave plugins compiled by ResInsight are dependent on Qt (currently Qt 32-bit only)
|
||||
// Some Octave installations for Windows have included Qt, and some don't. To make sure these plugins always can be
|
||||
// executed, the path to octave_plugin_dependencies is added to global path
|
||||
|
||||
QString pathString = penv.value("PATH", "");
|
||||
|
||||
if (pathString == "")
|
||||
pathString = QApplication::applicationDirPath() + "\\octave_plugin_dependencies";
|
||||
else
|
||||
pathString = QApplication::applicationDirPath() + "\\octave_plugin_dependencies" + ";" + pathString;
|
||||
|
||||
penv.insert("PATH", pathString);
|
||||
#else
|
||||
// Set the LD_LIBRARY_PATH to make the octave plugins find the embedded Qt
|
||||
QString ldPath = penv.value("LD_LIBRARY_PATH", "");
|
||||
|
||||
if (ldPath == "")
|
||||
ldPath = QApplication::applicationDirPath();
|
||||
else
|
||||
ldPath = QApplication::applicationDirPath() + ":" + ldPath;
|
||||
|
||||
penv.insert("LD_LIBRARY_PATH", ldPath);
|
||||
#endif
|
||||
|
||||
return penv;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaApplication::pythonPath() const
|
||||
{
|
||||
return m_preferences->pythonExecutable();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QProcessEnvironment RiaApplication::pythonProcessEnvironment() const
|
||||
{
|
||||
QProcessEnvironment penv = QProcessEnvironment::systemEnvironment();
|
||||
penv.insert("RESINSIGHT_GRPC_PORT", QString("%1").arg(m_grpcServer->portNumber()));
|
||||
penv.insert("RESINSIGHT_EXECUTABLE", QCoreApplication::applicationFilePath());
|
||||
|
||||
QStringList ripsLocations;
|
||||
#ifdef WIN32
|
||||
ripsLocations << QCoreApplication::applicationDirPath() + "\\Python"
|
||||
<< QCoreApplication::applicationDirPath() + "\\..\\..\\Python";
|
||||
|
||||
#else
|
||||
ripsLocations << QCoreApplication::applicationDirPath() + "/Python";
|
||||
#endif
|
||||
|
||||
penv.insert("PYTHONPATH", QString("%1;%2").arg(penv.value("PYTHONPATH")).arg(ripsLocations.join(";")));
|
||||
|
||||
return penv;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::launchProcess(const QString& program, const QStringList& arguments, const QProcessEnvironment& processEnvironment)
|
||||
{
|
||||
if (m_workerProcess == nullptr)
|
||||
{
|
||||
@@ -920,34 +986,7 @@ bool RiaApplication::launchProcess(const QString& program, const QStringList& ar
|
||||
m_runningWorkerProcess = true;
|
||||
m_workerProcess = new caf::UiProcess(QCoreApplication::instance());
|
||||
|
||||
QProcessEnvironment penv = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
#ifdef WIN32
|
||||
// Octave plugins compiled by ResInsight are dependent on Qt (currently Qt 32-bit only)
|
||||
// Some Octave installations for Windows have included Qt, and some don't. To make sure these plugins always can be
|
||||
// executed, the path to octave_plugin_dependencies is added to global path
|
||||
|
||||
QString pathString = penv.value("PATH", "");
|
||||
|
||||
if (pathString == "")
|
||||
pathString = QApplication::applicationDirPath() + "\\octave_plugin_dependencies";
|
||||
else
|
||||
pathString = QApplication::applicationDirPath() + "\\octave_plugin_dependencies" + ";" + pathString;
|
||||
|
||||
penv.insert("PATH", pathString);
|
||||
#else
|
||||
// Set the LD_LIBRARY_PATH to make the octave plugins find the embedded Qt
|
||||
QString ldPath = penv.value("LD_LIBRARY_PATH", "");
|
||||
|
||||
if (ldPath == "")
|
||||
ldPath = QApplication::applicationDirPath();
|
||||
else
|
||||
ldPath = QApplication::applicationDirPath() + ":" + ldPath;
|
||||
|
||||
penv.insert("LD_LIBRARY_PATH", ldPath);
|
||||
#endif
|
||||
|
||||
m_workerProcess->setProcessEnvironment(penv);
|
||||
m_workerProcess->setProcessEnvironment(processEnvironment);
|
||||
|
||||
QCoreApplication::instance()->connect(m_workerProcess,
|
||||
SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
@@ -989,7 +1028,8 @@ bool RiaApplication::launchProcess(const QString& program, const QStringList& ar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::launchProcessForMultipleCases(const QString& program,
|
||||
const QStringList& arguments,
|
||||
const std::vector<int>& caseIds)
|
||||
const std::vector<int>& caseIds,
|
||||
const QProcessEnvironment& processEnvironment)
|
||||
{
|
||||
m_currentCaseIds.clear();
|
||||
std::copy(caseIds.begin(), caseIds.end(), std::back_inserter(m_currentCaseIds));
|
||||
@@ -997,7 +1037,7 @@ bool RiaApplication::launchProcessForMultipleCases(const QString& progr
|
||||
m_currentProgram = program;
|
||||
m_currentArguments = arguments;
|
||||
|
||||
return launchProcess(m_currentProgram, m_currentArguments);
|
||||
return launchProcess(m_currentProgram, m_currentArguments, processEnvironment);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QApplication>
|
||||
#include <QMutex>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QString>
|
||||
|
||||
#include <iostream>
|
||||
@@ -144,9 +145,13 @@ public:
|
||||
|
||||
QString octavePath() const;
|
||||
QStringList octaveArguments() const;
|
||||
QProcessEnvironment octaveProcessEnvironment() const;
|
||||
|
||||
bool launchProcess(const QString& program, const QStringList& arguments);
|
||||
bool launchProcessForMultipleCases(const QString& program, const QStringList& arguments, const std::vector<int>& caseIds);
|
||||
QString pythonPath() const;
|
||||
QProcessEnvironment pythonProcessEnvironment() const;
|
||||
|
||||
bool launchProcess(const QString& program, const QStringList& arguments, const QProcessEnvironment& processEnvironment);
|
||||
bool launchProcessForMultipleCases(const QString& program, const QStringList& arguments, const std::vector<int>& caseIds, const QProcessEnvironment& processEnvironment);
|
||||
void terminateProcess();
|
||||
void waitForProcess() const;
|
||||
|
||||
|
||||
@@ -1655,6 +1655,8 @@ void RiaGuiApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitSt
|
||||
{
|
||||
m_mainWindow->processMonitor()->stopMonitorWorkProcess();
|
||||
|
||||
QProcessEnvironment processEnvironment = m_workerProcess->processEnvironment();
|
||||
|
||||
// Execute delete later so that other slots that are hooked up
|
||||
// get a chance to run before we delete the object
|
||||
if (m_workerProcess)
|
||||
@@ -1684,7 +1686,7 @@ void RiaGuiApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitSt
|
||||
// If multiple cases are present, invoke launchProcess() which will set next current case, and run script on this case
|
||||
if (!m_currentCaseIds.empty())
|
||||
{
|
||||
launchProcess(m_currentProgram, m_currentArguments);
|
||||
launchProcess(m_currentProgram, m_currentArguments, processEnvironment);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -67,6 +67,10 @@ RiaPreferences::RiaPreferences(void)
|
||||
CAF_PDM_InitField(&octaveShowHeaderInfoWhenExecutingScripts, "octaveShowHeaderInfoWhenExecutingScripts", false, "Show Text Header When Executing Scripts", "", "", "");
|
||||
octaveShowHeaderInfoWhenExecutingScripts.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitField(&pythonExecutable, "pythonExecutable", QString("python"), "Python Executable Location", "", "", "");
|
||||
pythonExecutable.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||
pythonExecutable.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
|
||||
|
||||
CAF_PDM_InitField(&ssihubAddress, "ssihubAddress", QString("http://"), "SSIHUB Address", "", "", "");
|
||||
ssihubAddress.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
|
||||
|
||||
@@ -273,6 +277,9 @@ void RiaPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
|
||||
octaveGroup->add(&octaveExecutable);
|
||||
octaveGroup->add(&octaveShowHeaderInfoWhenExecutingScripts);
|
||||
|
||||
caf::PdmUiGroup* pythonGroup = uiOrdering.addNewGroup("Python");
|
||||
pythonGroup->add(&pythonExecutable);
|
||||
|
||||
caf::PdmUiGroup* scriptGroup = uiOrdering.addNewGroup("Script files");
|
||||
scriptGroup->add(&scriptDirectories);
|
||||
scriptGroup->add(&scriptEditorExecutable);
|
||||
|
||||
@@ -77,6 +77,8 @@ public: // Pdm Fields
|
||||
caf::PdmField<QString> octaveExecutable;
|
||||
caf::PdmField<bool> octaveShowHeaderInfoWhenExecutingScripts;
|
||||
|
||||
caf::PdmField<QString> pythonExecutable;
|
||||
|
||||
caf::PdmField<QString> ssihubAddress;
|
||||
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::MeshModeType>> defaultMeshModeType;
|
||||
|
||||
Reference in New Issue
Block a user