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 <eismultiplexer.h>
#include <QMessageBox> #include <QMessageBox>
#include <QMessageBox> #include <QMessageBox>
#include <set>
#include <QFileDialog> #include <QFileDialog>
#include <QTextStream> #include <QTextStream>
#include <QFile> #include <QFile>
@ -13,7 +12,6 @@ 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)
{ {
@ -28,10 +26,7 @@ MainWindow::MainWindow(QWidget *parent):
font.setStyleHint(QFont::TypeWriter); font.setStyleHint(QFont::TypeWriter);
codeEditor.setFont(font); codeEditor.setFont(font);
ui->codeLayout->addWidget(&codeEditor, 1); ui->codeLayout->addWidget(&codeEditor);
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);
@ -47,7 +42,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;
updateStatus(); updateTitle();
}); });
} }
@ -56,16 +51,16 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::updateStatus() void MainWindow::updateTitle()
{ {
QString windowTitle = "EisMultiplexer-Qt";
if (!currentFilePath.isEmpty()) { if (!currentFilePath.isEmpty()) {
QString status = "EisMultiplexer-Qt"; windowTitle = QString("%1 - %2").arg(currentFilePath);
status = QString("%1").arg(currentFilePath);
if (isFileModified) {
status += " - [Unsaved Changes]";
}
ui->statusbar->showMessage(status);
} }
if (isFileModified) {
windowTitle += "[*]";
}
setWindowTitle(windowTitle);
} }
void MainWindow::onActionOpenTriggered() void MainWindow::onActionOpenTriggered()
@ -91,7 +86,7 @@ void MainWindow::onActionOpenTriggered()
codeEditor.setPlainText(content); codeEditor.setPlainText(content);
currentFilePath = filePath; currentFilePath = filePath;
isFileModified = false; isFileModified = false;
updateStatus(); updateTitle();
} }
void MainWindow::onActionSaveTriggered() void MainWindow::onActionSaveTriggered()
@ -112,7 +107,7 @@ void MainWindow::onActionSaveTriggered()
file.close(); file.close();
isFileModified = false; isFileModified = false;
updateStatus(); updateTitle();
} }
void MainWindow::onActionSaveAsTriggered() void MainWindow::onActionSaveAsTriggered()
@ -125,6 +120,13 @@ 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));
@ -137,7 +139,7 @@ void MainWindow::onActionSaveAsTriggered()
currentFilePath = filePath; currentFilePath = filePath;
isFileModified = false; isFileModified = false;
updateStatus(); updateTitle();
} }
void MainWindow::enumerateDevices() void MainWindow::enumerateDevices()
@ -223,47 +225,17 @@ 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 =
"# This is an example script to show you how\n# to drive eismultiplexer using the python api\n" "import eismultiplexer\n\n"
"import eismultiplexer as multi\n" "from time import sleep";
"from time import sleep\n\n"
"# First initalize the device(s)\n";
std::set<uint16_t> serials; for (const auto& channel : channels)
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("multiplexer_") + QString::number(i) + " multi.Multiplexer(serial=" + QString::number(serial) + ")\n"); example.append(QString("eismultiplexer"));
++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,7 +26,6 @@ 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);
@ -43,7 +42,7 @@ private slots:
private: private:
void enumerateDevices(); void enumerateDevices();
void generateExample(); void generateExample();
void updateStatus(); void updateTitle();
QString currentFilePath; QString currentFilePath;
bool isFileModified; bool isFileModified;
}; };

View file

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