mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
s/choose/manual/g
This commit is contained in:
parent
859e9f5261
commit
48e1a0b2bc
@ -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, interact_choose
|
||||
from .interaction import interact, interactive, fixed, interact_manual
|
||||
|
||||
# Deprecated classes
|
||||
from .widget_bool import CheckboxWidget, ToggleButtonWidget
|
||||
|
@ -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)
|
||||
choose = kwargs.pop('__choose', False)
|
||||
manual = kwargs.pop('__manual', 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 choose:
|
||||
choose_button = Button(description="Run %s" % f.__name__)
|
||||
c.append(choose_button)
|
||||
if manual:
|
||||
manual_button = Button(description="Run %s" % f.__name__)
|
||||
c.append(manual_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 choose:
|
||||
choose_button.disabled = True
|
||||
if manual:
|
||||
manual_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 choose:
|
||||
choose_button.disabled = False
|
||||
if manual:
|
||||
manual_button.disabled = False
|
||||
|
||||
# Wire up the widgets
|
||||
# If we are doing choose running, the callback is only triggered by the button
|
||||
# If we are doing manual 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 choose:
|
||||
choose_button.on_click(call_f)
|
||||
if manual:
|
||||
manual_button.on_click(call_f)
|
||||
else:
|
||||
for widget in kwargs_widgets:
|
||||
widget.on_trait_change(call_f, 'value')
|
||||
@ -266,15 +266,15 @@ def interact(__interact_f=None, **kwargs):
|
||||
return f
|
||||
return dec
|
||||
|
||||
def interact_choose(__interact_f=None, **kwargs):
|
||||
"""interact_choose(f, **kwargs)
|
||||
def interact_manual(__interact_f=None, **kwargs):
|
||||
"""interact_manual(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)
|
||||
return interact(__interact_f, __manual=True, **kwargs)
|
||||
|
||||
class fixed(HasTraits):
|
||||
"""A pseudo-widget whose value is fixed and never synced to the client."""
|
||||
|
@ -481,16 +481,16 @@ def test_custom_description():
|
||||
description='foo',
|
||||
)
|
||||
|
||||
def test_interact_choose_button():
|
||||
c = interactive(f, __choose=True)
|
||||
def test_interact_manual_button():
|
||||
c = interactive(f, __manual=True)
|
||||
w = c.children[0]
|
||||
check_widget(w, cls=widgets.Button)
|
||||
|
||||
def test_interact_choose_nocall():
|
||||
def test_interact_manual_nocall():
|
||||
callcount = 0
|
||||
def calltest(testarg):
|
||||
callcount += 1
|
||||
c = interactive(calltest, testarg=5, __choose=True)
|
||||
c = interactive(calltest, testarg=5, __manual=True)
|
||||
c.children[0].value = 10
|
||||
nt.assert_equal(callcount, 0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user