// Author: Konstantin Leontev
//
#include "LightApp_ExtInfoDlg.h"
-#include "LightApp_Application.h"
#include "utilities.h"
// Prevent slot compilation error
#include "PyInterp_Utils.h"
#pragma pop_macro("slots")
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.h>
-
-#include <QtxGridBox.h>
-
-#include <QLabel>
#include <QHBoxLayout>
-#include <QPixmap>
-#include <QIcon>
-#include <QGroupBox>
-#include <QTabWidget>
-#include <QPushButton>
-#include <QFileInfo> // to get path to the file
+
+// Show extensions info
+#include <QTableWidget>
+#include <QTableWidgetItem>
+#include <QHeaderView>
// Render dependency tree
#include <QSvgWidget>
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);
auto layout = new QHBoxLayout(mainFrame());
layout->addWidget(extInfoWiget);
layout->addWidget(extTreeWiget);
- layout->setStretch(0, 5);
- layout->setStretch(1, 5);
}
/*!Destructor.*/
//! 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<LightApp_Application*>(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;
MESSAGE("Start to get extensions dependency tree...\n");
auto extTreeWidget = new QSvgWidget(parent);
- auto app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
- ASSERT(app);
- if (!app)
- {
- return extTreeWidget;
- }
// Import Python module that manages SALOME extensions
PyLockWrapper lck; // acquire GIL