From d23cc71b7968855d500e3b7bfe79b24baa3ae582 Mon Sep 17 00:00:00 2001 From: xarkes Date: Thu, 22 Feb 2018 19:39:20 +0100 Subject: [PATCH] Added an error tab when Jupyter fails --- src/utils/JupyterConnection.cpp | 2 ++ src/utils/JupyterConnection.h | 1 + src/utils/PythonAPI.cpp | 1 - src/widgets/JupyterWidget.cpp | 17 +++++++++++++++-- src/widgets/JupyterWidget.h | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/utils/JupyterConnection.cpp b/src/utils/JupyterConnection.cpp index 7785c0cc..f558d668 100644 --- a/src/utils/JupyterConnection.cpp +++ b/src/utils/JupyterConnection.cpp @@ -45,6 +45,7 @@ void JupyterConnection::start() if (!moduleCodeObject) { qWarning() << "Could not compile cutter_jupyter."; + emit creationFailed(); return; } cutterJupyterModule = PyImport_ExecCodeModule("cutter_jupyter", moduleCodeObject); @@ -52,6 +53,7 @@ void JupyterConnection::start() if (!cutterJupyterModule) { qWarning() << "Could not import cutter_jupyter."; + emit creationFailed(); return; } diff --git a/src/utils/JupyterConnection.h b/src/utils/JupyterConnection.h index 7df523a0..64d20f7d 100644 --- a/src/utils/JupyterConnection.h +++ b/src/utils/JupyterConnection.h @@ -21,6 +21,7 @@ public: signals: void urlReceived(const QString &url); + void creationFailed(); private: PyObject *cutterJupyterModule = nullptr; diff --git a/src/utils/PythonAPI.cpp b/src/utils/PythonAPI.cpp index 576b2914..2a09df45 100644 --- a/src/utils/PythonAPI.cpp +++ b/src/utils/PythonAPI.cpp @@ -4,7 +4,6 @@ #include -/* Return the number of arguments of the application command line */ PyObject *api_version(PyObject *self, PyObject *null) { Q_UNUSED(self) diff --git a/src/widgets/JupyterWidget.cpp b/src/widgets/JupyterWidget.cpp index c23defb4..71273cf3 100644 --- a/src/widgets/JupyterWidget.cpp +++ b/src/widgets/JupyterWidget.cpp @@ -4,6 +4,9 @@ #include "JupyterWidget.h" #include +#include +#include +#include JupyterWidget::JupyterWidget(QWidget *parent, Qt::WindowFlags flags) : QDockWidget(parent, flags), @@ -13,6 +16,7 @@ JupyterWidget::JupyterWidget(QWidget *parent, Qt::WindowFlags flags) : jupyter = new JupyterConnection(this); connect(jupyter, &JupyterConnection::urlReceived, this, &JupyterWidget::urlReceived); + connect(jupyter, &JupyterConnection::creationFailed, this, &JupyterWidget::creationFailed); jupyter->start(); } @@ -27,13 +31,22 @@ JupyterWebView *JupyterWidget::createNewTab() return webView; } - void JupyterWidget::urlReceived(const QString &url) { createNewTab()->load(QUrl(url)); } - +void JupyterWidget::creationFailed() +{ + QWidget *failPage = new QWidget(this); + QLabel *label = new QLabel(failPage); + label->setText(tr("An error occurred while opening jupyter. Make sure Jupyter is installed system-wide.")); + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget(label); + layout->setAlignment(label, Qt::AlignCenter); + failPage->setLayout(layout); + ui->tabWidget->addTab(failPage, tr("Error")); +} JupyterWebView::JupyterWebView(JupyterWidget *mainWidget, QWidget *parent) : QWebEngineView(parent) { diff --git a/src/widgets/JupyterWidget.h b/src/widgets/JupyterWidget.h index 0b1bc931..63485d38 100644 --- a/src/widgets/JupyterWidget.h +++ b/src/widgets/JupyterWidget.h @@ -28,6 +28,7 @@ public: private slots: void urlReceived(const QString &url); + void creationFailed(); private: std::unique_ptr ui;