diff --git a/src/python/cutter_jupyter.py b/src/python/cutter_jupyter.py index 535f9798..56c19e7e 100644 --- a/src/python/cutter_jupyter.py +++ b/src/python/cutter_jupyter.py @@ -16,15 +16,7 @@ class CutterNotebookApp(NotebookApp): self.write_server_info_file() - class NotebookThread(threading.Thread): - def __init__(self, notebook_app): - super().__init__() - self.notebook_app = notebook_app - - def run(self): - self.notebook_app.run() - - self.thread = NotebookThread(self) + self.thread = threading.Thread(target=self.run) self.thread.start() def run(self): diff --git a/src/resources.qrc b/src/resources.qrc index 3b99ac5d..5532f223 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -60,5 +60,7 @@ img/cutter_plain.svg img/cutter_white_plain.svg img/cutter.svg + + python/cutter_jupyter.py diff --git a/src/utils/JupyterConnection.cpp b/src/utils/JupyterConnection.cpp index 2590f5ec..c1c0f962 100644 --- a/src/utils/JupyterConnection.cpp +++ b/src/utils/JupyterConnection.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "JupyterConnection.h" @@ -32,12 +33,25 @@ void JupyterConnection::start() Py_Initialize(); PyEval_InitThreads(); - cutterJupyterModule = PyImport_ImportModule("cutter_jupyter"); + QFile moduleFile(":/python/cutter_jupyter.py"); + moduleFile.open(QIODevice::ReadOnly); + QByteArray moduleCode = moduleFile.readAll(); + moduleFile.close(); + + auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_jupyter.py", Py_file_input); + if (!moduleCodeObject) + { + qWarning() << "Could not compile cutter_jupyter."; + return; + } + cutterJupyterModule = PyImport_ExecCodeModule("cutter_jupyter", moduleCodeObject); + Py_DECREF(moduleCodeObject); if (!cutterJupyterModule) { qWarning() << "Could not import cutter_jupyter."; return; } + auto startFunc = PyObject_GetAttrString(cutterJupyterModule, "start_jupyter"); cutterNotebookAppInstance = PyObject_CallObject(startFunc, nullptr); auto urlWithToken = PyObject_GetAttrString(cutterNotebookAppInstance, "url_with_token");