Skip to content

Commit

Permalink
Merge pull request #36 from jcoady/master
Browse files Browse the repository at this point in the history
VPython labextension support on remote host.
  • Loading branch information
jcoady committed Oct 25, 2019
2 parents 06bb235 + 8b26b26 commit d78f92b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 40 deletions.
22 changes: 18 additions & 4 deletions labextension/vpython/README.md
Expand Up @@ -16,18 +16,32 @@ jupyter labextension install vpython

## Development

For a development install (requires npm version 4 or later), do the following in the repository directory:
For a development install use the instructions for creating a custom jupyter labextension as a guide:

https://jupyterlab.readthedocs.io/en/stable/developer/extension_tutorial.html#extension-tutorial

but taylor the instructions for creating a vpython labextension.

```bash
npm install
cp -r ../../vpython/vpython_{libraries,data} lib/
jlpm install
jlpm add @jupyterlab/application
jlpm add @jupyterlab/apputils
jlpm add @jupyterlab/coreutils
jlpm add @jupyterlab/docregistry
jlpm add @jupyterlab/notebook
jlpm add @phosphor/disposable
jlpm add script-loader

cp -r ../../vpython/vpython_{libraries,data} .
jlpm run build
jupyter labextension install .
```

To rebuild the package and the JupyterLab app:

```bash
npm run build
jlpm run build
jupyter lab build
```


25 changes: 17 additions & 8 deletions labextension/vpython/package.json
@@ -1,6 +1,6 @@
{
"name": "vpython",
"version": "0.4.3",
"version": "0.4.6",
"description": "VPython extension for Jupyterlab",
"keywords": [
"jupyter",
Expand All @@ -14,17 +14,23 @@
"license": "BSD-3-Clause",
"author": "John Coady",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,otf}",
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,otf,ico}",
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf,otf,ico}",
"vpython_data/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf,otf,ico}",
"vpython_libraries/*"
],
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"style": "style/index.css",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "npm run build:src",
"build:src": "tsc",
"clean": "rimraf tsconfig.tsbuildinfo",
"prepublish": "npm run clean && npm run build",
"jpinstall": "jupyter labextension install ."
"build": "tsc",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"prepare": "npm run clean && npm run build",
"watch": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^1.1.3",
Expand All @@ -42,6 +48,9 @@
"rimraf": "^2.6.1",
"typescript": "^3.6.3"
},
"sideEffects": [
"style/*.css"
],
"jupyterlab": {
"extension": true
}
Expand Down
53 changes: 31 additions & 22 deletions labextension/vpython/src/glowcommlab.js
Expand Up @@ -5,9 +5,27 @@ import 'script-loader!./vpython_libraries/plotly.min.js';
import '../style/jquery-ui.custom.css'
import '../style/ide.css'

// Ensure downstream JupyterLab webpack places the fonts in predictable locations
import '!!file-loader?name=/vpython_data/[name].[ext]!./vpython_data/Roboto-Medium.ttf'
import '!!file-loader?name=/vpython_data/[name].[ext]!./vpython_data/NimbusRomNo9L-Med.otf'
// Ensure downstream JupyterLab webpack places the fonts and images in predictable locations
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/earth_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/favicon.ico'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/flower_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/granite_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/gravel_bumpmap.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/gravel_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/metal_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/NimbusRomNo9L-Med.otf'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/Roboto-Medium.ttf'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rock_bumpmap.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rock_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rough_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/rug_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stones_bumpmap.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stones_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stucco_bumpmap.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/stucco_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_old_bumpmap.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_old_texture.jpg'
import '!!file-loader?name=/vpython_data/[name].[ext]!../vpython_data/wood_texture.jpg'

export var comm
var ws = null
Expand All @@ -20,19 +38,13 @@ export function createWebsocket(msg, serviceUrl) {
// create websocket instance
var port = msg.content.data.wsport
var uri = msg.content.data.wsuri
var loc = document.location, new_uri, url;

if (loc.protocol === "https:") {
new_uri = "wss:";
} else {
new_uri = "ws:";
}
var url;

if (document.location.hostname.includes("localhost")){
url = "ws://localhost:" + port + uri;
}
else {
new_uri += '//' + document.location.host + service_url + uri;
url = new_uri
url = serviceUrl + port + uri;
}
ws = new WebSocket(url);
ws.binaryType = "arraybuffer";
Expand All @@ -57,25 +69,22 @@ export function createWebsocket(msg, serviceUrl) {
}
}

var wsmsg

function wscheckfontsloaded() {
function wscheckfontsloaded(msg,serviceUrl) {
"use strict";
if (window.__font_sans === undefined || window.__font_serif === undefined) {
setTimeout(wscheckfontsloaded,10)
setTimeout(wscheckfontsloaded,10,msg,serviceUrl)
} else {
createWebsocket(wsmsg)
createWebsocket(msg,serviceUrl)
}
}

export function setupWebsocket(msg) {
export function setupWebsocket(msg,serviceUrl) {
"use strict";
wsmsg = msg
wscheckfontsloaded()
wscheckfontsloaded(msg,serviceUrl)
}

var datadir = '/static/lab/vpython_data/'
window.Jupyter_VPython = "/static/lab/vpython_data/" // prefix used by glow.min.js for textures
var datadir = './static/lab/vpython_data/'
window.Jupyter_VPython = "./static/lab/vpython_data/" // prefix used by glow.min.js for textures

function fontloading() {
"use strict";
Expand Down
6 changes: 3 additions & 3 deletions labextension/vpython/src/index.ts
Expand Up @@ -47,11 +47,11 @@ class VPythonExtension implements DocumentRegistry.IWidgetExtension<NotebookPane
glowcommlab.comm = vp_comm
vp_comm.onMsg = glowcommlab.onmessage

// Get base URL of current notebook server
let baseUrl = PageConfig.getBaseUrl()
// Get Websocket URL of current notebook server
let ws_url = PageConfig.getWsUrl()

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

glowcommlab.setupWebsocket(commMsg, serviceUrl)
});
Expand Down
5 changes: 3 additions & 2 deletions labextension/vpython/tsconfig.json
Expand Up @@ -4,10 +4,11 @@
"lib": ["es6", "ES5", "ES2015.Promise", "DOM"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitAny": true,
"noEmitOnError": true,
"noUnusedLocals": true,
"outDir": "./lib",
"outDir": "lib",
"rootDir": "src",
"target": "es6",
"strict": true,
"strictNullChecks": false,
Expand Down
1 change: 1 addition & 0 deletions labextension/vpython/vpython_data/.gitkeep
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions labextension/vpython/vpython_libraries/.gitkeep
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion vpython/with_notebook.py
Expand Up @@ -55,7 +55,7 @@ def find_free_port():
pass
else:
# We have jupyterlab, is it the right version?
if jupyterlab.__version__ >= '0.35.0':
if (jupyterlab.__version__ >= '0.35.0') and (jupyterlab.__version__ < '1.0.0'):
from os.path import join
labextensions_dir = join(jupyterlab.commands.get_app_dir(), u'static')
try:
Expand Down

0 comments on commit d78f92b

Please sign in to comment.