Skip to content
Snippets Groups Projects
Commit 0f5bbe47 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #23570 Working Progress bar and threading improvements

parent debdffdf
No related merge requests found
Showing
with 75 additions and 34 deletions
......@@ -50,7 +50,7 @@ public:
~MultiTabScriptInterpreter() override;
/// Current interpreter
ScriptFileInterpreter *currentInterpreter();
ScriptFileInterpreter *currentInterpreter() { return m_current; };
/// Interpreter at given index
ScriptFileInterpreter *interpreterAt(int index);
......
......@@ -453,6 +453,8 @@ bool ProjectRecovery::loadRecoveryCheckpoint(const Poco::Path &recoveryFolder) {
throw std::runtime_error("Could not get handle to scripting window");
}
m_recoveryGui->connectProgressBarToRecoveryView();
// Ensure the window repaints so it doesn't appear frozen before exec
scriptWindow->executeCurrentTab(Script::ExecutionMode::Serialised);
if (scriptWindow->getSynchronousErrorFlag()) {
......
......@@ -91,6 +91,7 @@ public:
void removeLockedCheckpoints();
private:
friend class RecoveryThread;
/// Captures the current object in the background thread
std::thread createBackgroundThread();
......
......@@ -16,6 +16,7 @@
#include <Poco/Path.h>
#include <QThread>
#include <fstream>
#include <QApplication>
#include <memory>
namespace {
......@@ -81,7 +82,9 @@ void ProjectRecoveryModel::recoverSelectedCheckpoint(std::string &selected) {
Mantid::API::AnalysisDataService::Instance().clear();
// Recovery given the checkpoint selected here
selected.replace(selected.find(" "), 1, "T");
auto stringSpacePos = selected.find(" ");
if (stringSpacePos != std::string::npos)
selected.replace(stringSpacePos, 1, "T");
Poco::Path checkpoint(m_projRec->getRecoveryFolderLoadPR());
checkpoint.append(selected);
Poco::Path output(Mantid::Kernel::ConfigService::Instance().getAppDataDir());
......@@ -103,7 +106,9 @@ void ProjectRecoveryModel::openSelectedInEditor(std::string &selected) {
Mantid::API::AnalysisDataService::Instance().clear();
// Open editor for this checkpoint
selected.replace(selected.find(" "), 1, "T");
auto stringSpacePos = selected.find(" ");
if (stringSpacePos != std::string::npos)
selected.replace(stringSpacePos, 1, "T");
auto beforeCheckpoint = m_projRec->getRecoveryFolderLoadPR();
Poco::Path checkpoint(beforeCheckpoint);
checkpoint.append(selected);
......@@ -165,21 +170,24 @@ void ProjectRecoveryModel::updateCheckpointTried(
bool ProjectRecoveryModel::getFailedRun() const { return m_failedRun; }
void ProjectRecoveryModel::createThreadAndManage(const Poco::Path &checkpoint) {
std::unique_ptr<RecoveryThread> recoverThread =
std::make_unique<RecoveryThread>();
recoverThread->setProjRecPtr(m_projRec);
recoverThread->setCheckpoint(checkpoint);
recoverThread->start(QThread::HighestPriority);
// Wait for the thread to finish
recoverThread->wait();
RecoveryThread recoverThread;
recoverThread.setProjRecPtr(m_projRec);
recoverThread.setCheckpoint(checkpoint);
recoverThread.start(QThread::LowPriority);
while (!recoverThread.isFinished()){
std::this_thread::sleep_for(std::chrono::milliseconds(10));
QApplication::processEvents();
}
// Set failed run member to the value from the thread
m_failedRun = recoverThread->getFailedRun();
m_failedRun = recoverThread.getFailedRun();
}
std::string ProjectRecoveryModel::decideLastCheckpoint() {
auto mostRecentCheckpoints = m_projRec->getRecoveryFolderCheckpointsPR(
m_projRec->getRecoveryFolderLoadPR());
return mostRecentCheckpoints.back().toString();
auto mostRecentCheckpointPath = mostRecentCheckpoints.back();
return mostRecentCheckpointPath.directory(mostRecentCheckpointPath.depth() -
1);
}
\ No newline at end of file
......@@ -40,6 +40,7 @@ ProjectRecoveryPresenter::~ProjectRecoveryPresenter() {
bool ProjectRecoveryPresenter::startRecoveryView() {
try {
m_openView = RecoveryView;
m_recView = new ProjectRecoveryView(m_mainWindow, this);
m_recView->exec();
} catch (...) {
......@@ -54,6 +55,7 @@ bool ProjectRecoveryPresenter::startRecoveryView() {
bool ProjectRecoveryPresenter::startRecoveryFailure() {
try {
m_openView = FailureView;
m_failureView = new RecoveryFailureView(m_mainWindow, this);
m_failureView->exec();
} catch (...) {
......@@ -135,4 +137,13 @@ void ProjectRecoveryPresenter::setUpProgressBar(
if (secondView) {
secondView->setProgressBarMaximum(std::stoi(row[2]));
}
}
void ProjectRecoveryPresenter::connectProgressBarToRecoveryView(){
if (m_openView == RecoveryView){
m_recView->connectProgressBar();
} else {
m_failureView->connectProgressBar();
}
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ class ProjectRecoveryView;
class RecoveryFailureView;
class ProjectRecoveryPresenter {
public:
enum OpenView { RecoveryView, FailureView};
// Interestingly this nullptr should never be used
ProjectRecoveryPresenter(MantidQt::ProjectRecovery *projectRecovery,
ApplicationWindow *parentWindow);
......@@ -36,6 +37,7 @@ public:
boost::shared_ptr<QDialog> view);
void openSelectedInEditor(QString &selected);
void closeView();
void connectProgressBarToRecoveryView();
ProjectRecoveryPresenter &operator=(const ProjectRecoveryPresenter &obj);
private:
......@@ -43,6 +45,7 @@ private:
boost::shared_ptr<QDialog> view);
friend class ProjectRecoveryView;
friend class RecoveryFailureView;
OpenView m_openView;
ProjectRecoveryModel *m_model;
ProjectRecoveryView *m_recView;
RecoveryFailureView *m_failureView;
......
......@@ -5,23 +5,19 @@
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#include "ProjectRecoveryView.h"
#include "MantidKernel/UsageService.h"
#include "ApplicationWindow.h"
#include "ScriptingWindow.h"
#include "ScriptFileInterpreter.h"
#include "MantidKernel/UsageService.h"
#include "MultiTabScriptInterpreter.h"
#include "Script.h"
#include "ScriptFileInterpreter.h"
#include "ScriptingWindow.h"
#include "ui_ProjectRecoveryWidget.h"
#include <boost/smart_ptr/make_shared.hpp>
ProjectRecoveryView::ProjectRecoveryView(QWidget *parent,
ProjectRecoveryPresenter *presenter)
: QDialog(parent), m_progressBarCounter(0) {
ui = new Ui::ProjectRecoveryWidget;
m_presenter = presenter;
connect(m_presenter->m_mainWindow->getScriptWindowHandle()
->getCurrentScriptInterpreter()->getRunner().data(),
SIGNAL(currentLineChanged(int, bool)), this,
SLOT(updateProgressBar(int, bool)));
: QDialog(parent), ui(new Ui::ProjectRecoveryWidget),
m_presenter(presenter) {
ui->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
......@@ -76,4 +72,11 @@ void ProjectRecoveryView::updateProgressBar(int newValue, bool err) {
void ProjectRecoveryView::setProgressBarMaximum(int newValue) {
ui->progressBar->setMaximum(newValue);
}
void ProjectRecoveryView::connectProgressBar() {
connect(&m_presenter->m_mainWindow->getScriptWindowHandle()
->getCurrentScriptRunner(),
SIGNAL(currentLineChanged(int, bool)), this,
SLOT(updateProgressBar(int, bool)));
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ public:
~ProjectRecoveryView();
void reject() override;
void setProgressBarMaximum(int newValue);
void connectProgressBar();
public slots:
void updateProgressBar(int newValue, bool err);
......@@ -35,7 +36,7 @@ private slots:
private:
void addDataToTable(Ui::ProjectRecoveryWidget *ui);
unsigned int m_progressBarCounter;
Ui::ProjectRecoveryWidget *ui;
ProjectRecoveryPresenter *m_presenter;
};
......
......@@ -7,13 +7,14 @@
#include "RecoveryFailureView.h"
#include "ui_RecoveryFailure.h"
#include "ApplicationWindow.h"
#include "ScriptingWindow.h"
#include "Script.h"
#include "MantidKernel/UsageService.h"
#include <boost/smart_ptr/make_shared.hpp>
RecoveryFailureView::RecoveryFailureView(QWidget *parent,
ProjectRecoveryPresenter *presenter)
: QDialog(parent), ui(new Ui::RecoveryFailure), m_presenter(presenter),
m_progressBarCounter(0) {
: QDialog(parent), ui(new Ui::RecoveryFailure), m_presenter(presenter){
ui->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
......@@ -100,10 +101,19 @@ void RecoveryFailureView::reject() {
"Feature", "ProjectRecoveryFailureWindow->StartMantidNormally", false);
}
void RecoveryFailureView::updateProgressBar(int newValue) {
ui->progressBar->setValue(newValue);
void RecoveryFailureView::updateProgressBar(int newValue, bool err) {
if (!err) {
ui->progressBar->setValue(newValue);
}
}
void RecoveryFailureView::setProgressBarMaximum(int newValue) {
ui->progressBar->setMaximum(newValue);
}
void RecoveryFailureView::connectProgressBar() {
connect(&m_presenter->m_mainWindow->getScriptWindowHandle()
->getCurrentScriptRunner(),
SIGNAL(currentLineChanged(int, bool)), this,
SLOT(updateProgressBar(int, bool)));
}
\ No newline at end of file
......@@ -23,8 +23,11 @@ public:
ProjectRecoveryPresenter *presenter = nullptr);
~RecoveryFailureView();
void reject() override;
void updateProgressBar(int newValue);
void setProgressBarMaximum(int newValue);
void connectProgressBar();
public slots:
void updateProgressBar(int newValue, bool err);
private slots:
void onClickLastCheckpoint();
......@@ -35,7 +38,6 @@ private slots:
private:
void addDataToTable(Ui::RecoveryFailure *ui);
unsigned int m_progressBarCounter;
Ui::RecoveryFailure *ui;
ProjectRecoveryPresenter *m_presenter;
};
......
......@@ -57,7 +57,7 @@ public:
/// Is the script running
virtual bool isExecuting() const;
QSharedPointer<Script> getRunner() { return m_runner; }
const Script &getRunner() const{ return *m_runner.data(); }
public slots:
/// Save to the currently stored name
......
......@@ -906,6 +906,6 @@ Script::ExecutionMode ScriptingWindow::getExecutionMode() const {
return Script::Serialised;
}
ScriptFileInterpreter *ScriptingWindow::getCurrentScriptInterpreter() {
return m_manager->m_current;
const Script& ScriptingWindow::getCurrentScriptRunner() {
return m_manager->currentInterpreter()->getRunner();
}
\ No newline at end of file
......@@ -77,7 +77,7 @@ public:
// We set a flag on failure to avoid problems with Async not returning success
bool getSynchronousErrorFlag() { return m_failureFlag; }
ScriptFileInterpreter *getCurrentScriptInterpreter();
const Script &getCurrentScriptRunner();
signals:
/// Show the scripting language dialog
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment