Added an error tab when Jupyter fails

This commit is contained in:
xarkes 2018-02-22 19:39:20 +01:00 committed by xarkes
parent b9b903052c
commit d23cc71b79
5 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -21,6 +21,7 @@ public:
signals:
void urlReceived(const QString &url);
void creationFailed();
private:
PyObject *cutterJupyterModule = nullptr;

View File

@ -4,7 +4,6 @@
#include <QFile>
/* Return the number of arguments of the application command line */
PyObject *api_version(PyObject *self, PyObject *null)
{
Q_UNUSED(self)

View File

@ -4,6 +4,9 @@
#include "JupyterWidget.h"
#include <QWebEngineSettings>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QLabel>
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)
{

View File

@ -28,6 +28,7 @@ public:
private slots:
void urlReceived(const QString &url);
void creationFailed();
private:
std::unique_ptr<Ui::JupyterWidget> ui;