From: vsr Date: Tue, 12 Apr 2022 12:52:59 +0000 (+0300) Subject: Extra paths in embedded interpreter X-Git-Tag: V9_9_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c8eea387dc52ba4ba0d4a37b6800f0bed9eee6b0;p=modules%2Fgui.git Extra paths in embedded interpreter --- diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index aac94f91b..0cf0f4c81 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -2134,7 +2134,7 @@ bool SalomeApp_Application::checkExistingDoc() PyConsole_Interp* SalomeApp_Application::createPyInterp() { - return new SalomeApp_PyInterp; + return new SalomeApp_PyInterp( resourceMgr() ); } #endif // DISABLE_PYCONSOLE diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index 58e55b9b4..ede9f290b 100644 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -23,12 +23,13 @@ // Author : Nicolas REJNERI #include "SalomeApp_PyInterp.h" +#include "SUIT_ResourceMgr.h" /*! \brief Constructor */ -SalomeApp_PyInterp::SalomeApp_PyInterp() - : myFirstRun( true ), myFirstInitStudy( false ) +SalomeApp_PyInterp::SalomeApp_PyInterp( SUIT_ResourceMgr* resMgr ) + : myFirstRun( true ), myFirstInitStudy( false ), myResourceMgr( resMgr ) { } @@ -63,6 +64,13 @@ int SalomeApp_PyInterp::beforeRun() { if ( myFirstRun ) { myFirstRun = false; + QStringList parameters = myResourceMgr->parameters( "pythonpath" ); + foreach ( QString parameter, parameters ) { + QStringList paths = myResourceMgr->stringValue( "pythonpath", parameter ).split( ";;" ); + int index = 0; + foreach( QString path, paths ) + simpleRun( QString( "import sys; sys.path.insert(%1, '%2')" ).arg( index++ ).arg( path ).toUtf8().constData(), false ); + } int ret = simpleRun( "from Help import *", false ); if ( ret ) return ret; diff --git a/src/SalomeApp/SalomeApp_PyInterp.h b/src/SalomeApp/SalomeApp_PyInterp.h index bb2e2da59..8d4d328ab 100644 --- a/src/SalomeApp/SalomeApp_PyInterp.h +++ b/src/SalomeApp/SalomeApp_PyInterp.h @@ -27,6 +27,8 @@ #include +class SUIT_ResourceMgr; + class SalomeApp_PyInterp : public PyConsole_Interp { friend class SalomeApp_Application; @@ -38,13 +40,14 @@ public: virtual void closeContext(); protected: - SalomeApp_PyInterp(); + SalomeApp_PyInterp(SUIT_ResourceMgr*); virtual bool initContext(); virtual int beforeRun(); private: bool myFirstRun; bool myFirstInitStudy; + SUIT_ResourceMgr* myResourceMgr; }; #endif // SALOMEAPP_PYINTERP_H