From 1a722284b39e97a80734f5100037cfce3fc311df Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 30 Jun 2022 17:32:16 +0300 Subject: [PATCH] SalomePyQt methods activateModule(), activateView() do not work if focus is in other window than descktop --- src/CAM/CAM_Application.cxx | 10 +++++++--- src/LightApp/LightApp_Application.cxx | 10 +++++++--- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index aa92a3a97..afd1faf37 100644 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -415,13 +415,17 @@ bool CAM_Application::activateModule( const QString& modName ) // See issues 0021307, 0021373 BusyLocker lock( myBlocked ); + QString name = modName; + if ( !name.isEmpty() && !moduleTitle( modName ).isEmpty() ) + name = moduleTitle( modName ); + bool res = false; - if ( !modName.isEmpty() ) + if ( !name.isEmpty() ) { setProperty("activateModule", true); - CAM_Module* mod = module( modName ); + CAM_Module* mod = module( name ); if ( !mod ) - mod = loadModule( modName ); + mod = loadModule( name ); addModule( mod ); if ( mod ) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 9f042366b..e64fef2c7 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -542,17 +542,21 @@ bool LightApp_Application::activateModule( const QString& modName ) if ( prevMod ) actName = prevMod->moduleName(); - if ( actName == modName ) + QString name = modName; + if ( !name.isEmpty() && !moduleTitle( modName ).isEmpty() ) + name = moduleTitle( modName ); + + if ( actName == name ) return true; - putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) ); + putInfo( tr( "ACTIVATING_MODULE" ).arg( name ) ); saveDockWindowsState(); if ( infoPanel() ) infoPanel()->clear(); - bool status = CAM_Application::activateModule( modName ); + bool status = CAM_Application::activateModule( name ); updateModuleActions(); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 0cf073967..eea242463 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -225,6 +225,25 @@ namespace \internal */ const char* DEFAULT_SECTION = "SalomePyQt"; + + struct Activator + { + QWidget* myActiveWindow; + QWidget* myFocusedWidget; + Activator() + { + myActiveWindow = QApplication::activeWindow(); + myFocusedWidget = QApplication::focusWidget(); + QApplication::setActiveWindow( getApplication()->desktop() ); + } + ~Activator() + { + if ( myActiveWindow ) + QApplication::setActiveWindow( myActiveWindow ); + if ( myFocusedWidget ) + myFocusedWidget->setFocus(); + } + }; } /*! @@ -934,6 +953,7 @@ public: virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { + Activator activator; myResult = anApp->activateModule( myModuleName ); } } @@ -3616,6 +3636,7 @@ public: SUIT_ViewWindow* wnd = getWnd( myWndId ); MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd); if ( wnd ) { + Activator activator; wnd->setFocus(); myResult = true; } -- 2.30.2