Show More
@@ -14,27 +14,20 b' Represents a container that can be used to group other widgets.' | |||
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | from .widget import DOMWidget |
|
17 |
from IPython.utils.traitlets import Unicode, Tuple, |
|
|
17 | from IPython.utils.traitlets import Unicode, Tuple, TraitError | |
|
18 | 18 | |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | # Classes |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | class TupleOfDOMWidgets(Tuple): | |
|
24 | """Like Tuple(Instance(DOMWidget)), but without checking length.""" | |
|
25 | def validate_elements(self, obj, value): | |
|
26 | for v in value: | |
|
27 | if not isinstance(v, DOMWidget): | |
|
28 | raise TraitError("Container.children must be DOMWidgets, not %r" % v) | |
|
29 | return value | |
|
30 | ||
|
31 | 23 | class ContainerWidget(DOMWidget): |
|
32 | 24 | _view_name = Unicode('ContainerView', sync=True) |
|
33 | 25 | |
|
34 | # Keys, all private and managed by helper methods. Flexible box model | |
|
35 | # classes... | |
|
36 | children = TupleOfDOMWidgets() | |
|
37 |
|
|
|
26 | # Child widgets in the container. | |
|
27 | # Using a tuple here to force reassignment to update the list. | |
|
28 | # When a proper notifying-list trait exists, that is what should be used here. | |
|
29 | children = Tuple() | |
|
30 | _children = Tuple(sync=True) | |
|
38 | 31 | |
|
39 | 32 | def _children_changed(self, name, old, new): |
|
40 | 33 | """Validate children list. |
General Comments 0
You need to be logged in to leave comments.
Login now