From 0586f312fa9a87d0f9e231e885a35d70bce6a301 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 29 Jun 2006 13:30:07 +0000 Subject: [PATCH] PAL12651: EDF: Crash on a biprocessor machine. Disable GUI user actions while a python command is executed. --- src/PythonConsole/PythonConsole_PyEditor.cxx | 3 +++ src/SUIT/SUIT_Session.cxx | 28 ++++++++++++++++++++ src/SUIT/SUIT_Session.h | 5 ++++ src/SUITApp/SUITApp_Application.cxx | 13 +++++++++ src/Session/SALOME_Session_Server.cxx | 12 +++++++++ 5 files changed, 61 insertions(+) diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index 3093b89de..ed75e1f5b 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -66,7 +67,9 @@ protected: virtual void execute(){ if(myCommand != ""){ // if(MYDEBUG) MESSAGE("*** ExecCommand::execute() started"); + SUIT_Session::SetPythonExecuted(true); // disable GUI user actions int ret = getInterp()->run( myCommand.latin1() ); + SUIT_Session::SetPythonExecuted(false); // enable GUI user actions // if(MYDEBUG) MESSAGE("ExecCommand::execute() - myInterp = "< #endif +static bool SUIT_Session_IsPythonExecuted = false; +static QMutex SUIT_Session_PythonMutex; + SUIT_Session* SUIT_Session::mySession = 0; /*! Constructor.*/ @@ -323,3 +326,28 @@ void SUIT_Session::onApplicationActivated( SUIT_Application* app ) { myActiveApp = app; } + +/*! + \retval Return TRUE, if a command is currently executed in Python Console, + FALSE otherwise. +*/ +bool SUIT_Session::IsPythonExecuted() +{ + bool ret; + SUIT_Session_PythonMutex.lock(); + ret = SUIT_Session_IsPythonExecuted; + SUIT_Session_PythonMutex.unlock(); + return ret; +} + +/*! + Set value of boolean flag, being returned by method \a IsPythonExecuted(). + It is supposed to set the flag to TRUE when any python command starts + and reset it to FALSE when the command finishes. +*/ +void SUIT_Session::SetPythonExecuted(bool isPythonExecuted) +{ + SUIT_Session_PythonMutex.lock(); + SUIT_Session_IsPythonExecuted = isPythonExecuted; + SUIT_Session_PythonMutex.unlock(); +} diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index 08078ff74..840de5927 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -24,6 +24,7 @@ #include "SUIT_Application.h" #include "SUIT_ResourceMgr.h" +#include #include #include #include @@ -73,6 +74,10 @@ public: SUIT_ExceptionHandler* handler() const; + // To lock GUI user actions during python command execution (PAL12651) + static bool IsPythonExecuted(); + static void SetPythonExecuted(bool isPythonExecuted); + signals: void applicationClosed( SUIT_Application* ); diff --git a/src/SUITApp/SUITApp_Application.cxx b/src/SUITApp/SUITApp_Application.cxx index 4639f100d..7fe9b33a3 100644 --- a/src/SUITApp/SUITApp_Application.cxx +++ b/src/SUITApp/SUITApp_Application.cxx @@ -18,6 +18,7 @@ // #include "SUITApp_Application.h" +#include "SUIT_Session.h" #include "SUIT_MessageBox.h" #include "SUIT_ExceptionHandler.h" @@ -68,6 +69,18 @@ myExceptHandler( hand ) */ bool SUITApp_Application::notify( QObject* receiver, QEvent* e ) { + // Disable GUI user actions while python command is executed + if (SUIT_Session::IsPythonExecuted()) { + // Disable mouse and keyboard events + QEvent::Type aType = e->type(); + if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease || + aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove || + aType == QEvent::Wheel || + aType == QEvent::KeyPress || aType == QEvent::KeyRelease || + aType == QEvent::Accel || aType == QEvent::AccelOverride) + return false; + } + return myExceptHandler ? myExceptHandler->handle( receiver, e ) : QApplication::notify( receiver, e ); } diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 21ceec290..d278421c1 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -246,6 +246,18 @@ public: virtual bool notify( QObject* receiver, QEvent* e ) { + // Disable GUI user actions while python command is executed + if (SUIT_Session::IsPythonExecuted()) { + // Disable mouse and keyboard events + QEvent::Type aType = e->type(); + if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease || + aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove || + aType == QEvent::Wheel || + aType == QEvent::KeyPress || aType == QEvent::KeyRelease || + aType == QEvent::Accel || aType == QEvent::AccelOverride) + return false; + } + return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e ); } -- 2.39.2