Compare commits

..

4 commits

Author SHA1 Message Date
Carl Philipp Klemm cd67e8ddd7 Add text edit to hold the output of the python script 2025-10-13 15:47:44 +02:00
Carl Philipp Klemm b6fb6ca7d4 Put the file name of the code editor into the satus bar instead of the title bar 2025-10-13 15:32:47 +02:00
Carl Philipp Klemm 73aa61a13b Merge remote-tracking branch 'uvos/actions' 2025-10-13 15:24:02 +02:00
Carl Philipp Klemm 8ad659de76 Add example generation 2025-10-13 15:21:17 +02:00
3 changed files with 55 additions and 26 deletions

View file

@ -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) {
status += " - [Unsaved Changes]";
}
ui->statusbar->showMessage(status);
}
if (isFileModified) {
windowTitle += "[*]";
}
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);
}

View file

@ -26,6 +26,7 @@ class MainWindow : public QMainWindow
QCodeEditor codeEditor;
QPythonHighlighter highligter;
QPythonCompleter completer;
QTextEdit pythonOutput;
signals:
void channelStateChanged(uint16_t device, uint16_t channel);
@ -42,7 +43,7 @@ private slots:
private:
void enumerateDevices();
void generateExample();
void updateTitle();
void updateStatus();
QString currentFilePath;
bool isFileModified;
};

View file

@ -59,8 +59,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>595</width>
<height>537</height>
<width>591</width>
<height>533</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">