#include <utilities.h>
+// 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.
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");
}
myRemove->setEnabled(!myRemove->menu()->actions().isEmpty());
+ updateExtActions();
update();
}
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 <ext>:<can_remove> 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