Mantid
Loading...
Searching...
No Matches
MantidDialog.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------
8// Includes
9//----------------------------------
11
12#include <QMessageBox>
13
14using namespace MantidQt::API;
15
16//------------------------------------------------------
17// Public member functions
18//------------------------------------------------------
22MantidDialog::MantidDialog(QWidget *parent, const Qt::WindowFlags &flags) : QDialog(parent, flags), m_pyRunner() {
23 // re-emit the run Python code from m_pyRunner, to work this signal must reach
24 // the slot in QtiPlot
25 connect(&m_pyRunner, SIGNAL(runAsPythonScript(const QString &, bool)), this,
26 SIGNAL(runAsPythonScript(const QString &, bool)));
27}
28
33
41bool MantidDialog::handle(QObject *receiver, const std::exception &e) {
42 QObject *obj = receiver;
43 while (obj) {
44 if (obj->inherits("MantidQt::API::MantidDialog")) {
45 qobject_cast<MantidDialog *>(obj)->handleException(e);
46 return true;
47 }
48 obj = obj->parent();
49 };
50 return false;
51}
52
56void MantidDialog::handleException(const std::exception &e) {
57 QMessageBox::critical(qobject_cast<QWidget *>(parent()), "Mantid - Error",
58 "Exception is caught in dialog:\n\n" + QString::fromStdString(e.what()));
59 close();
60}
61
68QString MantidDialog::runPythonCode(const QString &code, bool no_output) {
69 return m_pyRunner.runPythonCode(code, no_output);
70}
double obj
the value of the quadratic function
PythonRunner m_pyRunner
This object implements the runPythonCode() function, by emitting the code as a runAsPythonScript sign...
Definition: MantidDialog.h:82
MantidDialog(QWidget *parent=nullptr, const Qt::WindowFlags &flags=Qt::WindowCloseButtonHint|Qt::WindowType::WindowTitleHint)
DefaultConstructor.
void runAsPythonScript(const QString &code, bool)
~MantidDialog() override
Destructor.
static bool handle(QObject *receiver, const std::exception &e)
Handles the exception caught in an event handler.
virtual void handleException(const std::exception &e)
Override this method to handle an exception in a derived class.
QString runPythonCode(const QString &code, bool no_output=false)
Run python code that is passed to it and, optionally, return anything it wrote to standard output as ...
QString runPythonCode(const QString &code, bool no_output=false)
Run python code.