]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix a bug: problem with Python module initialization when there are light / non-light...
authorvsr <vsr@opencascade.com>
Tue, 6 May 2014 08:34:45 +0000 (12:34 +0400)
committervsr <vsr@opencascade.com>
Tue, 6 May 2014 08:34:45 +0000 (12:34 +0400)
src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx

index 799522728ae27db9890b59de4b8251392e237d34..4b73279a700c3c34c38c8323852d078342d20d0c 100644 (file)
@@ -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,12 +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 ) {
       PyLockWrapper lck; // GIL acquisition
       INIT_FUNCTION();
-      alreadyInitialized = !alreadyInitialized;
+      if ( app ) app->setProperty( "salome_pyqt_gui_light_initialized", true );
     }
 
     return new SALOME_PYQT_Module();
index 2fb54675d69b6b39394cb646090d13a09af67a7e..da7043dbd9a0e06e657a0bfbea63f61b999dcc4a 100644 (file)
@@ -35,6 +35,8 @@
 #include <Container_init_python.hxx>
 #endif
 
+#include <QCoreApplication>
+
 // Py_ssize_t for old Pythons
 // This code is as recommended by"
 // http://www.python.org/dev/peps/pep-0353/#conversion-guidelines
@@ -80,13 +82,14 @@ extern "C"
 {
   SALOME_PYQT_LIGHT_EXPORT CAM_Module* createModule() 
   {
-    static bool alreadyInitialized = false;
+    QCoreApplication* app = QCoreApplication::instance();
+    bool alreadyInitialized = app && app->property( "salome_pyqt_gui_light_initialized" ).toBool();
 
     // make initialization only once (see comment above) !
     if ( !alreadyInitialized ) {
       PyLockWrapper lck; // GIL acquisition
       INIT_FUNCTION();
-      alreadyInitialized = !alreadyInitialized;
+      if ( app ) app->setProperty( "salome_pyqt_gui_light_initialized", true );
     }
 
     return new SALOME_PYQT_ModuleLight();