diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py
index d3cdb11..e14c773 100644
--- a/IPython/html/widgets/__init__.py
+++ b/IPython/html/widgets/__init__.py
@@ -9,7 +9,7 @@ from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress, IntRang
from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
from .widget_selectioncontainer import Tab, Accordion
from .widget_string import HTML, Latex, Text, Textarea
-from .interaction import interact, interactive, fixed
+from .interaction import interact, interactive, fixed, interact_choose
# Deprecated classes
from .widget_bool import CheckboxWidget, ToggleButtonWidget
diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py
index b3c102f..fe7080c 100644
--- a/IPython/html/widgets/interaction.py
+++ b/IPython/html/widgets/interaction.py
@@ -175,7 +175,7 @@ def interactive(__interact_f, **kwargs):
"""Build a group of widgets to interact with a function."""
f = __interact_f
co = kwargs.pop('clear_output', True)
- on_demand = kwargs.pop('on_demand', False)
+ choose = kwargs.pop('__choose', False)
kwargs_widgets = []
container = Box()
container.result = None
@@ -197,9 +197,9 @@ def interactive(__interact_f, **kwargs):
c = [w for w in kwargs_widgets if isinstance(w, DOMWidget)]
# If we are only to run the function on demand, add a button to request this
- if on_demand:
- on_demand_button = Button(description="Run %s" % f.__name__)
- c.append(on_demand_button)
+ if choose:
+ choose_button = Button(description="Run %s" % f.__name__)
+ c.append(choose_button)
container.children = c
# Build the callback
@@ -210,8 +210,8 @@ def interactive(__interact_f, **kwargs):
container.kwargs[widget.description] = value
if co:
clear_output(wait=True)
- if on_demand:
- on_demand_button.disabled = True
+ if choose:
+ choose_button.disabled = True
try:
container.result = f(**container.kwargs)
except Exception as e:
@@ -221,15 +221,15 @@ def interactive(__interact_f, **kwargs):
else:
ip.showtraceback()
finally:
- if on_demand:
- on_demand_button.disabled = False
+ if choose:
+ choose_button.disabled = False
# Wire up the widgets
- # If we are doing on demand running, the callback is only triggered by the button
+ # If we are doing choose running, the callback is only triggered by the button
# Otherwise, it is triggered for every trait change received
# On-demand running also suppresses running the fucntion with the initial parameters
- if on_demand:
- on_demand_button.on_click(call_f)
+ if choose:
+ choose_button.on_click(call_f)
else:
for widget in kwargs_widgets:
widget.on_trait_change(call_f, 'value')
@@ -266,6 +266,16 @@ def interact(__interact_f=None, **kwargs):
return f
return dec
+def interact_choose(__interact_f=None, **kwargs):
+ """interact_choose(f, **kwargs)
+
+ As `interact()`, generates widgets for each argument, but rather than running
+ the function after each widget change, adds a "Run" button and waits for it
+ to be clicked. Useful if the function is long-running and has several
+ parameters to change.
+ """
+ return interact(__interact_f, __choose=True, **kwargs)
+
class fixed(HasTraits):
"""A pseudo-widget whose value is fixed and never synced to the client."""
value = Any(help="Any Python object")
diff --git a/IPython/html/widgets/tests/test_interaction.py b/IPython/html/widgets/tests/test_interaction.py
index 51c9c5e..7d9ef7e 100644
--- a/IPython/html/widgets/tests/test_interaction.py
+++ b/IPython/html/widgets/tests/test_interaction.py
@@ -481,16 +481,16 @@ def test_custom_description():
description='foo',
)
-def test_interact_ondemand_button():
- c = interactive(f, on_demand=True)
+def test_interact_choose_button():
+ c = interactive(f, __choose=True)
w = c.children[0]
check_widget(w, cls=widgets.Button)
-def test_interact_ondemand_nocall():
+def test_interact_choose_nocall():
callcount = 0
def calltest(testarg):
callcount += 1
- c = interactive(calltest, testarg=5, on_demand=True)
+ c = interactive(calltest, testarg=5, __choose=True)
c.children[0].value = 10
nt.assert_equal(callcount, 0)