Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cd67e8ddd7 | ||
![]() |
b6fb6ca7d4 | ||
![]() |
73aa61a13b | ||
![]() |
8ad659de76 |
|
@ -1,6 +1,7 @@
|
||||||
#include <eismultiplexer.h>
|
#include <eismultiplexer.h>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <set>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -12,6 +13,7 @@ MainWindow::MainWindow(QWidget *parent):
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
codeEditor(this),
|
codeEditor(this),
|
||||||
|
pythonOutput(this),
|
||||||
currentFilePath(""),
|
currentFilePath(""),
|
||||||
isFileModified(false)
|
isFileModified(false)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +28,10 @@ MainWindow::MainWindow(QWidget *parent):
|
||||||
font.setStyleHint(QFont::TypeWriter);
|
font.setStyleHint(QFont::TypeWriter);
|
||||||
codeEditor.setFont(font);
|
codeEditor.setFont(font);
|
||||||
|
|
||||||
ui->codeLayout->addWidget(&codeEditor);
|
ui->codeLayout->addWidget(&codeEditor, 1);
|
||||||
|
|
||||||
|
pythonOutput.setReadOnly(true);
|
||||||
|
ui->codeLayout->addWidget(&pythonOutput);
|
||||||
|
|
||||||
// Set up keyboard shortcuts
|
// Set up keyboard shortcuts
|
||||||
ui->actionOpen->setShortcut(QKeySequence::Open);
|
ui->actionOpen->setShortcut(QKeySequence::Open);
|
||||||
|
@ -42,7 +47,7 @@ MainWindow::MainWindow(QWidget *parent):
|
||||||
// Connect text changed signal to track modifications
|
// Connect text changed signal to track modifications
|
||||||
connect(&codeEditor, &QTextEdit::textChanged, this, [this]() {
|
connect(&codeEditor, &QTextEdit::textChanged, this, [this]() {
|
||||||
isFileModified = true;
|
isFileModified = true;
|
||||||
updateTitle();
|
updateStatus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,16 +56,16 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateTitle()
|
void MainWindow::updateStatus()
|
||||||
{
|
{
|
||||||
QString windowTitle = "EisMultiplexer-Qt";
|
|
||||||
if (!currentFilePath.isEmpty()) {
|
if (!currentFilePath.isEmpty()) {
|
||||||
windowTitle = QString("%1 - %2").arg(currentFilePath);
|
QString status = "EisMultiplexer-Qt";
|
||||||
}
|
status = QString("%1").arg(currentFilePath);
|
||||||
if (isFileModified) {
|
if (isFileModified) {
|
||||||
windowTitle += "[*]";
|
status += " - [Unsaved Changes]";
|
||||||
|
}
|
||||||
|
ui->statusbar->showMessage(status);
|
||||||
}
|
}
|
||||||
setWindowTitle(windowTitle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onActionOpenTriggered()
|
void MainWindow::onActionOpenTriggered()
|
||||||
|
@ -86,7 +91,7 @@ void MainWindow::onActionOpenTriggered()
|
||||||
codeEditor.setPlainText(content);
|
codeEditor.setPlainText(content);
|
||||||
currentFilePath = filePath;
|
currentFilePath = filePath;
|
||||||
isFileModified = false;
|
isFileModified = false;
|
||||||
updateTitle();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onActionSaveTriggered()
|
void MainWindow::onActionSaveTriggered()
|
||||||
|
@ -107,7 +112,7 @@ void MainWindow::onActionSaveTriggered()
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
isFileModified = false;
|
isFileModified = false;
|
||||||
updateTitle();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onActionSaveAsTriggered()
|
void MainWindow::onActionSaveAsTriggered()
|
||||||
|
@ -120,13 +125,6 @@ void MainWindow::onActionSaveAsTriggered()
|
||||||
return;
|
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);
|
QFile file(filePath);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Could not save file: %1").arg(filePath));
|
QMessageBox::warning(this, tr("Error"), tr("Could not save file: %1").arg(filePath));
|
||||||
|
@ -139,7 +137,7 @@ void MainWindow::onActionSaveAsTriggered()
|
||||||
|
|
||||||
currentFilePath = filePath;
|
currentFilePath = filePath;
|
||||||
isFileModified = false;
|
isFileModified = false;
|
||||||
updateTitle();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::enumerateDevices()
|
void MainWindow::enumerateDevices()
|
||||||
|
@ -225,17 +223,47 @@ void MainWindow::enumerateDevices()
|
||||||
ui->statusbar->showMessage("Ready");
|
ui->statusbar->showMessage("Ready");
|
||||||
|
|
||||||
free(serials);
|
free(serials);
|
||||||
|
generateExample();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::generateExample()
|
void MainWindow::generateExample()
|
||||||
{
|
{
|
||||||
QString example =
|
QString example =
|
||||||
"import eismultiplexer\n\n"
|
"# This is an example script to show you how\n# to drive eismultiplexer using the python api\n"
|
||||||
"from time import sleep";
|
"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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class MainWindow : public QMainWindow
|
||||||
QCodeEditor codeEditor;
|
QCodeEditor codeEditor;
|
||||||
QPythonHighlighter highligter;
|
QPythonHighlighter highligter;
|
||||||
QPythonCompleter completer;
|
QPythonCompleter completer;
|
||||||
|
QTextEdit pythonOutput;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void channelStateChanged(uint16_t device, uint16_t channel);
|
void channelStateChanged(uint16_t device, uint16_t channel);
|
||||||
|
@ -42,7 +43,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void enumerateDevices();
|
void enumerateDevices();
|
||||||
void generateExample();
|
void generateExample();
|
||||||
void updateTitle();
|
void updateStatus();
|
||||||
QString currentFilePath;
|
QString currentFilePath;
|
||||||
bool isFileModified;
|
bool isFileModified;
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,8 +59,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>595</width>
|
<width>591</width>
|
||||||
<height>537</height>
|
<height>533</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
|
Loading…
Reference in a new issue