notebook/IPython/html/widgets/widget_container.py

52 lines
2.0 KiB
Python
Raw Normal View History

2013-10-26 02:31:48 +08:00
"""ContainerWidget class.
Represents a container that can be used to group other widgets.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
2014-01-07 20:04:24 +08:00
from .widget import DOMWidget
from IPython.utils.traitlets import Unicode, CTuple, Instance
2013-10-17 14:15:24 +08:00
2013-10-26 02:31:48 +08:00
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
2014-01-07 20:04:24 +08:00
class ContainerWidget(DOMWidget):
2014-01-23 08:21:00 +08:00
_view_name = Unicode('ContainerView', sync=True)
2013-10-26 02:31:48 +08:00
# Keys, all private and managed by helper methods. Flexible box model
# classes...
children = CTuple(Instance(DOMWidget))
_children = CTuple(Instance(DOMWidget), sync=True)
def _children_changed(self, name, old, new):
"""Validate children list.
Makes sure only one instance of any given model can exist in the
children list.
An excellent post on uniqifiers is available at
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):
seen = {}
def add_item(i):
seen[i.model_id] = True
return i
self._children = [add_item(i) for i in new if not i.model_id in seen]
2014-01-15 00:24:35 +08:00
2014-01-16 22:20:04 +08:00
2014-01-22 09:09:49 +08:00
class PopupWidget(ContainerWidget):
2014-01-23 08:21:00 +08:00
_view_name = Unicode('PopupView', sync=True)
description = Unicode(sync=True)
button_text = Unicode(sync=True)