]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
NPAL16628: Pb with KDE desktop and Salome option --execute. Ensure the application...
authorjfa <jfa@opencascade.com>
Tue, 14 Aug 2007 07:35:06 +0000 (07:35 +0000)
committerjfa <jfa@opencascade.com>
Tue, 14 Aug 2007 07:35:06 +0000 (07:35 +0000)
src/SUIT/SUIT_Application.cxx
src/SUIT/SUIT_Application.h
src/SUIT/SUIT_Session.cxx
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h

index a4a21d8623fb062d71e8f0c460382553fb8edbf4..0be1fbf72466f6f8efac9e75a6268a8b8aa22dbf 100755 (executable)
   Default constructor
 */
 SUIT_Application::SUIT_Application()
-: QObject( 0 ),
-myStudy( 0 ),
-myDesktop( 0 ),
-myStatusLabel( 0 )
-{ 
+  : QObject( 0 ),
+    myStudy( 0 ),
+    myDesktop( 0 ),
+    myStatusLabel( 0 ),
+    myIsInitiallyRegistered( false )
+{
 }
 
 /*!
index 72dc89363a4efe379f4923c74c642723fcbe7a11..8a8ac396814e0ee912c63e9ea02f6823904c78e0 100755 (executable)
@@ -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; //<! false before the first application registration in the session
+
 private:
   SUIT_Study*           myStudy;
   SUIT_Desktop*         myDesktop;
index 0e641f236e41676d82ed75884eeaa4537c973079..1d6ce09f76ced1d93b1b8e1d254c9534240031f0 100755 (executable)
@@ -325,6 +325,8 @@ SUIT_ResourceMgr* SUIT_Session::createResourceMgr( const QString& appName ) cons
 void SUIT_Session::onApplicationActivated( SUIT_Application* app ) 
 {
   myActiveApp = app;
+  if (app)
+    app->Registered();
 }
 
 /*!
index 3bb85faa3dc02eb88787ce22e79b9ff03ab77af1..ff63837648b36ad5cf79d1c5f7ebbc0c727aecd3 100644 (file)
@@ -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<SalomeApp_Study*>( 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;
 
index 09ece677d64a0f4906e35435e86f622d0e87ed3c..893d53c1dd884bbeba8782bc1619a508a76de918 100644 (file)
@@ -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();