From: kosta Date: Mon, 30 Jan 2023 14:16:54 +0000 (+0300) Subject: [bos #32523][EDF] SALOME on Demand GUI. Added loading extensions info on the launch... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7b42e43cd8cba7e25dbc1d0e99e92a186ac09843;p=modules%2Fgui.git [bos #32523][EDF] SALOME on Demand GUI. Added loading extensions info on the launch. Added check for Py_None return type from PyObject_CallMethod(). --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 6eb02e856..f660e45c2 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -251,6 +251,11 @@ static const char* imageEmptyIcon[] = { //since the 'toolbar marker' is not unique, find index of first occurrence of the //'toolbar marker' in the array and check that next string is name of the toolbar +namespace +{ + const char* salomeAppDir = "SALOME_APPLICATION_DIR"; +} + void LightAppCleanUpAppResources() { if ( LightApp_Application::_prefs_ ) { @@ -747,6 +752,8 @@ void LightApp_Application::createActions() connect( moduleAction, SIGNAL(showExtInfo()), this, SLOT(onShowExtInfo())); + addExtensionsActions(moduleAction); + // New window int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 ); int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); @@ -823,6 +830,46 @@ void LightApp_Application::createActions() createTool( ModulesListId, modTBar ); } +/*!Create actions for installed extensions:*/ +void LightApp_Application::addExtensionsActions(LightApp_ModuleAction* moduleAction) +{ + ASSERT(moduleAction) + if (!moduleAction) + { + return; + } + + // It should be set on the app start + auto extRootDir = getenv(salomeAppDir); + ASSERT(extRootDir) + if (!extRootDir) + { + return; + } + SCRUTE(extRootDir); + + // Import Python module that manages SALOME extensions. + PyLockWrapper lck; // acquire GIL + PyObjWrapper extensionQuery = PyImport_ImportModule((char*)"SalomeOnDemandTK.extension_query"); + PyObjWrapper installedExtensions = PyObject_CallMethod( + extensionQuery, (char*)"ext_by_name", (char*)"s", extRootDir); + if (!installedExtensions) + { + return; + } + + // Iterate installed extensions + for (Py_ssize_t pos = 0; pos < PyList_Size(installedExtensions); ++pos) + { + // Get the current ext name + auto extNameItem = PyList_GetItem(installedExtensions, pos); + QString extName(PyUnicode_AsUTF8(extNameItem)); + SCRUTE(extName.toStdString()); + + moduleAction->insertExtension(extName); + } +} + /*! Customize actions. */ @@ -884,7 +931,7 @@ void LightApp_Application::onExtAdding() return; // It should be set on the app start - auto extRootDir = getenv("SALOME_APPLICATION_DIR"); + auto extRootDir = getenv(salomeAppDir); ASSERT(extRootDir) if (!extRootDir) { @@ -911,7 +958,7 @@ void LightApp_Application::onExtAdding() PyObjWrapper unpackedModules = PyObject_CallMethod( extensionUnpacker, (char*)"install_salomex", (char*)"s", extPath.c_str()); - if (!unpackedModules) + if (!unpackedModules || unpackedModules == Py_None) { SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_FAILED_UNPACK_EXTENSION").arg(path) ); continue; @@ -1053,7 +1100,7 @@ void LightApp_Application::onExtRemoving(const QString& title) SCRUTE(extName); // It should be set on the app start - auto extRootDir = getenv("SALOME_APPLICATION_DIR"); + auto extRootDir = getenv(salomeAppDir); ASSERT(extRootDir) if (!extRootDir) { @@ -1067,7 +1114,7 @@ void LightApp_Application::onExtRemoving(const QString& title) PyObjWrapper extensionRemover = PyImport_ImportModule((char*)"SalomeOnDemandTK.extension_remover"); PyObjWrapper removedModules = PyObject_CallMethod( extensionRemover, (char*)"remove_salomex", (char*)"ss", extRootDir, extName.c_str()); - if (!removedModules) + if (!removedModules || removedModules == Py_None) { SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_FAILED_REMOVE_EXTENSION").arg(title) ); return; diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 2a5cf75b8..027ca395b 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -51,6 +51,7 @@ class LightApp_Preferences; class LightApp_SelectionMgr; class LightApp_FullScreenHelper; class LightApp_DataObject; +class LightApp_ModuleAction; class SUIT_DataBrowser; class SUIT_Study; class SUIT_Accel; @@ -219,6 +220,7 @@ public slots: protected: void showHelp( const QString& ); virtual void createActions(); + virtual void addExtensionsActions(LightApp_ModuleAction* moduleAction); virtual void customize(); virtual void createActionForViewer( const int id, const int parentId, diff --git a/src/LightApp/LightApp_ModuleAction.cxx b/src/LightApp/LightApp_ModuleAction.cxx index 70ee48ce7..053614366 100644 --- a/src/LightApp/LightApp_ModuleAction.cxx +++ b/src/LightApp/LightApp_ModuleAction.cxx @@ -432,6 +432,13 @@ 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);