From: vsr Date: Wed, 6 May 2009 08:40:37 +0000 (+0000) Subject: Issue 0020342: EDF 1025 GUI: Impossible to choose the container for a Python module X-Git-Tag: V5_1_2rc1~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=edbf1642174a3a8f34c328b53e6afa3f2e691128;p=modules%2Fgui.git Issue 0020342: EDF 1025 GUI: Impossible to choose the container for a Python module --- 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 267f5fb51..109d4c4e2 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -23,6 +23,8 @@ // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // +#include + #include "SALOME_PYQT_Module.h" #include "SalomeApp_Application.h" #include "SALOME_PYQT_ModuleLight.h" @@ -116,9 +118,59 @@ Engines::Component_var SALOME_PYQT_Module::getEngine() const */ QString SALOME_PYQT_Module::engineIOR() const { - if ( !CORBA::is_nil( getEngine() ) ) - return QString( getApp()->orb()->object_to_string( getEngine() ) ); - return QString( "" ); + class EngineIORReq : public PyInterp_LockRequest + { + public: + EngineIORReq( PyInterp_Interp* _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; +} + +/*! + * 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() ) ); } CAM_DataModel* SALOME_PYQT_Module::createDataModel() 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 3e1166ef2..3167efd0a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h @@ -38,14 +38,14 @@ class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module, { Q_OBJECT; - public: +public: SALOME_PYQT_Module(); ~SALOME_PYQT_Module(); /* get module engine IOR */ - virtual QString engineIOR() const; + virtual QString engineIOR() const; - public slots: +public slots: void preferenceChanged( const QString&, const QString&, const QString& ); @@ -54,12 +54,17 @@ class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module, void onViewClosed( SUIT_ViewWindow* ); void onViewCloned( SUIT_ViewWindow* ); - protected: +protected: /* create data model */ - virtual CAM_DataModel* createDataModel(); + virtual CAM_DataModel* createDataModel(); Engines::Component_var getEngine() const; +private: + void getEngineIOR(); + +private: + QString myIOR; }; #endif // SALOME_PYQT_MODULE_H diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index 2340b5ec3..e7e89fa8c 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -55,7 +55,6 @@ private: //! study to Python subinterpreter map typedef QMap InterpMap; - PyObjWrapper myModule; //!< Python GUI module static SALOME_PYQT_ModuleLight* myInitModule; //!< Python GUI being initialized (not zero only during the initialization) XmlHandler* myXmlHandler; //!< XML resource file parser @@ -63,8 +62,8 @@ private: QStringList myViewMgrList;//!< compatible view managers list bool myLastActivateStatus; //!< latest module activation status - protected: + PyObjWrapper myModule; //!< Python GUI module PyInterp_Interp* myInterp; //!< current Python subinterpreter static InterpMap myInterpMap; //!< study to Python subinterpreter map