My goal is to write an interactive variable viewer for IPython, i.e. which allows one to see, say nested dicts/lists as a tree, and drill down (a bit like the console.log in Javascript).
I spent a lot of time trying to extract minimalistic code out of the directview example in IPython but still can't get my head around how it all works. My Python's ok but my jQuery experience is quite limited.
So I got to stripping down directview.js to the following
container.show();
var widget = $('<div/>')
element.append(widget);
var output = $('<div></div>');
$(widget).append(output)
var output_area = new IPython.OutputArea(output, false);
var callbacks = { 'output': $.proxy(output_area.handle_output, output_area) };
var code = 'print 1+1'
var msg_id = IPython.notebook.kernel.execute(code, callbacks, {silent: false});
This works when I load the directview.ipynb. However I am still not clear how to make it pletely standalone (i.e. not require the directview.py, and pass another callback than the standard handle_output
of IPython.OutputArea
). One of the issues is the container.show()
which fails when called in a standalone way.
I am lost on several aspects:
- Why is there an
element.append(widget)
and then$(widget).append(output)
? Also why is there also a need to create anIpython.OutputArea
. Isn't there a way to just create a<div id=my_output_area>blah</div>
and then have theoutput
callback fill it with the relevant data? - What's the whole .proxy thing about? I would like to create my own callback for
output
but when I do that andconsole.log()
the arguments passed to the callback, they'reundefined
or just useless.
I appreciate that the authors of the IPython notebook have done an incredible job creating such a beautiful front-end using jQuery/websockets, and that creating developer documentation that allows beginners like me to tweak with it is asking much, but if anyone can lend a hand that would be great!
My goal is to write an interactive variable viewer for IPython, i.e. which allows one to see, say nested dicts/lists as a tree, and drill down (a bit like the console.log in Javascript).
I spent a lot of time trying to extract minimalistic code out of the directview example in IPython but still can't get my head around how it all works. My Python's ok but my jQuery experience is quite limited.
So I got to stripping down directview.js to the following
container.show();
var widget = $('<div/>')
element.append(widget);
var output = $('<div></div>');
$(widget).append(output)
var output_area = new IPython.OutputArea(output, false);
var callbacks = { 'output': $.proxy(output_area.handle_output, output_area) };
var code = 'print 1+1'
var msg_id = IPython.notebook.kernel.execute(code, callbacks, {silent: false});
This works when I load the directview.ipynb. However I am still not clear how to make it pletely standalone (i.e. not require the directview.py, and pass another callback than the standard handle_output
of IPython.OutputArea
). One of the issues is the container.show()
which fails when called in a standalone way.
I am lost on several aspects:
- Why is there an
element.append(widget)
and then$(widget).append(output)
? Also why is there also a need to create anIpython.OutputArea
. Isn't there a way to just create a<div id=my_output_area>blah</div>
and then have theoutput
callback fill it with the relevant data? - What's the whole .proxy thing about? I would like to create my own callback for
output
but when I do that andconsole.log()
the arguments passed to the callback, they'reundefined
or just useless.
I appreciate that the authors of the IPython notebook have done an incredible job creating such a beautiful front-end using jQuery/websockets, and that creating developer documentation that allows beginners like me to tweak with it is asking much, but if anyone can lend a hand that would be great!
Share Improve this question edited Feb 26, 2013 at 18:11 Perception 80.6k19 gold badges189 silver badges196 bronze badges asked Jul 26, 2012 at 11:52 joelhorojoelhoro 9201 gold badge9 silver badges21 bronze badges1 Answer
Reset to default 2I can answer to your second question. The fact is when JavaScript calls your callback, it makes it so without specifying the context, i.e. without setting this
(Pythonistas call it self
). But it's possible to bound a function to this
via $.proxy
, which you saw in:
var callbacks = { 'output': $.proxy(output_area.handle_output, output_area) };
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745177533a4615266.html
评论列表(0条)