From 35a2de86856ade4e80c81bb602068d79c8e9415a Mon Sep 17 00:00:00 2001 From: kosta Date: Fri, 10 Feb 2023 21:48:10 +0100 Subject: [PATCH] [bos #32523][EDF] SALOME on Demand GUI. Added update greyed out status for extension in Remove button menu. --- src/LightApp/LightApp_ModuleAction.cxx | 68 +++++++++++++++++++++++--- src/LightApp/LightApp_ModuleAction.h | 1 + 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/LightApp/LightApp_ModuleAction.cxx b/src/LightApp/LightApp_ModuleAction.cxx index 053614366..e7a70c10b 100644 --- a/src/LightApp/LightApp_ModuleAction.cxx +++ b/src/LightApp/LightApp_ModuleAction.cxx @@ -33,6 +33,12 @@ #include +// Prevent slot compilation error +#pragma push_macro("slots") +#undef slots +#include "PyInterp_Utils.h" +#pragma pop_macro("slots") + /*! \class LightApp_ModuleAction::ActionSet \brief Internal class to represent list of modules buttons. @@ -433,16 +439,12 @@ void LightApp_ModuleAction::insertExtension(const QString& name) QAction* inserted = new QAction(name); - // Grey out Base extension, so it's impossible to remove it - if (!QString::compare("Base", name, Qt::CaseInsensitive)) - { - inserted->setEnabled(false); - } - myRemove->menu()->insertAction(insertBefore, inserted); connect(inserted, SIGNAL(triggered()), myMapper, SLOT(map())); myMapper->setMapping(inserted, name); + updateExtActions(); + MESSAGE("An extension's action was inserted"); } @@ -469,6 +471,7 @@ void LightApp_ModuleAction::removeExtension(const QString& name) myRemove->setEnabled(!myRemove->menu()->actions().isEmpty()); + updateExtActions(); update(); } @@ -641,6 +644,59 @@ void LightApp_ModuleAction::update( QtxComboBox* cb ) cb->blockSignals( blocked ); } +/*! + \brief Update extension actions based on dependencies. + \internal + \param +*/ +void LightApp_ModuleAction::updateExtActions() +{ + MESSAGE("Check dependencies to update extensions actions..."); + + // It should be set on the app start + auto extRootDir = getenv("SALOME_APPLICATION_DIR"); + if (!extRootDir) + { + MESSAGE("Cannot get SALOME_APPLICATION_DIR env variable! Cancel adding selected extensions."); + return; + } + SCRUTE(extRootDir); + + // Import Python module that manages SALOME extensions. + PyLockWrapper lck; // acquire GIL + PyObjWrapper extensionQuery = PyImport_ImportModule((char*)"SalomeOnDemandTK.extension_query"); + PyObjWrapper extCanRemoveDict = PyObject_CallMethod(extensionQuery, (char*)"ext_canremove_flags", (char*)"s", extRootDir); + if (!extCanRemoveDict || extCanRemoveDict == Py_None) + { + MESSAGE("Couldn't get : dictionary from SalomeOnDemandTK.extension_query! Return."); + return; + } + + // Iterate extensions' actions to disable ones we can't remove because of dependencies. + foreach(QAction* curAction, myRemove->menu()->actions()) + { + const std::string action_name = curAction->text().toStdString(); + SCRUTE(action_name); + + PyObject* canRemoveObject = PyDict_GetItemString(extCanRemoveDict, action_name.c_str()); + if (!canRemoveObject) + { + MESSAGE("Couldn't get can remove flag from dictionary! Skip."); + continue; + } + + const int isTrueRes = PyObject_IsTrue(canRemoveObject); + if (isTrueRes == -1) + { + MESSAGE("PyObject_IsTrue() failed. Using false value instead."); + } + const bool canRemove = isTrueRes == 1; + SCRUTE(canRemove); + + curAction->setEnabled(canRemove); + } +} + /*! \brief Get an action corresponding to the active module. \internal diff --git a/src/LightApp/LightApp_ModuleAction.h b/src/LightApp/LightApp_ModuleAction.h index 6e2ab620d..c71524f3b 100644 --- a/src/LightApp/LightApp_ModuleAction.h +++ b/src/LightApp/LightApp_ModuleAction.h @@ -94,6 +94,7 @@ signals: private: void update(); void update( QtxComboBox* ); + void updateExtActions(); QAction* active() const; void activate( int, bool = true ); -- 2.39.2