]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix for Bug IPAL9053( 3.0.0: "Check Geometry" and "Load script" functionalities from...
authormzn <mzn@opencascade.com>
Thu, 9 Jun 2005 09:07:42 +0000 (09:07 +0000)
committermzn <mzn@opencascade.com>
Thu, 9 Jun 2005 09:07:42 +0000 (09:07 +0000)
"Load Script" moved from Geometry module to menu File(so, now it is accessible from all modules).

src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h
src/SalomeApp/resources/SalomeApp_msg_en.po

index 1a441fd102911c967d887e33c38dd314c6649a3e..c620afb41e620c2a8e0f73d29a48b034787afd30 100644 (file)
@@ -49,6 +49,7 @@
 
 #include <PythonConsole_PyConsole.h>
 
+#include <SUIT_FileDlg.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_ActionOperation.h>
@@ -252,7 +253,14 @@ void SalomeApp_Application::createActions()
 
   SUIT_Desktop* desk = desktop();
   SUIT_ResourceMgr* resMgr = resourceMgr();
-
+  
+  // Load script
+  createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
+               tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
+               0, desk, false, this, SLOT( onLoadScript() ) );
+  int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
+  createMenu( LoadScriptId, fileMenu, 10, -1 );
+  
   // default icon for neutral point ('SALOME' module)
   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
   if ( defIcon.isNull() )
@@ -311,7 +319,7 @@ void SalomeApp_Application::createActions()
   }
 
   SUIT_Tools::simplifySeparators( modTBar );
-
+  
   // New window
 
   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
@@ -515,6 +523,11 @@ void SalomeApp_Application::updateCommandsStatus()
     if ( a )
       a->setEnabled( activeStudy() );
   }
+
+  // Load script menu
+  QAction* a = action( LoadScriptId );
+  if ( a )
+    a->setEnabled( activeStudy() );
 }
 
 //=======================================================================
@@ -649,6 +662,15 @@ LogWindow* SalomeApp_Application::logWindow()
   return lw;
 }
 
+PythonConsole* SalomeApp_Application::pythonConsole()
+{
+  PythonConsole* console = 0;
+  QWidget* wid = getWindow( WT_PyConsole );
+  if ( wid->inherits( "PythonConsole" ) )
+    console = (PythonConsole*)wid;
+  return console;
+}
+
 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
 {
   SUIT_ViewManager* aVM = viewManager( vmType );
@@ -754,6 +776,35 @@ void SalomeApp_Application::onStudyClosed( SUIT_Study* )
   saveWindowsGeometry();
 }
 
+void SalomeApp_Application::onLoadScript( )
+{
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+  if ( !appStudy ) return;
+  _PTR(Study) aStudy = appStudy->studyDS();
+  
+  if ( aStudy->GetProperties()->IsLocked() ) {
+    SUIT_MessageBox::warn1 ( desktop(),
+                            QObject::tr("WRN_WARNING"), 
+                            QObject::tr("WRN_STUDY_LOCKED"),
+                            QObject::tr("BUT_OK") );
+    return;
+  }
+  
+  QStringList filtersList;
+  filtersList.append(tr("PYTHON_FILES_FILTER"));
+  filtersList.append(tr("ALL_FILES_FILTER"));
+  
+  QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, false);
+  if(!aFile.isEmpty()) {
+    QString command = QString("execfile(\"%1\")").arg(aFile);
+    
+    PythonConsole* pyConsole = pythonConsole();
+    
+    if(pyConsole)
+      pyConsole->exec(command);
+  }
+}
+
 QString SalomeApp_Application::getFileFilter() const
 {
   return "(*.hdf)";
index 587d5a2d0f6f8ab6049985f4efc48c62eb1170ba..dc2004eb0965d277f4ebed23bdcc1236893421bd 100644 (file)
@@ -27,6 +27,7 @@ class QDockWindow;
 
 class LogWindow;
 class OB_Browser;
+class PythonConsole;
 class SalomeApp_Module;
 class SalomeApp_SelectionMgr;
 class SalomeApp_WidgetContainer;
@@ -49,7 +50,7 @@ public:
   typedef enum { WT_ObjectBrowser, WT_PyConsole, WT_LogWindow, WT_User } WindowTypes;
 
   enum { ModulesListId = STD_Application::UserID, NewGLViewId,
-         NewPlot2dId, NewOCCViewId, NewVTKViewId, UserID };
+         NewPlot2dId, NewOCCViewId, NewVTKViewId, LoadScriptId, UserID };
 
 public:
   SalomeApp_Application();
@@ -65,6 +66,7 @@ public:
 
   OB_Browser*                         objectBrowser();
   LogWindow*                          logWindow();
+  PythonConsole*                      pythonConsole();   
 
   virtual QString                     getFileFilter() const;
   SUIT_ViewManager*                   getViewManager( const QString&, const bool );
@@ -127,6 +129,8 @@ private slots:
   void                                onStudyOpened( SUIT_Study* );
   void                                onStudySaved( SUIT_Study* );
   void                                onStudyClosed( SUIT_Study* );
+  
+  void                                onLoadScript(); 
 
 private:
   void                                updateWindows();
index 780d08f3cfc611346d7311ba45ca11b9294a8491..89035d0f26065e9862d1b8071a39087002b520f4 100644 (file)
@@ -135,3 +135,20 @@ msgid "SalomeApp_ModuleDlg::ActivateComponent_DESCRIPTION"
 msgstr "Create, open or load study."
 
 //=======================================================================================
+
+msgid "SalomeApp_Application::ALL_FILES_FILTER"
+msgstr "All files ( * )"
+
+msgid "SalomeApp_Application::PYTHON_FILES_FILTER"
+msgstr "PYTHON Files ( *.py )"
+
+//=======================================================================================
+
+msgid "TOT_DESK_FILE_LOAD_SCRIPT"
+msgstr "Load python script"
+
+msgid "MEN_DESK_FILE_LOAD_SCRIPT"
+msgstr "Load script..."
+
+msgid "PRP_DESK_FILE_LOAD_SCRIPT"
+msgstr "Loads python script from file"