##// END OF EJS Templates
s/choose/manual/g
Gordon Ball -
Show More
@@ -9,7 +9,7 b' from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress, IntRang'
9 from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
9 from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
10 from .widget_selectioncontainer import Tab, Accordion
10 from .widget_selectioncontainer import Tab, Accordion
11 from .widget_string import HTML, Latex, Text, Textarea
11 from .widget_string import HTML, Latex, Text, Textarea
12 from .interaction import interact, interactive, fixed, interact_choose
12 from .interaction import interact, interactive, fixed, interact_manual
13
13
14 # Deprecated classes
14 # Deprecated classes
15 from .widget_bool import CheckboxWidget, ToggleButtonWidget
15 from .widget_bool import CheckboxWidget, ToggleButtonWidget
@@ -175,7 +175,7 b' def interactive(__interact_f, **kwargs):'
175 """Build a group of widgets to interact with a function."""
175 """Build a group of widgets to interact with a function."""
176 f = __interact_f
176 f = __interact_f
177 co = kwargs.pop('clear_output', True)
177 co = kwargs.pop('clear_output', True)
178 choose = kwargs.pop('__choose', False)
178 manual = kwargs.pop('__manual', False)
179 kwargs_widgets = []
179 kwargs_widgets = []
180 container = Box()
180 container = Box()
181 container.result = None
181 container.result = None
@@ -197,9 +197,9 b' def interactive(__interact_f, **kwargs):'
197 c = [w for w in kwargs_widgets if isinstance(w, DOMWidget)]
197 c = [w for w in kwargs_widgets if isinstance(w, DOMWidget)]
198
198
199 # If we are only to run the function on demand, add a button to request this
199 # If we are only to run the function on demand, add a button to request this
200 if choose:
200 if manual:
201 choose_button = Button(description="Run %s" % f.__name__)
201 manual_button = Button(description="Run %s" % f.__name__)
202 c.append(choose_button)
202 c.append(manual_button)
203 container.children = c
203 container.children = c
204
204
205 # Build the callback
205 # Build the callback
@@ -210,8 +210,8 b' def interactive(__interact_f, **kwargs):'
210 container.kwargs[widget.description] = value
210 container.kwargs[widget.description] = value
211 if co:
211 if co:
212 clear_output(wait=True)
212 clear_output(wait=True)
213 if choose:
213 if manual:
214 choose_button.disabled = True
214 manual_button.disabled = True
215 try:
215 try:
216 container.result = f(**container.kwargs)
216 container.result = f(**container.kwargs)
217 except Exception as e:
217 except Exception as e:
@@ -221,15 +221,15 b' def interactive(__interact_f, **kwargs):'
221 else:
221 else:
222 ip.showtraceback()
222 ip.showtraceback()
223 finally:
223 finally:
224 if choose:
224 if manual:
225 choose_button.disabled = False
225 manual_button.disabled = False
226
226
227 # Wire up the widgets
227 # Wire up the widgets
228 # If we are doing choose running, the callback is only triggered by the button
228 # If we are doing manual running, the callback is only triggered by the button
229 # Otherwise, it is triggered for every trait change received
229 # Otherwise, it is triggered for every trait change received
230 # On-demand running also suppresses running the fucntion with the initial parameters
230 # On-demand running also suppresses running the fucntion with the initial parameters
231 if choose:
231 if manual:
232 choose_button.on_click(call_f)
232 manual_button.on_click(call_f)
233 else:
233 else:
234 for widget in kwargs_widgets:
234 for widget in kwargs_widgets:
235 widget.on_trait_change(call_f, 'value')
235 widget.on_trait_change(call_f, 'value')
@@ -266,15 +266,15 b' def interact(__interact_f=None, **kwargs):'
266 return f
266 return f
267 return dec
267 return dec
268
268
269 def interact_choose(__interact_f=None, **kwargs):
269 def interact_manual(__interact_f=None, **kwargs):
270 """interact_choose(f, **kwargs)
270 """interact_manual(f, **kwargs)
271
271
272 As `interact()`, generates widgets for each argument, but rather than running
272 As `interact()`, generates widgets for each argument, but rather than running
273 the function after each widget change, adds a "Run" button and waits for it
273 the function after each widget change, adds a "Run" button and waits for it
274 to be clicked. Useful if the function is long-running and has several
274 to be clicked. Useful if the function is long-running and has several
275 parameters to change.
275 parameters to change.
276 """
276 """
277 return interact(__interact_f, __choose=True, **kwargs)
277 return interact(__interact_f, __manual=True, **kwargs)
278
278
279 class fixed(HasTraits):
279 class fixed(HasTraits):
280 """A pseudo-widget whose value is fixed and never synced to the client."""
280 """A pseudo-widget whose value is fixed and never synced to the client."""
@@ -481,16 +481,16 b' def test_custom_description():'
481 description='foo',
481 description='foo',
482 )
482 )
483
483
484 def test_interact_choose_button():
484 def test_interact_manual_button():
485 c = interactive(f, __choose=True)
485 c = interactive(f, __manual=True)
486 w = c.children[0]
486 w = c.children[0]
487 check_widget(w, cls=widgets.Button)
487 check_widget(w, cls=widgets.Button)
488
488
489 def test_interact_choose_nocall():
489 def test_interact_manual_nocall():
490 callcount = 0
490 callcount = 0
491 def calltest(testarg):
491 def calltest(testarg):
492 callcount += 1
492 callcount += 1
493 c = interactive(calltest, testarg=5, __choose=True)
493 c = interactive(calltest, testarg=5, __manual=True)
494 c.children[0].value = 10
494 c.children[0].value = 10
495 nt.assert_equal(callcount, 0)
495 nt.assert_equal(callcount, 0)
496
496
General Comments 0
You need to be logged in to leave comments. Login now