From e8c9567d350fb0baf7240c4ba2dfb25cfad8438e Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 28 Jan 2011 14:50:44 +0000 Subject: [PATCH] Add new action to the "Module Activation" dialog box: "Load Python Script" --- src/SalomeApp/SalomeApp_Application.cxx | 41 +++++++++++++++++++-- src/SalomeApp/SalomeApp_Application.h | 3 +- src/SalomeApp/resources/SalomeApp_msg_en.ts | 4 ++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 35fd12d3c..04628a80b 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -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 SalomeApp_Application::activateModuleActions() const { QMap 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 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*/ diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index f4e82a0a9..f30f8017c 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -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); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index 2b98f7506..346fc9aeb 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -324,6 +324,10 @@ Do you want to reload it ? ACTIVATE_MODULE_OP_LOAD &Load... + + ACTIVATE_MODULE_OP_SCRIPT + Load &Script... + SalomeApp_StudyPropertiesDlg -- 2.39.2