Skip to content

Commit d78f92b

Browse files
authored
Merge pull request #36 from jcoady/master
VPython labextension support on remote host.
2 parents 06bb235 + 8b26b26 commit d78f92b

File tree

8 files changed

+75
-40
lines changed

8 files changed

+75
-40
lines changed

labextension/vpython/README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,32 @@ jupyter labextension install vpython
1616

1717
## Development
1818

19-
For a development install (requires npm version 4 or later), do the following in the repository directory:
19+
For a development install use the instructions for creating a custom jupyter labextension as a guide:
20+
21+
https://jupyterlab.readthedocs.io/en/stable/developer/extension_tutorial.html#extension-tutorial
22+
23+
but taylor the instructions for creating a vpython labextension.
2024

2125
```bash
22-
npm install
23-
cp -r ../../vpython/vpython_{libraries,data} lib/
26+
jlpm install
27+
jlpm add @jupyterlab/application
28+
jlpm add @jupyterlab/apputils
29+
jlpm add @jupyterlab/coreutils
30+
jlpm add @jupyterlab/docregistry
31+
jlpm add @jupyterlab/notebook
32+
jlpm add @phosphor/disposable
33+
jlpm add script-loader
34+
35+
cp -r ../../vpython/vpython_{libraries,data} .
36+
jlpm run build
2437
jupyter labextension install .
2538
```
2639

2740
To rebuild the package and the JupyterLab app:
2841

2942
```bash
30-
npm run build
43+
jlpm run build
3144
jupyter lab build
3245
```
3346

47+

labextension/vpython/package.json

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vpython",
3-
"version": "0.4.3",
3+
"version": "0.4.6",
44
"description": "VPython extension for Jupyterlab",
55
"keywords": [
66
"jupyter",
@@ -14,17 +14,23 @@
1414
"license": "BSD-3-Clause",
1515
"author": "John Coady",
1616
"files": [
17-
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,otf}",
18-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
17+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,otf,ico}",
18+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf,otf,ico}",
19+
"vpython_data/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf,otf,ico}",
20+
"vpython_libraries/*"
1921
],
2022
"main": "lib/index.js",
2123
"typings": "lib/index.d.ts",
24+
"style": "style/index.css",
25+
"repository": {
26+
"type": "git",
27+
"url": ""
28+
},
2229
"scripts": {
23-
"build": "npm run build:src",
24-
"build:src": "tsc",
25-
"clean": "rimraf tsconfig.tsbuildinfo",
26-
"prepublish": "npm run clean && npm run build",
27-
"jpinstall": "jupyter labextension install ."
30+
"build": "tsc",
31+
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
32+
"prepare": "npm run clean && npm run build",
33+
"watch": "tsc -w"
2834
},
2935
"dependencies": {
3036
"@jupyterlab/application": "^1.1.3",
@@ -42,6 +48,9 @@
4248
"rimraf": "^2.6.1",
4349
"typescript": "^3.6.3"
4450
},
51+
"sideEffects": [
52+
"style/*.css"
53+
],
4554
"jupyterlab": {
4655
"extension": true
4756
}

labextension/vpython/src/glowcommlab.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,27 @@ import 'script-loader!./vpython_libraries/plotly.min.js';
55
import '../style/jquery-ui.custom.css'
66
import '../style/ide.css'
77

8-
// Ensure downstream JupyterLab webpack places the fonts in predictable locations
9-
import '!!file-loader?name=/vpython_data/[name].[ext]!./vpython_data/Roboto-Medium.ttf'
10-
import '!!file-loader?name=/vpython_data/[name].[ext]!./vpython_data/NimbusRomNo9L-Med.otf'
8+
// Ensure downstream JupyterLab webpack places the fonts and images in predictable locations
9+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/earth_texture.jpg'
10+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/favicon.ico'
11+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/flower_texture.jpg'
12+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/granite_texture.jpg'
13+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/gravel_bumpmap.jpg'
14+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/gravel_texture.jpg'
15+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/metal_texture.jpg'
16+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/NimbusRomNo9L-Med.otf'
17+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/Roboto-Medium.ttf'
18+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rock_bumpmap.jpg'
19+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rock_texture.jpg'
20+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rough_texture.jpg'
21+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rug_texture.jpg'
22+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stones_bumpmap.jpg'
23+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stones_texture.jpg'
24+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stucco_bumpmap.jpg'
25+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stucco_texture.jpg'
26+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_old_bumpmap.jpg'
27+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_old_texture.jpg'
28+
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_texture.jpg'
1129

1230
export var comm
1331
var ws = null
@@ -20,19 +38,13 @@ export function createWebsocket(msg, serviceUrl) {
2038
// create websocket instance
2139
var port = msg.content.data.wsport
2240
var uri = msg.content.data.wsuri
23-
var loc = document.location, new_uri, url;
24-
25-
if (loc.protocol === "https:") {
26-
new_uri = "wss:";
27-
} else {
28-
new_uri = "ws:";
29-
}
41+
var url;
42+
3043
if (document.location.hostname.includes("localhost")){
3144
url = "ws://localhost:" + port + uri;
3245
}
3346
else {
34-
new_uri += '//' + document.location.host + service_url + uri;
35-
url = new_uri
47+
url = serviceUrl + port + uri;
3648
}
3749
ws = new WebSocket(url);
3850
ws.binaryType = "arraybuffer";
@@ -57,25 +69,22 @@ export function createWebsocket(msg, serviceUrl) {
5769
}
5870
}
5971

60-
var wsmsg
61-
62-
function wscheckfontsloaded() {
72+
function wscheckfontsloaded(msg,serviceUrl) {
6373
"use strict";
6474
if (window.__font_sans === undefined || window.__font_serif === undefined) {
65-
setTimeout(wscheckfontsloaded,10)
75+
setTimeout(wscheckfontsloaded,10,msg,serviceUrl)
6676
} else {
67-
createWebsocket(wsmsg)
77+
createWebsocket(msg,serviceUrl)
6878
}
6979
}
7080

71-
export function setupWebsocket(msg) {
81+
export function setupWebsocket(msg,serviceUrl) {
7282
"use strict";
73-
wsmsg = msg
74-
wscheckfontsloaded()
83+
wscheckfontsloaded(msg,serviceUrl)
7584
}
7685

77-
var datadir = '/static/lab/vpython_data/'
78-
window.Jupyter_VPython = "/static/lab/vpython_data/" // prefix used by glow.min.js for textures
86+
var datadir = './static/lab/vpython_data/'
87+
window.Jupyter_VPython = "./static/lab/vpython_data/" // prefix used by glow.min.js for textures
7988

8089
function fontloading() {
8190
"use strict";

labextension/vpython/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class VPythonExtension implements DocumentRegistry.IWidgetExtension<NotebookPane
4747
glowcommlab.comm = vp_comm
4848
vp_comm.onMsg = glowcommlab.onmessage
4949

50-
// Get base URL of current notebook server
51-
let baseUrl = PageConfig.getBaseUrl()
50+
// Get Websocket URL of current notebook server
51+
let ws_url = PageConfig.getWsUrl()
5252

5353
// Construct URL of our proxied service
54-
let serviceUrl = base_url + 'proxy/' + port;
54+
let serviceUrl = ws_url + 'proxy/';
5555

5656
glowcommlab.setupWebsocket(commMsg, serviceUrl)
5757
});

labextension/vpython/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"lib": ["es6", "ES5", "ES2015.Promise", "DOM"],
55
"module": "commonjs",
66
"moduleResolution": "node",
7-
"noImplicitAny": true,
7+
"noImplicitAny": true,
88
"noEmitOnError": true,
99
"noUnusedLocals": true,
10-
"outDir": "./lib",
10+
"outDir": "lib",
11+
"rootDir": "src",
1112
"target": "es6",
1213
"strict": true,
1314
"strictNullChecks": false,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

vpython/with_notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def find_free_port():
5555
pass
5656
else:
5757
# We have jupyterlab, is it the right version?
58-
if jupyterlab.__version__ >= '0.35.0':
58+
if (jupyterlab.__version__ >= '0.35.0') and (jupyterlab.__version__ < '1.0.0'):
5959
from os.path import join
6060
labextensions_dir = join(jupyterlab.commands.get_app_dir(), u'static')
6161
try:

0 commit comments

Comments
 (0)