Compare commits

..

No commits in common. "master" and "actions" have entirely different histories.

3 changed files with 26 additions and 55 deletions

View file

@ -1,7 +1,6 @@
#include <eismultiplexer.h>
#include <QMessageBox>
#include <QMessageBox>
#include <set>
#include <QFileDialog>
#include <QTextStream>
#include <QFile>
@ -13,7 +12,6 @@ MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow),
codeEditor(this),
pythonOutput(this),
currentFilePath(""),
isFileModified(false)
{
@ -28,10 +26,7 @@ MainWindow::MainWindow(QWidget *parent):
font.setStyleHint(QFont::TypeWriter);
codeEditor.setFont(font);
ui->codeLayout->addWidget(&codeEditor, 1);
pythonOutput.setReadOnly(true);
ui->codeLayout->addWidget(&pythonOutput);
ui->codeLayout->addWidget(&codeEditor);
// Set up keyboard shortcuts
ui->actionOpen->setShortcut(QKeySequence::Open);
@ -47,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent):
// Connect text changed signal to track modifications
connect(&codeEditor, &QTextEdit::textChanged, this, [this]() {
isFileModified = true;
updateStatus();
updateTitle();
});
}
@ -56,16 +51,16 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::updateStatus()
void MainWindow::updateTitle()
{
QString windowTitle = "EisMultiplexer-Qt";
if (!currentFilePath.isEmpty()) {
QString status = "EisMultiplexer-Qt";
status = QString("%1").arg(currentFilePath);
windowTitle = QString("%1 - %2").arg(currentFilePath);
}
if (isFileModified) {
status += " - [Unsaved Changes]";
}
ui->statusbar->showMessage(status);
windowTitle += "[*]";
}
setWindowTitle(windowTitle);
}
void MainWindow::onActionOpenTriggered()
@ -91,7 +86,7 @@ void MainWindow::onActionOpenTriggered()
codeEditor.setPlainText(content);
currentFilePath = filePath;
isFileModified = false;
updateStatus();
updateTitle();
}
void MainWindow::onActionSaveTriggered()
@ -112,7 +107,7 @@ void MainWindow::onActionSaveTriggered()
file.close();
isFileModified = false;
updateStatus();
updateTitle();
}
void MainWindow::onActionSaveAsTriggered()
@ -125,6 +120,13 @@ 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));
@ -137,7 +139,7 @@ void MainWindow::onActionSaveAsTriggered()
currentFilePath = filePath;
isFileModified = false;
updateStatus();
updateTitle();
}
void MainWindow::enumerateDevices()
@ -223,47 +225,17 @@ void MainWindow::enumerateDevices()
ui->statusbar->showMessage("Ready");
free(serials);
generateExample();
}
void MainWindow::generateExample()
{
QString example =
"# 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";
"import eismultiplexer\n\n"
"from time import sleep";
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)
for (const auto& channel : channels)
{
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);
example.append(QString("eismultiplexer"));
}
}

View file

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

View file

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