##// END OF EJS Templates
s/CTuple/Tuple
Jonathan Frederic -
Show More
@@ -1,51 +1,51 b''
1 """ContainerWidget class.
1 """ContainerWidget class.
2
2
3 Represents a container that can be used to group other widgets.
3 Represents a container that can be used to group other widgets.
4 """
4 """
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CTuple, Instance
17 from IPython.utils.traitlets import Unicode, Tuple, Instance
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class ContainerWidget(DOMWidget):
22 class ContainerWidget(DOMWidget):
23 _view_name = Unicode('ContainerView', sync=True)
23 _view_name = Unicode('ContainerView', sync=True)
24
24
25 # Keys, all private and managed by helper methods. Flexible box model
25 # Keys, all private and managed by helper methods. Flexible box model
26 # classes...
26 # classes...
27 children = CTuple(Instance(DOMWidget))
27 children = Tuple(Instance(DOMWidget))
28 _children = CTuple(Instance(DOMWidget), sync=True)
28 _children = Tuple(Instance(DOMWidget), sync=True)
29
29
30 def _children_changed(self, name, old, new):
30 def _children_changed(self, name, old, new):
31 """Validate children list.
31 """Validate children list.
32
32
33 Makes sure only one instance of any given model can exist in the
33 Makes sure only one instance of any given model can exist in the
34 children list.
34 children list.
35 An excellent post on uniqifiers is available at
35 An excellent post on uniqifiers is available at
36 http://www.peterbe.com/plog/uniqifiers-benchmark
36 http://www.peterbe.com/plog/uniqifiers-benchmark
37 which provides the inspiration for using this implementation. Below
37 which provides the inspiration for using this implementation. Below
38 I've implemented the `f5` algorithm using Python comprehensions."""
38 I've implemented the `f5` algorithm using Python comprehensions."""
39 if new is not None and isinstance(new, list):
39 if new is not None and isinstance(new, list):
40 seen = {}
40 seen = {}
41 def add_item(i):
41 def add_item(i):
42 seen[i.model_id] = True
42 seen[i.model_id] = True
43 return i
43 return i
44 self._children = [add_item(i) for i in new if not i.model_id in seen]
44 self._children = [add_item(i) for i in new if not i.model_id in seen]
45
45
46
46
47 class PopupWidget(ContainerWidget):
47 class PopupWidget(ContainerWidget):
48 _view_name = Unicode('PopupView', sync=True)
48 _view_name = Unicode('PopupView', sync=True)
49
49
50 description = Unicode(sync=True)
50 description = Unicode(sync=True)
51 button_text = Unicode(sync=True)
51 button_text = Unicode(sync=True)
General Comments 0
You need to be logged in to leave comments. Login now