From c3960037ab3b802c5357d99b5b36373238e09eb8 Mon Sep 17 00:00:00 2001 From: kosta Date: Thu, 9 Feb 2023 15:54:23 +0100 Subject: [PATCH] [bos #32523][EDF] SALOME on Demand GUI. Now extensions info dialog shows name, description, author, components and size for each extension as a table, sorted by name. --- src/LightApp/LightApp_ExtInfoDlg.cxx | 134 ++++++++++++++++----------- src/LightApp/LightApp_ExtInfoDlg.h | 4 +- 2 files changed, 85 insertions(+), 53 deletions(-) diff --git a/src/LightApp/LightApp_ExtInfoDlg.cxx b/src/LightApp/LightApp_ExtInfoDlg.cxx index d81d95ea5..1695775f4 100644 --- a/src/LightApp/LightApp_ExtInfoDlg.cxx +++ b/src/LightApp/LightApp_ExtInfoDlg.cxx @@ -24,7 +24,6 @@ // Author: Konstantin Leontev // #include "LightApp_ExtInfoDlg.h" -#include "LightApp_Application.h" #include "utilities.h" // Prevent slot compilation error @@ -33,19 +32,12 @@ #include "PyInterp_Utils.h" #pragma pop_macro("slots") -#include -#include - -#include - -#include #include -#include -#include -#include -#include -#include -#include // to get path to the file + +// Show extensions info +#include +#include +#include // Render dependency tree #include @@ -59,8 +51,7 @@ LightApp_ExtInfoDlg::LightApp_ExtInfoDlg(QWidget* parent) MESSAGE("Start creating a dialog...\n"); setObjectName("salome_ext_info_dialog"); - QString capText = tr("EXT_INFO_CAPTION"); - setWindowTitle(capText); + setWindowTitle(tr("EXT_INFO_CAPTION")); setSizeGripEnabled(true); setButtonPosition(ButtonPosition::Center, ButtonFlags::OK); @@ -70,8 +61,6 @@ LightApp_ExtInfoDlg::LightApp_ExtInfoDlg(QWidget* parent) auto layout = new QHBoxLayout(mainFrame()); layout->addWidget(extInfoWiget); layout->addWidget(extTreeWiget); - layout->setStretch(0, 5); - layout->setStretch(1, 5); } /*!Destructor.*/ @@ -80,50 +69,97 @@ LightApp_ExtInfoDlg::~LightApp_ExtInfoDlg() //! Do nothing. } -/*! Return widget with info about installed extensions */ -QWidget* LightApp_ExtInfoDlg::getExtListWidget(QWidget* parent) const +/*! Fill the given widget with info about installed extensions */ +bool LightApp_ExtInfoDlg::fillExtListWidget(QTableWidget* extListWidget) const { - MESSAGE("Start to get modules info...\n"); - - auto extListWidget = new QWidget(parent); - auto app = dynamic_cast(SUIT_Session::session()->activeApplication()); - ASSERT(app); - if (!app) - { - return extListWidget; - } - - auto gridLayout = new QGridLayout(extListWidget); - gridLayout->setSpacing(5); + MESSAGE("Getting info from SalomeOnDemandTK.extension_query...\n"); // Import Python module that manages SALOME extensions PyLockWrapper lck; // acquire GIL PyObjWrapper extensionQuery = PyImport_ImportModule((char*)"SalomeOnDemandTK.extension_query"); auto extRootDir = getenv("SALOME_APPLICATION_DIR"); PyObjWrapper extInfoDict = PyObject_CallMethod(extensionQuery, (char*)"ext_info_dict", (char*)"s", extRootDir); - ASSERT(extInfoDict); + if (!extInfoDict) + { + PyErr_Print(); + return false; + } - if (extInfoDict) + // Check if we have any info to display + Py_ssize_t rowCount = PyDict_Size(extInfoDict); + if (!rowCount) { - PyObject *key = nullptr; - PyObject *value = nullptr; - Py_ssize_t pos = 0; + MESSAGE("Didn't find any extensions! Return.\n"); + return false; + } - while (PyDict_Next(extInfoDict, &pos, &key, &value)) - { - auto name = new QLabel(PyUnicode_AsUTF8(key), extListWidget); - auto size = new QLabel(PyUnicode_AsUTF8(value), extListWidget); + extListWidget->setRowCount(rowCount); + const int columnCount = extListWidget->columnCount(); - gridLayout->addWidget(name , pos, 0); - gridLayout->addWidget(size , pos, 1); + auto makeTableWidgetItem = [](PyObject* itemText) -> QTableWidgetItem* + { + const char* itemTextStr = PyUnicode_AsUTF8(itemText); + SCRUTE(itemTextStr); + + return new QTableWidgetItem(itemTextStr); + }; - SCRUTE(name->text().toStdString()); - SCRUTE(size->text().toStdString()); + PyObject* keyName = nullptr; + PyObject* infoList = nullptr; + Py_ssize_t keyNamePos = 0; + + // Iterate name:info_list dictionary + while (PyDict_Next(extInfoDict, &keyNamePos, &keyName, &infoList)) + { + auto widgetItem = makeTableWidgetItem(keyName); + + // keyNamePos is already 1 on the first iteration, so we need to decrease it + extListWidget->setItem(keyNamePos - 1, 0, widgetItem); + + // Iterate an extension info list + for (Py_ssize_t infoPos = 0; infoPos < PyList_Size(infoList); ++infoPos) + { + if (infoPos >= columnCount) + { + MESSAGE("Number of info items is greater than column count! Skip.\n"); + break; + } + + auto info = PyList_GetItem(infoList, infoPos); + widgetItem = makeTableWidgetItem(info); + + // keyNamePos started from 1 instead of 0, so decrease + // info need to be filled from column 1, so increase + extListWidget->setItem(keyNamePos - 1, infoPos + 1, widgetItem); } } - else + + return true; +} + +/*! Return widget with info about installed extensions */ +QWidget* LightApp_ExtInfoDlg::getExtListWidget(QWidget* parent) const +{ + MESSAGE("Make a widget to display extensions info...\n"); + + auto extListWidget = new QTableWidget(parent); + + // Setup the table params + const QStringList headerLabels = { + "Name", "Description", "Author", "Components", "Size" + }; + + extListWidget->setColumnCount(headerLabels.count()); + extListWidget->setHorizontalHeaderLabels(headerLabels); + + // Fill it with data about extensions + if (fillExtListWidget(extListWidget)) { - PyErr_Print(); + // Tune an appearance + extListWidget->sortItems(0); + extListWidget->horizontalHeader()->setStretchLastSection(true); + extListWidget->resizeColumnsToContents(); + extListWidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); } return extListWidget; @@ -135,12 +171,6 @@ QWidget* LightApp_ExtInfoDlg::getExtTreeWidget(QWidget* parent) const MESSAGE("Start to get extensions dependency tree...\n"); auto extTreeWidget = new QSvgWidget(parent); - auto app = dynamic_cast(SUIT_Session::session()->activeApplication()); - ASSERT(app); - if (!app) - { - return extTreeWidget; - } // Import Python module that manages SALOME extensions PyLockWrapper lck; // acquire GIL diff --git a/src/LightApp/LightApp_ExtInfoDlg.h b/src/LightApp/LightApp_ExtInfoDlg.h index 16183bc30..3db7e0a66 100644 --- a/src/LightApp/LightApp_ExtInfoDlg.h +++ b/src/LightApp/LightApp_ExtInfoDlg.h @@ -30,7 +30,7 @@ #include -class QLabel; +class QTableWidget; /*! \class LightApp_ExtInfoDlg @@ -47,6 +47,8 @@ public: private: QWidget* getExtListWidget(QWidget* parent) const; QWidget* getExtTreeWidget(QWidget* parent) const; + + bool fillExtListWidget(QTableWidget* extListWidget) const; }; #endif -- 2.39.2