This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
[WIP] Changes necessary to work standalone similar to ipywidgets examples #157
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d227b4a
[ci skip] Changes necessary to work standalone similar to ipywidgets …
ef4a829
[ci skip]Moved the example under this project and added a Makefile
84ef0ab
[ci skip]First victory just using channels and urth-core-bind
b6fac88
[ci skip]Modified example to use urth-core-function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
index.built.js | ||
es5/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"esnext": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
.PHONY: help clean build run | ||
|
||
clean: clean-npm clean-build | ||
|
||
clean-npm: | ||
-@rm -r node_modules | ||
|
||
clean-build: | ||
-@rm -r es5 | ||
-@rm index.built.js | ||
|
||
build-ipywidgets: | ||
@echo 'Building ipywidgets' | ||
cd ../../../../ipywidgets/ipywidgets && npm install | ||
|
||
build-urth-widgets: | ||
@echo 'Building urth-widgets' | ||
cd ../../.. && make dist NOSCALA=true && npm install | ||
|
||
build: build-urth-widgets build-ipywidgets | ||
@echo 'Building example' | ||
npm install | ||
-cd node_modules/urth-widgets/dist/urth_widgets && ln -s bower_components/ urth_components | ||
|
||
run: | ||
python -m SimpleHTTPServer 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Using urth-widgets in non-notebook, web context | ||
## Description | ||
This directory is an example project that shows how you can embed the widgets in | ||
a context other than the notebook. | ||
|
||
## Try it | ||
This assumes that ipywidgets is cloned out at the same level as declarativewidgets | ||
In this directory: | ||
|
||
1. `make build` | ||
2. `make run` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<html> | ||
<head> | ||
<script src="index.built.js"></script> | ||
<meta http-equiv="content-type" content="text/html; charset=UTF8"> | ||
<link rel="stylesheet" type="text/css" href="./node_modules/font-awesome/css/font-awesome.css"> | ||
<style> | ||
body { | ||
margin-left: auto; | ||
margin-right: auto; | ||
max-width: 900px; | ||
background-color: #eee; | ||
} | ||
|
||
.jupyter-js-widgets-example { | ||
margin-top: 10px; | ||
margin-bottom: 10px; | ||
background-color: white; | ||
overflow: auto; | ||
box-shadow: 0px 0px 12px 1px rgba(87, 87, 87, 0.2); | ||
} | ||
|
||
.widgetarea, .inputarea { | ||
margin: 5px; | ||
} | ||
|
||
.CodeMirror { | ||
border: 1px solid #ccc; | ||
height: auto; | ||
background-color: #f7f7f7; | ||
border-radius: 2px; | ||
} | ||
|
||
.CodeMirror-Scroll { | ||
height: auto; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="jupyter-js-widgets-example"> | ||
<div class="inputarea"></div> | ||
<div class="widgetarea"></div> | ||
<template is='urth-core-bind' channel='a'> | ||
<template is='dom-if' if='{{kernelready}}'> | ||
<urth-core-function ref="hello" arg-name="{{name}}" result="{{msg}}" auto></urth-core-function> | ||
name: <input type="text" value="{{name::input}}"></input> | ||
</template> | ||
<H1>{{msg}}</H1> | ||
</template> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "urth-standalone-example", | ||
"version": "1.0.0", | ||
"description": "Example of urth-widgets running in a standalone web app using jupyter-js-services", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepublish": "npm run build", | ||
"build": "npm run build:es5 && npm run build:bundle", | ||
"build:es5": "babel src --out-dir es5 --presets es2015", | ||
"build:bundle": "browserify -g node-lessify ./es5/index.js --outfile ./index.built.js --debug", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "IPython", | ||
"license": "BSD-3-Clause", | ||
"dependencies": { | ||
"browserify": "^11.2.0", | ||
"codemirror": "^5.9.0", | ||
"font-awesome": "^4.5.0", | ||
"jupyter-js-widgets": "file:../../../../ipywidgets/ipywidgets", | ||
"urth-widgets": "file:../../../../declarativewidgets", | ||
"jquery": "^2.1.4", | ||
"jquery-ui": "^1.10.5", | ||
"jupyter-js-services": "^0.2.2", | ||
"node-lessify": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.3.15", | ||
"babel-preset-es2015": "^6.3.13", | ||
"bower": "^1.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var CodeMirror = require("codemirror"); | ||
require("../node_modules/codemirror/lib/codemirror.css"); | ||
require("../node_modules/codemirror/mode/python/python"); | ||
|
||
var WidgetManager = require("./manager").WidgetManager; | ||
|
||
var urth_widgets = require('urth-widgets'); | ||
|
||
|
||
|
||
var services = require('jupyter-js-services'); | ||
var getKernelSpecs = services.getKernelSpecs; | ||
var startNewKernel = services.startNewKernel; | ||
|
||
var BASEURL = prompt('Notebook BASEURL', 'http://192.168.99.100:8888'); | ||
|
||
var WSURL = 'ws:' + BASEURL.split(':').slice(1).join(':'); | ||
|
||
urth_widgets.init('./node_modules/urth-widgets/dist/urth_widgets/'); | ||
|
||
document.addEventListener("DOMContentLoaded", function(event) { | ||
|
||
// Connect to the notebook webserver. | ||
getKernelSpecs(BASEURL).then(kernelSpecs => { | ||
return startNewKernel({ | ||
baseUrl: BASEURL, | ||
wsUrl: WSURL, | ||
name: kernelSpecs.default, | ||
}); | ||
}).then(kernel => { | ||
|
||
// Create a codemirror instance | ||
var code = require("../widget_code.json").join("\n"); | ||
var inputarea = document.getElementsByClassName("inputarea")[0]; | ||
var editor = CodeMirror(inputarea, { | ||
value: code, | ||
mode: "python", | ||
tabSize: 4, | ||
showCursorWhenSelecting: true, | ||
viewportMargin: Infinity, | ||
readOnly: true | ||
}); | ||
|
||
// Create the widget area and widget manager | ||
var widgetarea = document.getElementsByClassName("widgetarea")[0]; | ||
var manager = new WidgetManager(kernel, widgetarea); | ||
|
||
//more shimming | ||
IPython.notebook.kernel = kernel; | ||
IPython.notebook.kernel.widget_manager = manager; | ||
IPython.notebook.events.trigger('kernel_ready.Kernel'); | ||
|
||
// Run backend code to create the widgets. You could also create the | ||
// widgets in the frontend, like the other /web/ examples demonstrate. | ||
var execPromise = kernel.execute({ code: code }); | ||
execPromise.onReply = function(){ | ||
IPython.notebook.events.trigger('shell_reply.Kernel'); | ||
} | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require('../node_modules/jupyter-js-widgets/static/components/bootstrap/css/bootstrap.css'); | ||
require('../node_modules/jquery-ui/themes/smoothness/jquery-ui.min.css'); | ||
|
||
const ipywidgets = require('jupyter-js-widgets'); | ||
|
||
export class WidgetManager extends ipywidgets.ManagerBase { | ||
constructor(kernel, el) { | ||
super(); | ||
this.kernel = kernel; | ||
this.el = el; | ||
|
||
// Create a comm manager shim | ||
this.commManager = new ipywidgets.shims.services.CommManager(kernel); | ||
|
||
// Register the comm target | ||
this.commManager.register_target(this.comm_target_name, this.handle_comm_open.bind(this)); | ||
} | ||
|
||
display_view(msg, view, options) { | ||
var that = this; | ||
return Promise.resolve(view).then(function(view) { | ||
that.el.appendChild(view.el); | ||
view.on('remove', function() { | ||
console.log('view removed', view); | ||
}); | ||
return view; | ||
}); | ||
} | ||
|
||
_create_comm(targetName, id, metadata) { | ||
return Promise.resolve( this.commManager.new_comm(targetName, metadata, id) ); | ||
} | ||
|
||
_get_comm_info() { | ||
return Promise.resolve({}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
"from urth.widgets.widget_channels import channel", | ||
"def hello(name):", | ||
" return 'Hello ' + name", | ||
"channel('a').set('kernelready', True)" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
// This is the main file that will be loaded when urth-widgets is required in an | ||
// npm environment. | ||
// | ||
//module.exports = function createDefine(targetModule) { | ||
// var amdefine = require('amdefine')(targetModule, require); | ||
// | ||
// return function define() { | ||
// var args = Array.prototype.slice.call(arguments); | ||
// //if (args.length > 1) { | ||
// // args[0] = args[0].map(function(arg) { | ||
// // if (arg === 'jqueryui') arg = 'jquery'; | ||
// // arg = arg.replace('nbextensions/widgets/widgets/css/', '../css/'); | ||
// // arg = arg.replace('nbextensions/widgets/components/require-css/css!', ''); | ||
// // return arg; | ||
// // }); | ||
// //} | ||
// amdefine.apply(this, args); | ||
// }; | ||
//}; | ||
|
||
global.jQuery = global.$ = require('jquery'); | ||
var init = require('./dist/urth_widgets/js/init/init'); | ||
|
||
exports.init = init; | ||
|
||
var Events = function () {}; | ||
|
||
var events = new Events(); | ||
|
||
|
||
//shim in IPython | ||
IPython = { | ||
notebook: { | ||
events: $([events]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
que?