[IPython-User] question about frontend-kernel interaction
Matthias BUSSONNIER
bussonniermatthias@gmail....
Tue Jul 10 01:38:38 CDT 2012
Hi Zoltán,
Le 9 juil. 2012 à 23:44, Zoltán Vörös a écrit :
> Hi Matthias,
>
>
> Something like the example 'directview'? I could try, though it seems a lot of trouble...:(
> What is not clear to me at the moment is how I gain access to 'this' from within the notebook. What you suggest above is that I should have something like this for the kernel call
>
> kernel.execute("pyfunc();", {'output': $.proxy(this.output_area.handle_output, this.output_area)});
>
> but I don't know how to get 'this'. I think, tying the output to the output handler would be fine with me.
Either you trust IPython.notebook.selected_cell (or smith like that) at each call.
You can take a more object oriented version of your script and store the value
of IPython.notebook.selected_cell when the script is inserted.
Or, as ou insert the script through python, try to find yourself, then the containing `codecell`.
Something like inserting before the script a <div> with a known random id, `$('myid')`the get get the correct nth parent.
But then I lack JS knowledge to help you.
> By the way, the problem is not related to figures. This example does not display anything, while the code is actually executed. This I know from printing out the value of 'a'.
Yes, whatever you try to display, if you don't bound a request to a handler the fronted has no way of knowing `where the hell should I print this message I got from the kernel ?`
> from IPython.core.display import display, HTML, clear_output
Note that if you wish to use clear_output in your function, you will remove the script that you've just injected...
So you'll be able to update only once...
--
Matthias
> html = """<script type="text/javascript">
> function jsfunction () {
> IPython.notebook.kernel.execute("a+=1; pyfunc();");
> }
> </script>
> <input type="button" value="Click" onclick="jsfunction()" />
> """
> a = 1
> display(HTML(html))
> def pyfunc():
> print 'hi!'
>
More information about the IPython-User
mailing list