diff --git a/MantidPlot/src/MultiTabScriptInterpreter.h b/MantidPlot/src/MultiTabScriptInterpreter.h index 00b51ad78da2b45a3a76b7e53298f26af27ed7cd..c57a57742e348c140601b85e8cea02c45b8a753d 100644 --- a/MantidPlot/src/MultiTabScriptInterpreter.h +++ b/MantidPlot/src/MultiTabScriptInterpreter.h @@ -50,7 +50,7 @@ public: ~MultiTabScriptInterpreter() override; /// Current interpreter - ScriptFileInterpreter *currentInterpreter(); + ScriptFileInterpreter *currentInterpreter() { return m_current; }; /// Interpreter at given index ScriptFileInterpreter *interpreterAt(int index); diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp index da34c5e58ad543e9d0769bc35861c619b03a8f38..49f1b316cda47b1a361bfd28839f17a51cbcb686 100644 --- a/MantidPlot/src/ProjectRecovery.cpp +++ b/MantidPlot/src/ProjectRecovery.cpp @@ -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()) { diff --git a/MantidPlot/src/ProjectRecovery.h b/MantidPlot/src/ProjectRecovery.h index 51760782b3dba8b77a5484a99e601449a484c191..a1e52db40b2161b89e73201e3aa9e11103be11ae 100644 --- a/MantidPlot/src/ProjectRecovery.h +++ b/MantidPlot/src/ProjectRecovery.h @@ -91,6 +91,7 @@ public: void removeLockedCheckpoints(); private: + friend class RecoveryThread; /// Captures the current object in the background thread std::thread createBackgroundThread(); diff --git a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryModel.cpp b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryModel.cpp index 5d247376b35190f9253d7f89117a78adf3e41d65..509d8f8e368505321945b781b3fc42e49fdae531 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryModel.cpp +++ b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryModel.cpp @@ -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 diff --git a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.cpp b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.cpp index 0c0e1935159c84bd4594ac25c1483bd516afbbed..fa9c24ec77b1b0587c245c4b59f9014f605ff45e 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.cpp +++ b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.cpp @@ -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 diff --git a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.h b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.h index 39152fec74c441a7a08a6da2028cc2608611e649..b7f3091bac77dbcf8e7ba2877a29a85f777c4edc 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.h +++ b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryPresenter.h @@ -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; diff --git a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.cpp b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.cpp index b03b2a6cfadc10558e112905523ebec248f2aeec..775e67eabd9326b804becfc735d4b72b6fb3243e 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.cpp +++ b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.cpp @@ -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 diff --git a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.h b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.h index 778e684460ca9c497efcdefb3a8a83901ae9e1ba..8ea03a379ca82a63c88f65b7847472f563b16767 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.h +++ b/MantidPlot/src/ProjectRecoveryGUIs/ProjectRecoveryView.h @@ -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; }; diff --git a/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.cpp b/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.cpp index 94734988f5d398aeab167fba8bc6658ba560f580..dc10d4fadf9da51c957a06aa0077e8ee58293181 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.cpp +++ b/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.cpp @@ -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 diff --git a/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.h b/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.h index efe59f01d505ecff8a127b7100d304c1e86b37f3..4364d602a29b6c5942033d39b527c446e9a647a6 100644 --- a/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.h +++ b/MantidPlot/src/ProjectRecoveryGUIs/RecoveryFailureView.h @@ -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; }; diff --git a/MantidPlot/src/ScriptFileInterpreter.h b/MantidPlot/src/ScriptFileInterpreter.h index 03a5ad6a138b35d5724e1b84862e26311a7b670c..60a97f5667fcefb04bea8e900c0df98a3b714913 100644 --- a/MantidPlot/src/ScriptFileInterpreter.h +++ b/MantidPlot/src/ScriptFileInterpreter.h @@ -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 diff --git a/MantidPlot/src/ScriptingWindow.cpp b/MantidPlot/src/ScriptingWindow.cpp index 7cfd0e0d5b76f2174b0d57f49e9144030fa2583d..10440154497b361764fdf1008ec759e18669250f 100644 --- a/MantidPlot/src/ScriptingWindow.cpp +++ b/MantidPlot/src/ScriptingWindow.cpp @@ -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 diff --git a/MantidPlot/src/ScriptingWindow.h b/MantidPlot/src/ScriptingWindow.h index fd5cb2f9945577f8c9bded2950a1c24f5edd2c52..16314cbbf770843645d6ff75833458db5e116b08 100644 --- a/MantidPlot/src/ScriptingWindow.h +++ b/MantidPlot/src/ScriptingWindow.h @@ -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