Permalink
Browse files

fix issue in magic command %snap

  • Loading branch information...
sdpython committed Jul 19, 2015
1 parent ebffea4 commit 86d9244874fb86e91d4d0a66ace38fb22ed7d010
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/code_beatrix/ipython_helper/magic_scratch.py
@@ -5,6 +5,7 @@
"""
import os
import glob
import random
from IPython.core.magic import magics_class, line_magic
from IPython.core.display import HTML, display_html, Javascript
@@ -26,7 +27,7 @@ def snap_parser():
"""
defines the way to parse the magic command ``%snap``
"""
parser = MagicCommandParser(
parser = MagicCommandParser(prog="snap",
description='insert a snap window inside a notebook')
parser.add_argument(
'-f',
@@ -52,13 +53,18 @@ def snap(self, line):
args = self.get_args(line, parser)
if args is not None:
if args.f in [None, ""]:
if args.file in [None, ""]:
#filename = None
pass
else:
raise NotImplementedError()
iddiv = args.div
if iddiv == "scratch-div-id":
# we should use a static counter but it
# is very unlikely more than one snap will be added to
# a notebook
iddiv += "-%d" % random.randint(0,100000)
js_path = os.path.dirname(location_js_snap)
files = [os.path.split(_)[-1]
@@ -72,15 +78,15 @@ def snap(self, line):
test_js = """
var world;
window.onload = function () {
world = new WorldMorph(document.getElementById('{0}'));
world = new WorldMorph(document.getElementById('__DIV__'));
world.worldCanvas.focus();
new IDE_Morph().openIn(world);
setInterval(loop, 1);
};
function loop() {
world.doOneCycle();
}
""".format(iddiv)
""".replace("__DIV__", iddiv)
display_html(HTML(data=html_src))
return Javascript(data=test_js, lib=js_libs)

0 comments on commit 86d9244

Please sign in to comment.