diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py
index 54211a9..adc1c98 100644
--- a/IPython/html/widgets/widget_container.py
+++ b/IPython/html/widgets/widget_container.py
@@ -24,11 +24,29 @@ class ContainerWidget(DOMWidget):
# Keys, all private and managed by helper methods. Flexible box model
# classes...
- children = List(Instance(DOMWidget), sync=True)
-
- description = Unicode(sync=True)
- button_text = Unicode(sync=True)
+ children = List(Instance(DOMWidget))
+ _children = List(Instance(DOMWidget), sync=True)
+
+ def __init__(self, *pargs, **kwargs):
+ """Constructor"""
+ DOMWidget.__init__(self, *pargs, **kwargs)
+ self.on_trait_change(self._validate, ['children'])
+
+ def _validate(self, name, old, new):
+ """Validate children list.
+
+ Makes sure only one instance of any given model can exist in the
+ children list."""
+ if new is not None and isinstance(new, list):
+ children = []
+ for child in new:
+ if child not in children:
+ children.append(child)
+ self._children = children
class ModalWidget(ContainerWidget):
view_name = Unicode('ModalView', sync=True)
+
+ description = Unicode(sync=True)
+ button_text = Unicode(sync=True)
diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py
index c5c97d0..a095faf 100644
--- a/IPython/html/widgets/widget_selectioncontainer.py
+++ b/IPython/html/widgets/widget_selectioncontainer.py
@@ -14,21 +14,19 @@ pages.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
-from .widget import DOMWidget
+from .widget_container import ContainerWidget
from IPython.utils.traitlets import Unicode, Dict, CInt, List, Instance
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
-class AccordionWidget(DOMWidget):
+class AccordionWidget(ContainerWidget):
view_name = Unicode('AccordionView', sync=True)
# Keys
_titles = Dict(help="Titles of the pages", sync=True)
selected_index = CInt(0, sync=True)
- children = List(Instance(DOMWidget), sync=True)
-
# Public methods
def set_title(self, index, title):
"""Sets the title of a container page.