From 285fac479612e886db4b47e36a317a3d96904d8a Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 18 Oct 2006 11:23:18 +0000 Subject: [PATCH] Imp PAL13554 : -file option of runSalome --- src/PythonConsole/PythonConsole_PyEditor.cxx | 10 ++++- src/PythonConsole/PythonConsole_PyEditor.h | 7 ++-- src/SalomeApp/SalomeApp_Application.cxx | 40 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index 04d136463..e32bf03ee 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -148,8 +148,10 @@ void PythonConsole_PyEditor::setText(QString s) void PythonConsole_PyEditor::exec( const QString& command ) { // Some interactive command is being executed in this editor -> do nothing - if ( isReadOnly() ) + if ( isReadOnly() ) { + myQueue.push_back( command ); return; + } int para=paragraphs()-1; removeParagraph( para ); _currentPrompt = READY_PROMPT; @@ -680,6 +682,12 @@ void PythonConsole_PyEditor::customEvent(QCustomEvent* e) setReadOnly( false ); _isInHistory = false; + + if ( e->type() == PyInterp_Event::OK && myQueue.count() > 0 ) { + QString nextcmd = myQueue[0]; + myQueue.pop_front(); + exec( nextcmd ); + } } /*! diff --git a/src/PythonConsole/PythonConsole_PyEditor.h b/src/PythonConsole/PythonConsole_PyEditor.h index 004b40021..d362b1f8c 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.h +++ b/src/PythonConsole/PythonConsole_PyEditor.h @@ -69,9 +69,10 @@ private: PyInterp_base* myInterp; - QString myBanner; - QString myOutput; - QString myError; + QString myBanner; + QString myOutput; + QString myError; + QStringList myQueue; }; #endif diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index d8b2ffc7c..d0912a6eb 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -151,6 +151,46 @@ void SalomeApp_Application::start() LightApp_Application::start(); SalomeApp_EventFilter::Init(); + + static bool isFirst = true; + if ( isFirst ) { + isFirst = false; + QString hdffile; + QStringList pyfiles; + for (int i = 1; i < qApp->argc(); i++) { + QRegExp rx("--test=(.+)"); + if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 0 ) { + QStringList files = QStringList::split(",",rx.capturedTexts()[1],false); + for (uint j = 0; j < files.count(); j++ ) { + QFileInfo fi( files[j] ); + QString extension = fi.extension( false ).lower(); + if ( extension == "hdf" && fi.exists() ) + hdffile = fi.absFilePath(); + else if ( extension == "py" || extension == "" ) + pyfiles.append( fi.baseName( true ) ); + } + } + } + if ( !hdffile.isEmpty() ) // open hdf file given as parameter + onOpenDoc( hdffile ); + else if ( pyfiles.count() > 0 ) // create new study + onNewDoc(); + // import python scripts + if ( pyfiles.count() > 0 && activeStudy() ) { + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( appStudy ) { + _PTR(Study) aStudy = appStudy->studyDS(); + if ( !aStudy->GetProperties()->IsLocked() ) { + for ( uint i = 0; i < pyfiles.count(); i++ ) { + QString command = QString( "import %1" ).arg( pyfiles[i] ); + PythonConsole* pyConsole = pythonConsole(); + if ( pyConsole ) + pyConsole->exec( command ); + } + } + } + } + } } /*!Create actions:*/ -- 2.39.2