-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathindex.ts
More file actions
86 lines (67 loc) · 1.99 KB
/
Copy pathindex.ts
File metadata and controls
86 lines (67 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
IDisposable, DisposableDelegate
} from '@lumino/disposable';
import {
JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
DocumentRegistry
} from '@jupyterlab/docregistry';
import {
NotebookPanel, INotebookModel
} from '@jupyterlab/notebook';
import { PageConfig } from '@jupyterlab/coreutils';
/**
* The plugin registration information.
*/
const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: 'vpython',
autoStart: true
};
/**
* A notebook extension to support VPython in Jupyterlab
*/
export
class VPythonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
/**
* Create a new extension object.
*/
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
Promise.all([panel.revealed, panel.sessionContext.ready, context.ready]).then(function() {
const session = context.sessionContext.session;
const kernelInstance = session.kernel;
(<any>window).JLab_VPython = true;
try {
kernelInstance.registerCommTarget('glow', (vp_comm: any, commMsg: any) => {
// Use Dynamic import() Expression to import glowcomm when comm is opened
import("./glowcommlab").then(glowcommlab => {
glowcommlab.comm = vp_comm
vp_comm.onMsg = glowcommlab.onmessage
// Get Websocket URL of current notebook server
let ws_url = PageConfig.getWsUrl()
// Construct URL of our proxied service
let serviceUrl = ws_url + 'proxy/';
glowcommlab.setupWebsocket(commMsg, serviceUrl)
});
vp_comm.onClose = (msg: any) => {console.log("comm onClose");};
});
}
catch(err) {
console.log("register glow error : ",err.message);
}
});
return new DisposableDelegate(() => {
});
}
}
/**
* Activate the extension.
*/
function activate(app: JupyterFrontEnd) {
app.docRegistry.addWidgetExtension('Notebook', new VPythonExtension());
};
/**
* Export the plugin as default.
*/
export default plugin;