From 580018e42cb0e5b33332567648fe799d1226fc2d Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 6 May 2009 10:17:29 +0000 Subject: [PATCH] Issue 0020342: EDF 1025 GUI: Impossible to choose the container for a Python module --- .../SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx | 57 +++++++++++++++++-- .../SALOME_PYQT_GUI/SALOME_PYQT_Module.h | 12 ++-- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index 55171f8a4..35c178b97 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -1009,10 +1009,28 @@ Engines::Component_var SALOME_PYQT_Module::getEngine() const */ QString SALOME_PYQT_Module::engineIOR() const { - QString anIOR = QString::null; - if ( !CORBA::is_nil( getEngine() ) ) - return QString( getApp()->orb()->object_to_string( getEngine() ) ); - return QString( "" ); + class EngineIORReq : public PyInterp_LockRequest + { + public: + EngineIORReq( PyInterp_base* _py_interp, + SALOME_PYQT_Module* _obj ) + : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) + myObj( _obj ) {} + + protected: + virtual void execute() + { + myObj->getEngineIOR(); + } + + private: + SALOME_PYQT_Module* myObj; + }; + + // post request + PyInterp_Dispatcher::Get()->Exec( new EngineIORReq( myInterp, const_cast( this ) ) ); + + return myIOR; } /*! @@ -1155,6 +1173,37 @@ void SALOME_PYQT_Module::initPreferences() myInitModule = 0; } +/*! + * Tries to get engine IOR from the Python module using engineIOR() function. + * That function can load module engine using appropriate container if required. + * If this function is not available in Python module, the default implementation + * is used which loads engine to the default FactoryServerPy container. + */ +void SALOME_PYQT_Module::getEngineIOR() +{ + myIOR = ""; + + // Python interpreter should be initialized and Python module should be + // import first + if ( !myInterp || !myModule ) + return; + + if ( PyObject_HasAttrString( myModule , "engineIOR" ) ) { + PyObjWrapper res( PyObject_CallMethod( myModule, "engineIOR", "" ) ); + if ( !res ) { + PyErr_Print(); + } + else { + // parse the return value, result chould be string + if ( PyString_Check( res ) ) { + myIOR = PyString_AsString( res ); + } + } + } + else if ( !CORBA::is_nil( getEngine() ) ) + myIOR = QString( getApp()->orb()->object_to_string( getEngine() ) ); +} + /*! * Initialises python subinterpreter (one per study) */ diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h index 039cc72ee..beeb04b7b 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h @@ -80,6 +80,8 @@ private: /* status of last trying of module activation*/ bool myLastActivateStatus; + /* engine IOR */ + QString myIOR; /****************************** * Construction/destruction @@ -231,6 +233,8 @@ private: void menuHighlight( const int, const int ); /* Init preferences */ void initPreferences(); + /* Get engine IOR */ + void getEngineIOR(); /* initialize a Python subinterpreter */ void initInterp ( int ); @@ -243,10 +247,10 @@ private: void prefChanged( const QString&, const QString& ); /* window signals connectors*/ - void activeViewChanged( const SUIT_ViewWindow* ); - void viewClosed( const SUIT_ViewWindow* ); - void viewCloned( const SUIT_ViewWindow* ); - void connectView( const SUIT_ViewWindow* ); + void activeViewChanged( const SUIT_ViewWindow* ); + void viewClosed( const SUIT_ViewWindow* ); + void viewCloned( const SUIT_ViewWindow* ); + void connectView( const SUIT_ViewWindow* ); friend class SALOME_PYQT_XmlHandler; }; -- 2.39.2