##// END OF EJS Templates
don't check shape of ContainerWidget.children
don't check shape of ContainerWidget.children

File last commit:

r15475:ef0aff9a
r15475:ef0aff9a
Show More
widget_container.py
60 lines | 2.3 KiB | text/x-python | PythonLexer
Jonathan Frederic
Cleaned up Python widget code.
r14283 """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
#-----------------------------------------------------------------------------
Jonathan Frederic
s/Widget/DOMWidget s/BaseWidget/Widget
r14540 from .widget import DOMWidget
MinRK
don't check shape of ContainerWidget.children
r15475 from IPython.utils.traitlets import Unicode, Tuple, Instance, TraitError
Jonathan Frederic
Add container widget
r14239
Jonathan Frederic
Cleaned up Python widget code.
r14283 #-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
MinRK
don't check shape of ContainerWidget.children
r15475
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
Jonathan Frederic
s/Widget/DOMWidget s/BaseWidget/Widget
r14540 class ContainerWidget(DOMWidget):
Jonathan Frederic
s/view_name/_view_name
r14701 _view_name = Unicode('ContainerView', sync=True)
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268
Jonathan Frederic
Cleaned up Python widget code.
r14283 # Keys, all private and managed by helper methods. Flexible box model
# classes...
MinRK
don't check shape of ContainerWidget.children
r15475 children = TupleOfDOMWidgets()
_children = TupleOfDOMWidgets(sync=True)
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608
Jonathan Frederic
Fixed type in container...
r14715 def _children_changed(self, name, old, new):
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608 """Validate children list.
Makes sure only one instance of any given model can exist in the
Jonathan Frederic
Replace O(N^2) algorithm with a faster one.
r14699 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."""
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608 if new is not None and isinstance(new, list):
Jonathan Frederic
Replace O(N^2) algorithm with a faster one.
r14699 seen = {}
def add_item(i):
seen[i.model_id] = True
return i
Jonathan Frederic
Fixed type in container...
r14715 self._children = [add_item(i) for i in new if not i.model_id in seen]
Jonathan Frederic
1-to-1 widget / view mapping
r14592
Jonathan Frederic
More PEP8 changes
r14607
Jonathan Frederic
s/ModalView/PopupView
r14676 class PopupWidget(ContainerWidget):
Jonathan Frederic
s/view_name/_view_name
r14701 _view_name = Unicode('PopupView', sync=True)
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608
description = Unicode(sync=True)
button_text = Unicode(sync=True)