[IPython-User] question about frontend-kernel interaction

Zoltán Vörös zvoros@gmail....
Tue Jul 10 02:03:39 CDT 2012


Hi Matthias,

Thanks for the comments! Here are mine.

On 07/10/2012 08:38 AM, Matthias BUSSONNIER wrote:
>>
>> 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.
OK, I will try to experiment with that. This sounds much less trouble 
than creating a custom widget for the purpose.

>> 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 ?`
Very nicely put:)  What really confuses me, however, is the fact that, 
from Animation_and_Progress.ipynb, this works

for n in range(1,10):
     time.sleep(1)
     ax.plot(x, jn(x,n))
     clear_output()
     display(f)

while if I try to do the very same by connecting a button to 
kernel.execute directly, what happens is not what one would expect. (In 
that case, the plots will be displayed after the next command in a code 
cell was entered manually.)

>> 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...
Oh, in the original function, I had this:

def pyfunc():
     ax.plot(rand(100))
     clear_output()
     display(HTML(html))
     display(f)

so the script was placed back into the output cell at each step.

Cheers,
Zoltán


More information about the IPython-User mailing list