|
|
|
|
@ -14,18 +14,27 @@ Represents a container that can be used to group other widgets.
|
|
|
|
|
# Imports
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
from .widget import DOMWidget
|
|
|
|
|
from IPython.utils.traitlets import Unicode, Tuple, Instance
|
|
|
|
|
from IPython.utils.traitlets import Unicode, Tuple, Instance, TraitError
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
# Classes
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class TupleOfDOMWidgets(Tuple):
|
|
|
|
|
"""Like Tuple(Instance(DOMWidget)), but without checking length."""
|
|
|
|
|
def validate_elements(self, obj, value):
|
|
|
|
|
for v in value:
|
|
|
|
|
if not isinstance(v, DOMWidget):
|
|
|
|
|
raise TraitError("Container.children must be DOMWidgets, not %r" % v)
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
class ContainerWidget(DOMWidget):
|
|
|
|
|
_view_name = Unicode('ContainerView', sync=True)
|
|
|
|
|
|
|
|
|
|
# Keys, all private and managed by helper methods. Flexible box model
|
|
|
|
|
# classes...
|
|
|
|
|
children = Tuple(Instance(DOMWidget))
|
|
|
|
|
_children = Tuple(Instance(DOMWidget), sync=True)
|
|
|
|
|
children = TupleOfDOMWidgets()
|
|
|
|
|
_children = TupleOfDOMWidgets(sync=True)
|
|
|
|
|
|
|
|
|
|
def _children_changed(self, name, old, new):
|
|
|
|
|
"""Validate children list.
|
|
|
|
|
@ -36,7 +45,7 @@ class ContainerWidget(DOMWidget):
|
|
|
|
|
http://www.peterbe.com/plog/uniqifiers-benchmark
|
|
|
|
|
which provides the inspiration for using this implementation. Below
|
|
|
|
|
I've implemented the `f5` algorithm using Python comprehensions."""
|
|
|
|
|
if new is not None and isinstance(new, list):
|
|
|
|
|
if new is not None:
|
|
|
|
|
seen = {}
|
|
|
|
|
def add_item(i):
|
|
|
|
|
seen[i.model_id] = True
|
|
|
|
|
|