<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Le 10 juil. 2012 ŕ 09:03, Zoltán Vörös a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi Matthias,<br><br>Thanks for the comments! Here are mine.<br><br>On 07/10/2012 08:38 AM, Matthias BUSSONNIER wrote:<br><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">kernel.execute("pyfunc();", {'output': $.proxy(this.output_area.handle_output, this.output_area)});<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">but I don't know how to get 'this'. &nbsp;I think, tying the output to the output handler would be fine with me.<br></blockquote></blockquote><blockquote type="cite">Either you trust IPython.notebook.selected_cell (or smith like that) at each call.<br></blockquote><blockquote type="cite">You can take a more object oriented version of your script and store the value<br></blockquote><blockquote type="cite">of IPython.notebook.selected_cell when the script is inserted.<br></blockquote><blockquote type="cite">Or, as ou insert the script through python, try to find yourself, then the containing `codecell`.<br></blockquote><blockquote type="cite">Something like inserting before the script a&lt;div&gt; &nbsp;with a known random id, `$('myid')`the get get the correct nth parent.<br></blockquote>OK, I will try to experiment with that. This sounds much less trouble than creating a custom widget for the purpose.<br><br><blockquote type="cite"><blockquote type="cite">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'.<br></blockquote></blockquote><blockquote type="cite">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 ?`<br></blockquote>Very nicely put:) &nbsp;What really confuses me, however, is the fact that, from Animation_and_Progress.ipynb, this works<br><br>for n in range(1,10):<br> &nbsp;&nbsp;&nbsp;time.sleep(1)<br> &nbsp;&nbsp;&nbsp;ax.plot(x, jn(x,n))<br> &nbsp;&nbsp;&nbsp;clear_output()<br> &nbsp;&nbsp;&nbsp;display(f)<br></div></blockquote><div><br></div><div>The difference is here that everything is executed in the kernel, and the codecell take care of binding the code it send to the kernel to its own _handle_output. Then, every call in the kernel to clear_output and display(f) are known to be owned by this cell.&nbsp;</div><div>&nbsp;the codecell does (using half js/half python syntax ):</div><div><br></div><div>IPython.kernel.execute(</div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>"""</div></div><div><div><div>for n in range(1,10):</div></div></div><div><div><div>&nbsp;&nbsp;&nbsp;time.sleep(1)</div></div></div><div><div><div>&nbsp;&nbsp;&nbsp;ax.plot(x, jn(x,n))</div></div></div><div><div><div>&nbsp;&nbsp;&nbsp;clear_output()</div></div></div><div><div><div>&nbsp;&nbsp;&nbsp;display(f)</div></div></div><div><div>""",&nbsp;</div></div><div><div>callbacks = {<span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span></div></div><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>stdout: self.stdout_handler,<span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span></div><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>stderr: self.stderr_handler<span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span></div><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>…<span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span></div><div>&nbsp;}</div></blockquote><div><div>)</div><div><br></div><div><br></div><div>The second JS progress bar generate a string with a random uuid `divid = str(uuid.uuid4())` and then the progress bar can be updated by any js, displayed anywhere as long as you know the id of the div :&nbsp;</div><div>"$('div#%s').width('%i%%')" % (divid, i)</div><div><br></div><div>Which can read : select the dis which id is `divid` and apply a width of `i%` to it.</div><div><br></div><div>If you look at the source code, there is actually 102 (1+101) div appended (one every 0.1 sec), with all but the first one that are "display:none".</div><div><br></div><br><blockquote type="cite"><div><br>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.)<br></div></blockquote><div><br></div><div>That is strange, and might be a bug.</div><div>Brian does know much more on how JS side works, so we might want to ask him.&nbsp;</div><div>You can try to open an issue about it on github, but we'll all be pretty low on bandwidth for the next 2 weeks,</div><div>That is to say until after SciPy.</div><div><br></div><div>--&nbsp;</div><div>Matthias</div></div></body></html>