##// END OF EJS Templates
Merge pull request #15 from minrk/ctuple...
Jonathan Frederic -
r15478:710ce285 merge
parent child Browse files
Show More
@@ -14,18 +14,27 b' Represents a container that can be used to group other widgets.'
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, Tuple, Instance
17 from IPython.utils.traitlets import Unicode, Tuple, Instance, TraitError
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22
23 class TupleOfDOMWidgets(Tuple):
24 """Like Tuple(Instance(DOMWidget)), but without checking length."""
25 def validate_elements(self, obj, value):
26 for v in value:
27 if not isinstance(v, DOMWidget):
28 raise TraitError("Container.children must be DOMWidgets, not %r" % v)
29 return value
30
22 class ContainerWidget(DOMWidget):
31 class ContainerWidget(DOMWidget):
23 _view_name = Unicode('ContainerView', sync=True)
32 _view_name = Unicode('ContainerView', sync=True)
24
33
25 # Keys, all private and managed by helper methods. Flexible box model
34 # Keys, all private and managed by helper methods. Flexible box model
26 # classes...
35 # classes...
27 children = Tuple(Instance(DOMWidget))
36 children = TupleOfDOMWidgets()
28 _children = Tuple(Instance(DOMWidget), sync=True)
37 _children = TupleOfDOMWidgets(sync=True)
29
38
30 def _children_changed(self, name, old, new):
39 def _children_changed(self, name, old, new):
31 """Validate children list.
40 """Validate children list.
@@ -36,7 +45,7 b' class ContainerWidget(DOMWidget):'
36 http://www.peterbe.com/plog/uniqifiers-benchmark
45 http://www.peterbe.com/plog/uniqifiers-benchmark
37 which provides the inspiration for using this implementation. Below
46 which provides the inspiration for using this implementation. Below
38 I've implemented the `f5` algorithm using Python comprehensions."""
47 I've implemented the `f5` algorithm using Python comprehensions."""
39 if new is not None and isinstance(new, list):
48 if new is not None:
40 seen = {}
49 seen = {}
41 def add_item(i):
50 def add_item(i):
42 seen[i.model_id] = True
51 seen[i.model_id] = True
General Comments 0
You need to be logged in to leave comments. Login now