Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jupyter_renderjs_extension
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jupyter_renderjs_extension
Commits
fe74b7a1
Commit
fe74b7a1
authored
Mar 07, 2017
by
Sebastian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renderjs-extension: update ipy-extension to match ERP5Kernel version
parent
8827f2ce
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
89 deletions
+65
-89
renderjs_ipyextension/README.md
renderjs_ipyextension/README.md
+1
-1
renderjs_ipyextension/renderjs_ipyextension/renderjs_extension.py
..._ipyextension/renderjs_ipyextension/renderjs_extension.py
+63
-85
renderjs_nbextension/README.md
renderjs_nbextension/README.md
+1
-3
No files found.
renderjs_ipyextension/README.md
View file @
fe74b7a1
# TODO
\ No newline at end of file
See top-level README.md
\ No newline at end of file
renderjs_ipyextension/renderjs_ipyextension/renderjs_extension.py
View file @
fe74b7a1
#
# TODO
#
# prevent multiple class of init_renderjs - ie. check if loading_gadget there
# find proper location for static files
#
*
prevent multiple class of init_renderjs - ie. check if loading_gadget there
#
*
find proper location for static files
#
#
# For each gadget which is to be integrated into the jupyter page one
# RJSGadget object is created. It is used to call call_declared_method
# and destroy.
class
RJSGadget
:
def
__init__
(
self
,
gadgetId
):
# The UID is used to identify the gadget and gets passed along
# to the events sent to the frontend so that the loading_gadget
# is able to decide to which gadget the fired event belongs
# Python call on object with (uid) ->
# -> Fire event (uid) ->
# -> loading_gadget (uid) ->
# -> pass on the call to gadget with (uid)
self
.
gadgetId
=
gadgetId
def
__del__
(
self
):
pass
# Fires an event with
# * the uid of the gadget
# * the name of the declared_method
# * the arguments to be passed to the declared_method
# The arguments are packed into a json string and passed to js as such
def
call_declared_method
(
self
,
method_name
,
*
args
):
from
IPython.core.display
import
display
,
HTML
import
json
j_str
=
json
.
dumps
(
args
)
script
=
'''
<script>
var call_event = new CustomEvent("call_gadget",
{ "detail": {
"gadgetId": "'''
+
self
.
gadgetId
+
'''",
"methodName": "'''
+
method_name
+
'''",
"methodArgs": '''
+
"'"
+
j_str
+
"'"
+
'''
}});
var loadingDiv = document.querySelector(".loading_gadget");
if(loadingDiv != null) {
loadingDiv.dispatchEvent(call_event);
} else {
console.log("~~ call: RenderJS init required first!");
}
</script>
'''
display
(
HTML
(
script
))
# Fires an event to the destroy this gadget (self)
# Only thing passed is the uid of the gadget
def
destroy
(
self
):
from
IPython.core.display
import
display
,
HTML
script
=
'''
<script>
var destroy_event = new CustomEvent("destroy_gadget",
{ "detail": { "gadgetId": "'''
+
self
.
gadgetId
+
'''" }});
var loadingDiv = document.querySelector(".loading_gadget");
if(loadingDiv != null) {
loadingDiv.dispatchEvent(destroy_event);
} else {
console.log("~~ destroy: RenderJS init required first!");
}
</script>
'''
display
(
HTML
(
script
))
# Do nothing on load
def
load_ipython_extension
(
ipython
):
pass
# Do nothing on unload
def
unload_ipython_extension
(
ipython
):
pass
# Create the original load_gadget with modified rsvp, renderjs
# Because jupyter notebook has already loaded when this can be called
# a manual intialization of the whole renderJS setup is required
# a manual in
i
tialization of the whole renderJS setup is required
#
# First the libs rsvp, renderjs-gadget-global and renderjs (patched)
# are injected into the page. The patch on renderjs itself is to enable
...
...
@@ -96,7 +21,7 @@ def unload_ipython_extension(ipython):
# After everything is inplace, rJS.manualBootstrap initializes the
# loading_gadget in exactly the same way as when rJS is normally initialized
# (on-load)
def
init
_r
enderjs
():
def
init
R
enderjs
():
from
IPython.core.display
import
display
,
HTML
script
=
'''
<script>
...
...
@@ -123,17 +48,13 @@ def init_renderjs():
# Load a gadget given a URL to the HTML file of the gadget
# -> Generates a new uid for the gadget to-be-loaded
# -> Fires an event which loading_gadget listens on and passes on the URL
# -> returns the python gadget-object which has the uid as member-variable
def
load_gadget
(
gadgetUrl
):
def
loadGadget
(
ref
,
gadgetUrl
):
from
IPython.core.display
import
display
,
HTML
import
uuid
gadgetId
=
str
(
uuid
.
uuid4
())
script
=
'''
<script>
var load_event = new CustomEvent("load_gadget",
{ "detail": { "url": "'''
+
gadgetUrl
+
'", "gadgetId": "'
+
gadgetId
+
'''" }});
{ "detail": { "url": "'''
+
gadgetUrl
+
'", "gadgetId": "'
+
ref
+
'''" }});
var loadingDiv = document.querySelector(".loading_gadget");
if(loadingDiv != null) {
...
...
@@ -145,3 +66,60 @@ def load_gadget(gadgetUrl):
'''
display
(
HTML
(
script
))
return
RJSGadget
(
gadgetId
)
# Fires an event with
# * the ref of the gadget
# * the name of the declared_method
# * the arguments to be passed to the declared_method
# The arguments are packed into a json string and passed to js as such
def
call_declared_method
(
ref
,
method_name
,
*
args
):
from
IPython.core.display
import
display
,
HTML
import
json
j_str
=
json
.
dumps
(
args
)
script
=
'''
<script>
var call_event = new CustomEvent("call_gadget",
{ "detail": { "gadgetId": "'''
+
ref
+
'''",
"methodName": "'''
+
method_name
+
'''",
"methodArgs": '''
+
"'"
+
j_str
+
"'"
+
'''
}});
var loadingDiv = document.querySelector(".loading_gadget");
if(loadingDiv != null) {
loadingDiv.dispatchEvent(call_event);
} else {
console.log("~~ call: RenderJS init required first!");
}
</script>
'''
display
(
HTML
(
script
))
# Fires an event to the destroy this gadget
# Only thing passed is the ref of the gadget
def
destroy
(
ref
):
from
IPython.core.display
import
display
,
HTML
script
=
'''<script>
var destroy_event = new CustomEvent("destroy_gadget",
{ "detail": { "gadgetId": "'''
+
ref
+
'''" }});
var loadingDiv = document.querySelector(".loading_gadget");
if(loadingDiv != null) {
loadingDiv.dispatchEvent(destroy_event);
} else {
console.log("~~ destroy: RenderJS init required first!");
}
</script>
'''
display
(
HTML
(
script
))
# Do nothing on load
def
load_ipython_extension
(
ipython
):
pass
# Do nothing on unload
def
unload_ipython_extension
(
ipython
):
pass
renderjs_nbextension/README.md
View file @
fe74b7a1
# Frontend part of the jupyter extension for RenderJS
TODO
\ No newline at end of file
See top-level README.md
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment