[IPython-dev] (no subject)

Jonathan Frederic jon.freder at gmail.com
Fri Sep 25 01:23:51 EDT 2015


Sorry, remove the -1 from the get_selected_index - that was because I was
using shift+enter to test.  It should be:

from IPython.display import Javascript, display
display(Javascript("""
var start = IPython.notebook.get_selected_index();
for (var i = start+1; i < IPython.notebook.ncells(); i++) {
    IPython.notebook.get_cell(i).execute();
};
IPython.notebook.get_cell(start).clear_output;
"""))

On Thu, Sep 24, 2015 at 10:22 PM, Jonathan Frederic <jon.freder at gmail.com>
wrote:

> Hi Col,
>
> You'll need to use Javascript to accomplish that.  The following is a
> hack, but should do the trick:
>
> from IPython.display import Javascript, display
> display(Javascript("""
> var start = IPython.notebook.get_selected_index()-1;
> for (var i = start+1; i < IPython.notebook.ncells(); i++) {
>     IPython.notebook.get_cell(i).execute();
> };
> IPython.notebook.get_cell(start).clear_output;
> """))
>
> Cheers,
> Jon
>
> On Thu, Sep 24, 2015 at 6:24 PM, col <colyork at gmail.com> wrote:
>
>> I'm trying use a multi select widget to enable users to select from a
>> list of countries, and then have a widget button which, when clicked, runs
>> all the cells below.
>>
>> This displays the list.
>>
>> from IPython.display import display
>> w = widgets.SelectMultiple(
>>
>>     description="Select up to five countries",
>>     options=dfCountries['name'].tolist()
>> )
>> display(w)
>>
>> And I want something like this to run all cells below:
>>
>> def run_all(button):
>>     get_ipython().run_cell()
>>
>> button = widgets.Button(description="Create next input")
>> button.on_click(run_all)
>> display(button)
>>
>> But I can't find the hook to 'run all cells below
>>
>> Thanks
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> https://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150924/d24d8b7a/attachment.html>


More information about the IPython-dev mailing list