From 429569482740fac22e173cef932536d7ed0a8aa9 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 6 May 2014 12:34:45 +0400 Subject: [PATCH] Fix a bug: problem with Python module initialization when there are light / non-light modules in GUI session --- src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx | 7 +++++-- .../SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx | 7 +++++-- 2 files changed, 10 insertions(+), 4 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 799522728..4b73279a7 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -29,6 +29,8 @@ #include #include +#include + // // 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(); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index 2fb54675d..da7043dbd 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -35,6 +35,8 @@ #include #endif +#include + // 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(); -- 2.39.2