|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include <eismultiplexer.h>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QFile>
|
|
|
|
@ -12,6 +13,7 @@ MainWindow::MainWindow(QWidget *parent):
|
|
|
|
|
QMainWindow(parent),
|
|
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
|
codeEditor(this),
|
|
|
|
|
pythonOutput(this),
|
|
|
|
|
currentFilePath(""),
|
|
|
|
|
isFileModified(false)
|
|
|
|
|
{
|
|
|
|
@ -26,7 +28,10 @@ MainWindow::MainWindow(QWidget *parent):
|
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
|
codeEditor.setFont(font);
|
|
|
|
|
|
|
|
|
|
ui->codeLayout->addWidget(&codeEditor);
|
|
|
|
|
ui->codeLayout->addWidget(&codeEditor, 1);
|
|
|
|
|
|
|
|
|
|
pythonOutput.setReadOnly(true);
|
|
|
|
|
ui->codeLayout->addWidget(&pythonOutput);
|
|
|
|
|
|
|
|
|
|
// Set up keyboard shortcuts
|
|
|
|
|
ui->actionOpen->setShortcut(QKeySequence::Open);
|
|
|
|
@ -42,7 +47,7 @@ MainWindow::MainWindow(QWidget *parent):
|
|
|
|
|
// Connect text changed signal to track modifications
|
|
|
|
|
connect(&codeEditor, &QTextEdit::textChanged, this, [this]() {
|
|
|
|
|
isFileModified = true;
|
|
|
|
|
updateTitle();
|
|
|
|
|
updateStatus();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -51,16 +56,16 @@ MainWindow::~MainWindow()
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateTitle()
|
|
|
|
|
void MainWindow::updateStatus()
|
|
|
|
|
{
|
|
|
|
|
QString windowTitle = "EisMultiplexer-Qt";
|
|
|
|
|
if (!currentFilePath.isEmpty()) {
|
|
|
|
|
windowTitle = QString("%1 - %2").arg(currentFilePath);
|
|
|
|
|
}
|
|
|
|
|
QString status = "EisMultiplexer-Qt";
|
|
|
|
|
status = QString("%1").arg(currentFilePath);
|
|
|
|
|
if (isFileModified) {
|
|
|
|
|
windowTitle += "[*]";
|
|
|
|
|
status += " - [Unsaved Changes]";
|
|
|
|
|
}
|
|
|
|
|
ui->statusbar->showMessage(status);
|
|
|
|
|
}
|
|
|
|
|
setWindowTitle(windowTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onActionOpenTriggered()
|
|
|
|
@ -86,7 +91,7 @@ void MainWindow::onActionOpenTriggered()
|
|
|
|
|
codeEditor.setPlainText(content);
|
|
|
|
|
currentFilePath = filePath;
|
|
|
|
|
isFileModified = false;
|
|
|
|
|
updateTitle();
|
|
|
|
|
updateStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onActionSaveTriggered()
|
|
|
|
@ -107,7 +112,7 @@ void MainWindow::onActionSaveTriggered()
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
isFileModified = false;
|
|
|
|
|
updateTitle();
|
|
|
|
|
updateStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onActionSaveAsTriggered()
|
|
|
|
@ -120,13 +125,6 @@ void MainWindow::onActionSaveAsTriggered()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure the file has a .py extension if it's a Python file
|
|
|
|
|
if (filePath.endsWith(".py", Qt::CaseInsensitive)) {
|
|
|
|
|
// File already has .py extension
|
|
|
|
|
} else {
|
|
|
|
|
filePath += ".py";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
|
QMessageBox::warning(this, tr("Error"), tr("Could not save file: %1").arg(filePath));
|
|
|
|
@ -139,7 +137,7 @@ void MainWindow::onActionSaveAsTriggered()
|
|
|
|
|
|
|
|
|
|
currentFilePath = filePath;
|
|
|
|
|
isFileModified = false;
|
|
|
|
|
updateTitle();
|
|
|
|
|
updateStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::enumerateDevices()
|
|
|
|
@ -225,17 +223,47 @@ void MainWindow::enumerateDevices()
|
|
|
|
|
ui->statusbar->showMessage("Ready");
|
|
|
|
|
|
|
|
|
|
free(serials);
|
|
|
|
|
generateExample();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::generateExample()
|
|
|
|
|
{
|
|
|
|
|
QString example =
|
|
|
|
|
"import eismultiplexer\n\n"
|
|
|
|
|
"from time import sleep";
|
|
|
|
|
"# This is an example script to show you how\n# to drive eismultiplexer using the python api\n"
|
|
|
|
|
"import eismultiplexer as multi\n"
|
|
|
|
|
"from time import sleep\n\n"
|
|
|
|
|
"# First initalize the device(s)\n";
|
|
|
|
|
|
|
|
|
|
for (const auto& channel : channels)
|
|
|
|
|
std::set<uint16_t> serials;
|
|
|
|
|
for (size_t i = 0; i < channels.size(); ++i)
|
|
|
|
|
serials.insert(channels[i]->getDeviceSerial());
|
|
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
for (uint16_t serial : serials)
|
|
|
|
|
{
|
|
|
|
|
example.append(QString("eismultiplexer"));
|
|
|
|
|
example.append(QString("multiplexer_") + QString::number(i) + " multi.Multiplexer(serial=" + QString::number(serial) + ")\n");
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
example.append("\nprint('\\nListing the nummber of channels per unit')\n");
|
|
|
|
|
for (size_t i = 0; i < serials.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
QString printLine = "print(f'Found unit with serial number {" + QString::number(channels[i]->getDeviceSerial()) + "} and {multiplexer_" + QString::number(i) + ".getChannelCount()} channels')\n";
|
|
|
|
|
example.append(printLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
example.append("\nprint('Connecting the first and second channel on the first unit')\n");
|
|
|
|
|
example.append("multiplexer_0.connectChannel(multi.Channel.A)\n");
|
|
|
|
|
example.append("multiplexer_0.connectChannel(multi.Channel.B)\n\n");
|
|
|
|
|
example.append("print('Waiting for half a second for something to happen')\n");
|
|
|
|
|
example.append("sleep(0.5)\n\n");
|
|
|
|
|
example.append("print('Disconnect first channel')\n");
|
|
|
|
|
example.append("multiplexer_0.disconnectChannel(multi.Channel.A)\n\n");
|
|
|
|
|
example.append("print('Waiting up to 5000 milliseconds for a trigger')\n");
|
|
|
|
|
example.append("multiplexer_0.setTriggerState(0, multi.TriggerState.INPUT)\n");
|
|
|
|
|
example.append("multiplexer_0.waitTrigger(0, multi.TriggerState.HIGHLEVEL, 5000)\n\n");
|
|
|
|
|
example.append("print('Disconnecting all channels')\n");
|
|
|
|
|
example.append("multiplexer_0.clear()\n");
|
|
|
|
|
codeEditor.setText(example);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|