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