mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
containers and selectioncontainers now only allow one of any single child
This commit is contained in:
parent
bfdebf9632
commit
7387f886c6
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user