Salome HOME
Improve locale selection actvation in case if sub-shape of any type can be selected...
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUI / SALOME_PYQT_Module.cxx
index e41087cee03618974e09fb06d60ec94b9e340546..d704c0397e690114d556dfdd4c24b5e75c20f38c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,6 +29,8 @@
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <Container_init_python.hxx>
 
+#include <QCoreApplication>
+
 //
 // NB: Python requests.
 // General rule for Python requests created by Python-based GUI modules
@@ -64,14 +66,13 @@ PyMODINIT_FUNC INIT_FUNCTION();
 extern "C" {
   SALOME_PYQT_EXPORT CAM_Module* createModule()
   {
-    static bool alreadyInitialized = false;
+    QCoreApplication* app = QCoreApplication::instance();
+    bool alreadyInitialized = app && app->property( "salome_pyqt_gui_light_initialized" ).toBool();
 
     if ( !alreadyInitialized ) {
-      // call only once (see comment above) !
-      PyEval_RestoreThread( KERNEL_PYTHON::_gtstate);
+      PyLockWrapper lck; // GIL acquisition
       INIT_FUNCTION();
-      PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate);
-      alreadyInitialized = !alreadyInitialized;
+      if ( app ) app->setProperty( "salome_pyqt_gui_light_initialized", true );
     }
 
     return new SALOME_PYQT_Module();
@@ -107,7 +108,7 @@ SALOME_PYQT_Module::~SALOME_PYQT_Module()
   This function 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.
+  is used which loads engine to the default FactoryServer container.
 */
 QString SALOME_PYQT_Module::engineIOR() const
 {
@@ -120,11 +121,11 @@ QString SALOME_PYQT_Module::engineIOR() const
   }
   if ( ior.isEmpty() ) {
     // if IOR is still not specified, try default implementation
-    // which loads engine to the default FactoryServerPy container.
+    // which loads engine to the default FactoryServer container.
     Engines::EngineComponent_var comp;
     // temporary solution
     try {
-      comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServerPy", name().toLatin1() );
+      comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServer", name().toLatin1() );
     }
     catch (CORBA::Exception&) {
     }
@@ -245,6 +246,18 @@ void SALOME_PYQT_Module::preferencesChanged( const QString& section, const QStri
   myHelper->preferencesChanged( section, parameter );
 }
 
+/*!
+  \brief Called when study is closed
+  \param study study being closed
+  \sa PyModuleHelper::studyClosed()
+*/
+void SALOME_PYQT_Module::studyClosed( SUIT_Study* study )
+{
+  // call helper
+  myHelper->modelClosed( study );
+  SalomeApp_Module::studyClosed( study );
+}
+
 /*!
   \brief Test if object \a what can be dragged by the user.
   \param what data object being tested