From 8ebc6987c99c300ca88473c8dc33bd2c7097ce4f Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 14 Aug 2007 07:35:06 +0000 Subject: [PATCH] NPAL16628: Pb with KDE desktop and Salome option --execute. Ensure the application is registered in the session before python scripts execution. --- src/SUIT/SUIT_Application.cxx | 11 +++-- src/SUIT/SUIT_Application.h | 6 +++ src/SUIT/SUIT_Session.cxx | 2 + src/SalomeApp/SalomeApp_Application.cxx | 66 +++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Application.h | 2 + 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index a4a21d862..0be1fbf72 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -34,11 +34,12 @@ Default constructor */ SUIT_Application::SUIT_Application() -: QObject( 0 ), -myStudy( 0 ), -myDesktop( 0 ), -myStatusLabel( 0 ) -{ + : QObject( 0 ), + myStudy( 0 ), + myDesktop( 0 ), + myStatusLabel( 0 ), + myIsInitiallyRegistered( false ) +{ } /*! diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 72dc89363..8a8ac3968 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -104,6 +104,9 @@ public: //! Invokes application-specific "Select Directory" dialog and returns the selected directory name. virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0; + //! Perform required actions on the application, just registed in the session + virtual void Registered() { myIsInitiallyRegistered = true; }; + signals: void applicationClosed( SUIT_Application* ); void activated( SUIT_Application* ); @@ -154,6 +157,9 @@ protected: protected slots: virtual void onDesktopActivated(); +protected: + bool myIsInitiallyRegistered; //Registered(); } /*! diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 3bb85faa3..ff6383764 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -159,6 +159,72 @@ void SalomeApp_Application::start() if ( isFirst ) { isFirst = false; + /* + QString hdffile; + QStringList pyfiles; + + for (int i = 1; i < qApp->argc(); i++) { + QRegExp rxs ("--study-hdf=(.+)"); + if ( rxs.search( QString(qApp->argv()[i]) ) >= 0 && rxs.capturedTexts().count() > 1 ) { + QString file = rxs.capturedTexts()[1]; + QFileInfo fi ( file ); + QString extension = fi.extension( false ).lower(); + if ( extension == "hdf" && fi.exists() ) + hdffile = fi.absFilePath(); + } + else { + QRegExp rxp ("--pyscript=(.+)"); + if ( rxp.search( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) { + QStringList files = QStringList::split(",",rxp.capturedTexts()[1],false); + pyfiles += files; + } + } + } + + if ( !hdffile.isEmpty() ) // open hdf file given as parameter + onOpenDoc( hdffile ); + else if ( pyfiles.count() > 0 ) // create new study + onNewDoc(); + + // import/execute 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 j = 0; j < pyfiles.count(); j++ ) { + QFileInfo fi ( pyfiles[j] ); + PythonConsole* pyConsole = pythonConsole(); + if ( pyConsole ) { + QString extension = fi.extension( false ).lower(); + if ( extension == "py" && fi.exists() ) { + // execute python script + QString command = QString( "execfile(\"%1\")" ).arg( fi.absFilePath() ); + pyConsole->exec( command ); + } + else { + // import python module + QString command = QString( "import %1" ).arg( pyfiles[j] ); + //QString command = QString( "import %1" ).arg( fi.baseName( true ) ); + pyConsole->exec( command ); + } + } + } + } + } + } + */ + } +} + +/*!Just registered in the session*/ +void SalomeApp_Application::Registered() +{ + if (!myIsInitiallyRegistered) + { + myIsInitiallyRegistered = true; + + // execute python scripts QString hdffile; QStringList pyfiles; diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 09ece677d..893d53c1d 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -94,6 +94,8 @@ public: SUIT_ViewManager* newViewManager(const QString&); void updateSavePointDataObjects( SalomeApp_Study* ); + virtual void Registered(); + public slots: virtual bool onOpenDoc( const QString& ); virtual void onLoadDoc(); -- 2.39.2