]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Add new action to the "Module Activation" dialog box: "Load Python Script"
authorvsr <vsr@opencascade.com>
Fri, 28 Jan 2011 14:50:44 +0000 (14:50 +0000)
committervsr <vsr@opencascade.com>
Fri, 28 Jan 2011 14:50:44 +0000 (14:50 +0000)
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h
src/SalomeApp/resources/SalomeApp_msg_en.ts

index 35fd12d3cb90652f5d47ec38642c52c6b784c848..04628a80b369b887eaea5d9934eb0f7f47fca969 100644 (file)
@@ -403,6 +403,33 @@ void SalomeApp_Application::onLoadDoc()
   }
 }
 
+/*!SLOT. Create new study and load script*/
+void SalomeApp_Application::onNewWithScript()
+{
+  QStringList filtersList;
+  filtersList.append(tr("PYTHON_FILES_FILTER"));
+  filtersList.append(tr("ALL_FILES_FILTER"));
+  
+  QString anInitialPath = "";
+  if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+    anInitialPath = QDir::currentPath();
+
+  QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+  if ( !aFile.isEmpty() )
+  {
+    onNewDoc();
+
+    QString command = QString("execfile(r\"%1\")").arg(aFile);
+
+    PyConsole_Console* pyConsole = pythonConsole();
+
+    if ( pyConsole )
+      pyConsole->exec( command );
+  }
+}
+
+
 /*!SLOT. Load document with \a aName.*/
 bool SalomeApp_Application::onLoadDoc( const QString& aName )
 {
@@ -1082,7 +1109,8 @@ bool SalomeApp_Application::openAction( const int aChoice, const QString& aName
 QMap<int, QString> SalomeApp_Application::activateModuleActions() const
 {
   QMap<int, QString> opmap = LightApp_Application::activateModuleActions();
-  opmap.insert( LoadStudyId,  tr( "ACTIVATE_MODULE_OP_LOAD" ) );
+  opmap.insert( LoadStudyId,     tr( "ACTIVATE_MODULE_OP_LOAD" ) );
+  opmap.insert( NewAndScriptId,  tr( "ACTIVATE_MODULE_OP_SCRIPT" ) );
   return opmap;
 }
 
@@ -1097,10 +1125,17 @@ QMap<int, QString> SalomeApp_Application::activateModuleActions() const
 */
 void SalomeApp_Application::moduleActionSelected( const int id )
 {
-  if ( id == LoadStudyId )
+  switch ( id ) {
+  case LoadStudyId:
     onLoadDoc();
-  else
+    break;
+  case NewAndScriptId:
+    onNewWithScript();
+    break;
+  default:
     LightApp_Application::moduleActionSelected( id );
+    break;
+  }
 }
 
 /*!Gets CORBA::ORB_var*/
index f4e82a0a9b305a02226f2c748a1926a54ac44bfb..f30f8017c8a9e5bbbfc218d0a938344f5977896f 100644 (file)
@@ -71,7 +71,7 @@ public:
 protected:
   enum { OpenRefresh = LightApp_Application::OpenReload + 1 };
   enum { CloseUnload = LightApp_Application::CloseDiscard + 1 };
-  enum { LoadStudyId = LightApp_Application::OpenStudyId + 1 };
+  enum { LoadStudyId = LightApp_Application::OpenStudyId + 1, NewAndScriptId };
 
 public:
   SalomeApp_Application();
@@ -106,6 +106,7 @@ public:
 
 public slots:
   virtual void                        onLoadDoc();
+  virtual void                        onNewWithScript();
   virtual bool                        onLoadDoc( const QString& );
   virtual void                        onCloseDoc( bool ask = true);
 
index 2b98f750607c50112ecc30e4d4b587087bee30be..346fc9aebf441b67daafcda16f72ff8a5923d086 100644 (file)
@@ -324,6 +324,10 @@ Do you want to reload it ?</translation>
         <source>ACTIVATE_MODULE_OP_LOAD</source>
         <translation>&amp;Load...</translation>
     </message>
+    <message>
+        <source>ACTIVATE_MODULE_OP_SCRIPT</source>
+        <translation>Load &amp;Script...</translation>
+    </message>
 </context>
 <context>
     <name>SalomeApp_StudyPropertiesDlg</name>