- * Initialises python subinterpreter (one per study)
- */
-void SALOME_PYQT_Module::initInterp( int theStudyId )
-{
- // check study Id
- if ( !theStudyId ) {
- // Error! Study Id must not be 0!
- myInterp = NULL;
- return;
- }
- // try to find the subinterpreter
- if( myInterpMap.find( theStudyId ) != myInterpMap.end() ) {
- // found!
- myInterp = myInterpMap[ theStudyId ];
- return;
- }
- // not found - create a new one!
- ///////////////////////////////////////////////////////////////////
- // Attention: the creation of Python interpretor must be protected
- // by a C++ Lock because of C threads
- ///////////////////////////////////////////////////////////////////
- myInterp = new SALOME_PYQT_PyInterp();
- myInterp->initialize();
- myInterpMap[ theStudyId ] = myInterp;
-
- // import 'salome' module and call 'salome_init' method;
- // do it only once on interpreter creation
- // ... first get python lock
- PyLockWrapper aLock = myInterp->GetLockWrapper();
- // ... then import a module
- PyObjWrapper aMod = PyImport_ImportModule( "salome" );
- if( !aMod ) {
- // Error!
- PyErr_Print();
- return;
- }
- // ... then call a method
- PyObjWrapper aRes( PyObject_CallMethod( aMod, "salome_init", "" ) );
- if( !aRes ) {
- // Error!
- PyErr_Print();
- return;
- }
-}
-
-/*!
- * Imports Python GUI module and remember the reference to the module
- * !!! initInterp() should be called first!!!
- */
-void SALOME_PYQT_Module::importModule()
-{
- // check if the subinterpreter is initialized
- if ( !myInterp ) {
- // Error! Python subinterpreter should be initialized first!
- myModule = 0;
- return;
- }
- // import Python GUI module and puts it in <myModule> attribute
- // ... first get python lock
- PyLockWrapper aLock = myInterp->GetLockWrapper();
- // ... then import a module
- QString aMod = QString( name("") ) + "GUI";
- myModule = PyImport_ImportModule( (char*)( aMod.latin1() ) );
- if( !myModule ) {
- // Error!
- PyErr_Print();
- return;
- }
-}
-
-/*!
- * Calls <module>.setWorkSpace() method with PyQt QWidget object to use with
- * interpreter.
- * !!! initInterp() and importModule() should be called first!!!
- */
-void SALOME_PYQT_Module::setWorkSpace()
-{
- // check if the subinterpreter is initialized and Python module is imported
- if ( !myInterp || !myModule ) {
- // Error! Python subinterpreter should be initialized and module should be imported first!
- return;
- }
-
- // call setWorkspace() method
- // ... first get python lock
- PyLockWrapper aLock = myInterp->GetLockWrapper();
-
- // ... then try to import SalomePyQt module. If it's not possible don't go on.
- PyObjWrapper aQtModule( PyImport_ImportModule( "SalomePyQt" ) );
- if( !aQtModule ) {
- // Error!
- PyErr_Print();
- return;
- }
-
- if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__
- // ... then get workspace object
- QWidget* aWorkspace = 0;
- if ( getApp()->desktop()->inherits( "STD_MDIDesktop" ) ) {
- STD_MDIDesktop* aDesktop = dynamic_cast<STD_MDIDesktop*>( getApp()->desktop() );
- if ( aDesktop )
- aWorkspace = aDesktop->workspace();
- }
- else if ( getApp()->desktop()->inherits( "STD_TabDesktop" ) ) {
- STD_TabDesktop* aDesktop = dynamic_cast<STD_TabDesktop*>( getApp()->desktop() );
- if ( aDesktop )
- aWorkspace = aDesktop->workstack();
- }
- PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget ) );
- // ... and finally call Python module's setWorkspace() method (obsolete)
- if ( PyObject_HasAttrString(myModule , "setWorkSpace") ) {
- PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) );
- if( !res ) {
- PyErr_Print();
- }
- }
- } //__CALL_OLD_METHODS__
-}
-
-/*!
- * Returns default menu group
- */
-int SALOME_PYQT_Module::defaultMenuGroup()
-{
- return __DEFAULT_GROUP__;
-}
-
-/*!
- * The next methods call the parent implementation.
- * This is done to open protected methods from CAM_Module class.
- * Also these methods are used to register created from outside menus
- * in order to enable dynamic menus handling.
- */
-int SALOME_PYQT_Module::createTool( const QString& name )
-{
- return SalomeApp_Module::createTool( name );
-}
-int SALOME_PYQT_Module::createTool( const int id, const int tBar, const int idx )
-{
- return SalomeApp_Module::createTool( id, tBar, idx );
-}
-int SALOME_PYQT_Module::createTool( const int id, const QString& tBar, const int idx )
-{
- return SalomeApp_Module::createTool( id, tBar, idx );
-}
-int SALOME_PYQT_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
-{
- return SalomeApp_Module::createTool( a, tBar, id, idx );
-}
-int SALOME_PYQT_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
-{
- return SalomeApp_Module::createTool( a, tBar, id, idx );
-}
-int SALOME_PYQT_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx, const bool constantMenu )
-{
- bool exists = hasMenu( subMenu, menu );
- int regId = SalomeApp_Module::createMenu( subMenu, menu, id, group, idx, true );
- if ( !exists )
- registerMenu( regId, menu, constantMenu );
- return regId;
-}
-int SALOME_PYQT_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx, const bool constantMenu )
-{
- QStringList menus = QStringList::split( "|", menu, false );
- int pid = -1;
- for (int i = 0; i < menus.count(); i++ ) {
- pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu );
- if ( pid == -1 ) break;
- }
- if ( pid != -1 )
- pid = createMenu( subMenu, pid, id, group, idx, constantMenu );
- return pid;
-}
-int SALOME_PYQT_Module::createMenu( const int id, const int menu, const int group, const int idx, const bool constantMenu )
-{
- int regId = SalomeApp_Module::createMenu( id, menu, group, idx );
- if ( regId != -1 )
- registerMenu( regId, menu, constantMenu );
- return regId;
-}
-int SALOME_PYQT_Module::createMenu( const int id, const QString& menu, const int group, const int idx, const bool constantMenu )
-{
- QStringList menus = QStringList::split( "|", menu, false );
- int pid = -1;
- for (int i = 0; i < menus.count(); i++ ) {
- pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu );
- if ( pid == -1 ) break;
- }
- if ( pid != -1 )
- pid = createMenu( id, pid, group, idx, constantMenu );
- return pid;
-}
-int SALOME_PYQT_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx, const bool constantMenu )
-{
- int regId = SalomeApp_Module::createMenu( a, menu, id, group, idx );
- if ( regId != -1 )
- registerMenu( regId, menu, constantMenu );
- return regId;
-}
-int SALOME_PYQT_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx, const bool constantMenu )
-{
- QStringList menus = QStringList::split( "|", menu, false );
- int pid = -1;
- for (int i = 0; i < menus.count(); i++ ) {
- pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu );
- if ( pid == -1 ) break;
- }
- if ( pid != -1 )
- pid = createMenu( a, pid, id, group, idx, constantMenu );
- return pid;
-}
-QAction* SALOME_PYQT_Module::createSeparator()
-{
- return SalomeApp_Module::separator();
-}
-QAction* SALOME_PYQT_Module::action( const int id ) const
-{
- return SalomeApp_Module::action( id );
-}
-int SALOME_PYQT_Module::actionId( const QAction* a ) const
-{
- return SalomeApp_Module::actionId( a );
-}
-QAction* SALOME_PYQT_Module::createAction( const int id, const QString& text, const QString& icon,
- const QString& menu, const QString& tip, const int key,
- const bool toggle )