Load cutter_jupyter.py from Qt resources

This commit is contained in:
Florian Märkl 2018-02-11 13:26:23 +01:00 committed by xarkes
parent a5e77c5095
commit 0a9fba0677
3 changed files with 18 additions and 10 deletions

View File

@ -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):

View File

@ -60,5 +60,7 @@
<file>img/cutter_plain.svg</file>
<file>img/cutter_white_plain.svg</file>
<file>img/cutter.svg</file>
<file>python/cutter_jupyter.py</file>
</qresource>
</RCC>

View File

@ -6,6 +6,7 @@
#include <QJsonObject>
#include <QDebug>
#include <QThread>
#include <QFile>
#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");