Skip to content

Commit

Permalink
plugingenerator: Changed pdk templates.
Browse files Browse the repository at this point in the history
Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Aug 21, 2024
1 parent 8bf6fa6 commit 8d4e837
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 39 deletions.
4 changes: 2 additions & 2 deletions tools/plugingenerator/plugin_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
if pdkSupport:
pdkPath = generatorOptions["pdk"]["project_path"]
if not pdkPath:
pdkPath = os.path.join(pathToScopy, "ScopyPDK")
pdkPath = os.path.join(pathToScopy, "ScopyPluginRunner")
else:
pdkPath = os.path.join(pdkPath, "ScopyPDK")
pdkPath = os.path.join(pdkPath, "ScopyPluginRunner")
try:
os.mkdir(pdkPath, mode)
directoriesGenerated.append(pdkPath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.9)

# Project name
set(TARGET_NAME "ScopyPDK")
set(TARGET_NAME "ScopyPluginRunner")

project(${"${TARGET_NAME}"} VERSION 0.0.1 DESCRIPTION "Project Description")

Expand Down
9 changes: 8 additions & 1 deletion tools/plugingenerator/templates/pdk/pdk_header_template.mako
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public:
public Q_SLOTS:
void onConnect();
void onDisconnect();
void onLoad();
void onUnload();
Q_SIGNALS:
void sigLabelTextUpdated(std::string_view);

Expand Down Expand Up @@ -51,28 +53,33 @@ public:
Q_SIGNALS:
void connected();
void disconnected();
void loaded();
void unloaded();

private Q_SLOTS:
void onConnect();
void onDisconnect();
void loadPlugin();
void unloadPlugin();
void browseFile(QLineEdit *pluginPathEdit);

private:
void unloadPluginDetails();
void loadPluginDetails();
void btnsActivation();
bool validConnection(QString uri, QString cat);
bool isCompatible(QString uri, QString cat);

PluginManager *m_pluginManager;
QLineEdit *m_uriEdit;
QLineEdit *m_pluginPathEdit;
QPushButton *m_connBtn;
QPushButton *m_disconnBtn;
QPushButton *m_loadBtn;
QPushButton *m_unloadBtn;
QWidget *m_pluginIcon;
scopy::MenuCombo *m_deviceTypeCb;
QScrollArea *m_scrollArea;
bool m_connected;
};

class PluginManager : public QObject
Expand Down
125 changes: 90 additions & 35 deletions tools/plugingenerator/templates/pdk/pdk_src_template.mako
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ PDKWindow::PDKWindow(QWidget *parent)
addHorizontalTab(m_prefPage, createTabLabel("Preferences"));
connect(m_mainWidget, &MainWidget::connected, this, &PDKWindow::onConnect);
connect(m_mainWidget, &MainWidget::disconnected, this, &PDKWindow::onDisconnect);
connect(m_mainWidget, &MainWidget::loaded, this, &PDKWindow::onLoad);
connect(m_mainWidget, &MainWidget::unloaded, this, &PDKWindow::onUnload);
}

PDKWindow::~PDKWindow()
Expand All @@ -60,7 +62,6 @@ PDKWindow::~PDKWindow()

void PDKWindow::onConnect()
{
addPluginPrefPage();
QList<scopy::ToolMenuEntry *> tools = m_mainWidget->getPluginTools();
for(const scopy::ToolMenuEntry *t : qAsConst(tools)) {
if(!t->tool())
Expand All @@ -78,14 +79,21 @@ void PDKWindow::onConnect()

void PDKWindow::onDisconnect()
{
removePluginPrefPage();
QList<scopy::ToolMenuEntry *> tools = m_mainWidget->getPluginTools();
for(const scopy::ToolMenuEntry *t : qAsConst(tools)) {
t->disconnect(this);
}
for(auto t : qAsConst(m_toolList)) {
int idx = m_tabWidget->indexOf(t);
m_tabWidget->removeTab(idx);
m_toolList.removeOne(t);
}
}

void PDKWindow::onLoad() { addPluginPrefPage(); }

void PDKWindow::onUnload() { removePluginPrefPage(); }

void PDKWindow::initMainWindow()
{
QWidget *centralWidget = new QWidget(this);
Expand Down Expand Up @@ -170,23 +178,45 @@ QLabel *PDKWindow::createTabLabel(QString name)

MainWidget::MainWidget(QWidget *parent)
: QWidget(parent)
, m_pluginManager(nullptr)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMinimumWidth(1024);
QGridLayout *lay = new QGridLayout(this);
lay->setMargin(9);
lay->setSpacing(6);

// load section
m_loadBtn = new QPushButton("Load plugin", this);
scopy::StyleHelper::BlueGrayButton(m_loadBtn);
m_loadBtn->setFixedWidth(128);
// browse section
QPushButton *browseBtn = new QPushButton("Browse", this);
scopy::StyleHelper::BlueGrayButton(browseBtn);
browseBtn->setFixedWidth(128);

m_pluginPathEdit = new QLineEdit(this);
m_pluginPathEdit->setText(PLUGIN_INSTALL_PATH);
m_pluginPathEdit->setPlaceholderText(PLUGIN_INSTALL_PATH);
connect(m_loadBtn, &QPushButton::clicked, this, [this]() { browseFile(m_pluginPathEdit); });
connect(browseBtn, &QPushButton::clicked, this, [this]() { browseFile(m_pluginPathEdit); });

QWidget *loadBtns = new QWidget(this);
loadBtns->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
loadBtns->setLayout(new QVBoxLayout(loadBtns));
loadBtns->layout()->setSpacing(0);
loadBtns->layout()->setMargin(0);
// load section
m_loadBtn = new QPushButton("Load", loadBtns);
scopy::StyleHelper::BlueGrayButton(m_loadBtn);
m_loadBtn->setFixedWidth(128);

connect(m_loadBtn, &QPushButton::clicked, this, &MainWidget::loadPlugin);

// unload
m_unloadBtn = new QPushButton("Unload", loadBtns);
scopy::StyleHelper::BlueGrayButton(m_unloadBtn);
m_unloadBtn->setFixedWidth(128);
m_unloadBtn->setVisible(false);
connect(m_unloadBtn, &QPushButton::clicked, this, &MainWidget::unloadPlugin);

loadBtns->layout()->addWidget(m_loadBtn);
loadBtns->layout()->addWidget(m_unloadBtn);
// connect section
m_uriEdit = new QLineEdit(this);
m_uriEdit->setPlaceholderText("URI");
Expand All @@ -197,19 +227,26 @@ MainWidget::MainWidget(QWidget *parent)
m_deviceTypeCb->combo()->addItem("iio");
m_deviceTypeCb->combo()->addItem("test");

QWidget *connBtns = new QWidget(this);
connBtns->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
connBtns->setLayout(new QVBoxLayout(connBtns));
connBtns->layout()->setSpacing(0);
connBtns->layout()->setMargin(0);

m_connBtn = new QPushButton("Connect", this);
scopy::StyleHelper::BlueGrayButton(m_connBtn);
m_connBtn->setCheckable(true);
m_connBtn->setFixedWidth(128);
m_connBtn->setEnabled(false);
connect(m_connBtn, &QPushButton::clicked, this, &MainWidget::onConnect);

// unload
m_unloadBtn = new QPushButton("Unload", this);
scopy::StyleHelper::BlueGrayButton(m_unloadBtn);
m_unloadBtn->setFixedWidth(128);
m_unloadBtn->setEnabled(false);
connect(m_unloadBtn, &QPushButton::clicked, this, &MainWidget::onDisconnect);
m_disconnBtn = new QPushButton("Disconnect", this);
scopy::StyleHelper::BlueGrayButton(m_disconnBtn);
m_disconnBtn->setFixedWidth(128);
m_disconnBtn->setVisible(false);
connect(m_disconnBtn, &QPushButton::clicked, this, &MainWidget::onDisconnect);

connBtns->layout()->addWidget(m_connBtn);
connBtns->layout()->addWidget(m_disconnBtn);
// plugin info
QWidget *pluginPage = new QWidget(this);
pluginPage->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Expand All @@ -227,20 +264,20 @@ MainWidget::MainWidget(QWidget *parent)
m_pluginIcon->setFixedSize(100, 100);

lay->addWidget(m_pluginPathEdit, 0, 0);
lay->addWidget(m_uriEdit, 1, 0);
lay->addWidget(m_deviceTypeCb, 2, 0);
lay->addWidget(m_deviceTypeCb, 1, 0);
lay->addWidget(m_uriEdit, 2, 0);
lay->addWidget(pluginPage, 3, 0);

lay->addWidget(m_loadBtn, 0, 1);
lay->addWidget(m_connBtn, 1, 1);
lay->addWidget(m_unloadBtn, 2, 1);
lay->addWidget(browseBtn, 0, 1, Qt::AlignTop);
lay->addWidget(loadBtns, 1, 1, Qt::AlignTop);
lay->addWidget(connBtns, 2, 1, Qt::AlignTop);
lay->addWidget(m_pluginIcon, 3, 1, Qt::AlignCenter | Qt::AlignBottom);
}

MainWidget::~MainWidget()
{
if(m_pluginManager && !m_connBtn->isEnabled()) {
onDisconnect();
if(m_pluginManager) {
unloadPlugin();
}
}

Expand All @@ -257,6 +294,25 @@ QWidget *MainWidget::pluginPrefPage()
QList<scopy::ToolMenuEntry *> MainWidget::getPluginTools() { return m_pluginManager->plugin()->toolList(); }

void MainWidget::onConnect()
{
if(!m_pluginManager->plugin()->onConnect()) {
return;
}
m_disconnBtn->setVisible(true);
m_connBtn->setVisible(false);
m_connected = true;
Q_EMIT connected();
}

void MainWidget::onDisconnect()
{
m_pluginManager->plugin()->onDisconnect();
m_disconnBtn->setVisible(false);
m_connBtn->setVisible(true);
Q_EMIT disconnected();
}

void MainWidget::loadPlugin()
{
QString uri = m_uriEdit->text();
QString cat = m_deviceTypeCb->combo()->currentText();
Expand All @@ -266,27 +322,32 @@ void MainWidget::onConnect()
return;
}
m_pluginManager = new PluginManager(pluginPath, this);
if(!isCompatible(uri, cat) || !m_pluginManager->plugin()->onConnect()) {
if(!isCompatible(uri, cat)) {
m_connBtn->setChecked(false);
delete m_pluginManager;
m_pluginManager = nullptr;
return;
}
btnsActivation();
loadPluginDetails();
Q_EMIT connected();
m_loadBtn->setVisible(false);
m_unloadBtn->setVisible(true);
m_connBtn->setEnabled(true);
Q_EMIT loaded();
}

void MainWidget::onDisconnect()
void MainWidget::unloadPlugin()
{
btnsActivation();
unloadPluginDetails();
m_pluginManager->plugin()->onDisconnect();
if(m_connected) {
onDisconnect();
}
m_pluginManager->plugin()->unload();
m_connBtn->setChecked(false);
delete m_pluginManager;
m_pluginManager = nullptr;
Q_EMIT disconnected();
m_unloadBtn->setVisible(false);
m_loadBtn->setVisible(true);
m_connBtn->setEnabled(false);
Q_EMIT unloaded();
}

void MainWidget::browseFile(QLineEdit *pluginPathEdit)
Expand Down Expand Up @@ -320,12 +381,6 @@ void MainWidget::loadPluginDetails()
}
}

void MainWidget::btnsActivation()
{
m_unloadBtn->setEnabled(!m_unloadBtn->isEnabled());
m_connBtn->setEnabled(!m_connBtn->isEnabled());
}

bool MainWidget::validConnection(QString uri, QString cat)
{
ConnectionStrategy *connStrategy = new ConnectionStrategy(uri, this);
Expand Down

0 comments on commit 8d4e837

Please sign in to comment.