##// END OF EJS Templates
Adding const pseudo-widget for fixing arguments to interact.
Brian E. Granger -
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -9,4 +9,4 b' from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, In'
9 9 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, SelectWidget
10 10 from .widget_selectioncontainer import TabWidget, AccordionWidget
11 11 from .widget_string import HTMLWidget, LatexWidget, TextWidget, TextareaWidget
12 from .interaction import interact, interactive, annotate
12 from .interaction import interact, interactive, annotate, const
@@ -22,9 +22,10 b' from inspect import getcallargs'
22 22
23 23 from IPython.html.widgets import (Widget, TextWidget,
24 24 FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget,
25 ContainerWidget)
25 ContainerWidget, DOMWidget)
26 26 from IPython.display import display, clear_output
27 27 from IPython.utils.py3compat import string_types, unicode_type
28 from IPython.utils.traitlets import HasTraits, Any, Unicode
28 29
29 30 #-----------------------------------------------------------------------------
30 31 # Classes and Functions
@@ -107,7 +108,7 b' def _widget_abbrev(o):'
107 108
108 109 def _widget_from_abbrev(abbrev):
109 110 """Build a Widget intstance given an abbreviation or Widget."""
110 if isinstance(abbrev, Widget):
111 if isinstance(abbrev, Widget) or isinstance(abbrev, const):
111 112 return abbrev
112 113
113 114 widget = _widget_abbrev(abbrev)
@@ -211,8 +212,10 b' def interactive(f, *args, **kwargs):'
211 212 kwargs_widgets.extend(_widgets_from_abbreviations(sorted(kwargs.items(), key = lambda x: x[0])))
212 213
213 214 # This has to be done as an assignment, not using container.children.append,
214 # so that traitlets notices the update.
215 container.children = args_widgets + kwargs_widgets
215 # so that traitlets notices the update. We skip any objects (such as const) that
216 # are not DOMWidgets.
217 c = [w for w in args_widgets+kwargs_widgets if isinstance(w, DOMWidget)]
218 container.children = c
216 219
217 220 # Build the callback
218 221 def call_f(name, old, new):
@@ -261,6 +264,13 b' def interact(*args, **kwargs):'
261 264 return f
262 265 return dec
263 266
267 class const(HasTraits):
268 """A pseudo-widget whose value is constant and never client synced."""
269 value = Any(help="Any Python object")
270 description = Unicode('', help="Any Python object")
271 def __init__(self, value, **kwargs):
272 super(const, self).__init__(value=value, **kwargs)
273
264 274 def annotate(**kwargs):
265 275 """Python 3 compatible function annotation for Python 2."""
266 276 if not kwargs:
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now