fix a couple of bugs that would hang the app waiting for log output

This commit is contained in:
Axel Kohlmeyer
2023-08-02 05:25:24 -04:00
parent c99d0f5452
commit c918bdeb07
2 changed files with 5 additions and 4 deletions

View File

@ -369,7 +369,7 @@ void LammpsGui::logupdate()
double t_elapsed, t_remain, t_total; double t_elapsed, t_remain, t_total;
int completed = 1000; int completed = 1000;
if (is_running) { if (lammps.is_running()) {
t_elapsed = lammps.get_thermo("cpu"); t_elapsed = lammps.get_thermo("cpu");
t_remain = lammps.get_thermo("cpuremain"); t_remain = lammps.get_thermo("cpuremain");
t_total = t_elapsed + t_remain + 1.0e-10; t_total = t_elapsed + t_remain + 1.0e-10;
@ -441,7 +441,8 @@ void LammpsGui::run_buffer()
clear(); clear();
capturer->BeginCapture(); capturer->BeginCapture();
char *input = mystrdup(ui->textEdit->toPlainText().toStdString()); // always add final newline since the text edit widget does not
char *input = mystrdup(ui->textEdit->toPlainText().toStdString() + "\n");
is_running = true; is_running = true;
LammpsRunner *runner = new LammpsRunner(this); LammpsRunner *runner = new LammpsRunner(this);
@ -524,7 +525,6 @@ void LammpsGui::view_image()
void LammpsGui::clear() void LammpsGui::clear()
{ {
if (!lammps.is_open()) lammps.command("clear");
ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor); ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
} }

View File

@ -20,13 +20,14 @@ class LammpsRunner : public QThread {
Q_OBJECT Q_OBJECT
public: public:
LammpsRunner(QObject *parent = nullptr) : QThread(parent), lammps(nullptr), input(nullptr) {} LammpsRunner(QObject *parent = nullptr) : QThread(parent), lammps(nullptr), input(nullptr) {}
~LammpsRunner() = default; ~LammpsRunner() = default;
public: public:
// execute LAMMPS in runner thread // execute LAMMPS in runner thread
void run() override void run() override
{ {
lammps->command("clear");
lammps->commands_string(input); lammps->commands_string(input);
emit resultReady(); emit resultReady();
} }