Show More
@@ -1,34 +1,52 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, Bool, List, Instance |
|
17 | from IPython.utils.traitlets import Unicode, Bool, List, 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 = List(Instance(DOMWidget) |
|
27 | children = List(Instance(DOMWidget)) | |
28 |
|
28 | _children = List(Instance(DOMWidget), sync=True) | ||
29 | description = Unicode(sync=True) |
|
29 | ||
30 | button_text = Unicode(sync=True) |
|
30 | def __init__(self, *pargs, **kwargs): | |
|
31 | """Constructor""" | |||
|
32 | DOMWidget.__init__(self, *pargs, **kwargs) | |||
|
33 | self.on_trait_change(self._validate, ['children']) | |||
|
34 | ||||
|
35 | def _validate(self, name, old, new): | |||
|
36 | """Validate children list. | |||
|
37 | ||||
|
38 | Makes sure only one instance of any given model can exist in the | |||
|
39 | children list.""" | |||
|
40 | if new is not None and isinstance(new, list): | |||
|
41 | children = [] | |||
|
42 | for child in new: | |||
|
43 | if child not in children: | |||
|
44 | children.append(child) | |||
|
45 | self._children = children | |||
31 |
|
46 | |||
32 |
|
47 | |||
33 | class ModalWidget(ContainerWidget): |
|
48 | class ModalWidget(ContainerWidget): | |
34 | view_name = Unicode('ModalView', sync=True) |
|
49 | view_name = Unicode('ModalView', sync=True) | |
|
50 | ||||
|
51 | description = Unicode(sync=True) | |||
|
52 | button_text = Unicode(sync=True) |
@@ -1,59 +1,57 b'' | |||||
1 | """SelectionContainerWidget class. |
|
1 | """SelectionContainerWidget class. | |
2 |
|
2 | |||
3 | Represents a multipage container that can be used to group other widgets into |
|
3 | Represents a multipage container that can be used to group other widgets into | |
4 | pages. |
|
4 | pages. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
from .widget import |
|
17 | from .widget_container import ContainerWidget | |
18 | from IPython.utils.traitlets import Unicode, Dict, CInt, List, Instance |
|
18 | from IPython.utils.traitlets import Unicode, Dict, CInt, List, Instance | |
19 |
|
19 | |||
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 | # Classes |
|
21 | # Classes | |
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 |
class AccordionWidget( |
|
23 | class AccordionWidget(ContainerWidget): | |
24 | view_name = Unicode('AccordionView', sync=True) |
|
24 | view_name = Unicode('AccordionView', sync=True) | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 | _titles = Dict(help="Titles of the pages", sync=True) |
|
27 | _titles = Dict(help="Titles of the pages", sync=True) | |
28 | selected_index = CInt(0, sync=True) |
|
28 | selected_index = CInt(0, sync=True) | |
29 |
|
29 | |||
30 | children = List(Instance(DOMWidget), sync=True) |
|
|||
31 |
|
||||
32 | # Public methods |
|
30 | # Public methods | |
33 | def set_title(self, index, title): |
|
31 | def set_title(self, index, title): | |
34 | """Sets the title of a container page. |
|
32 | """Sets the title of a container page. | |
35 |
|
33 | |||
36 | Parameters |
|
34 | Parameters | |
37 | ---------- |
|
35 | ---------- | |
38 | index : int |
|
36 | index : int | |
39 | Index of the container page |
|
37 | Index of the container page | |
40 | title : unicode |
|
38 | title : unicode | |
41 | New title""" |
|
39 | New title""" | |
42 | self._titles[index] = title |
|
40 | self._titles[index] = title | |
43 | self.send_state('_titles') |
|
41 | self.send_state('_titles') | |
44 |
|
42 | |||
45 | def get_title(self, index): |
|
43 | def get_title(self, index): | |
46 | """Gets the title of a container pages. |
|
44 | """Gets the title of a container pages. | |
47 |
|
45 | |||
48 | Parameters |
|
46 | Parameters | |
49 | ---------- |
|
47 | ---------- | |
50 | index : int |
|
48 | index : int | |
51 | Index of the container page""" |
|
49 | Index of the container page""" | |
52 | if index in self._titles: |
|
50 | if index in self._titles: | |
53 | return self._titles[index] |
|
51 | return self._titles[index] | |
54 | else: |
|
52 | else: | |
55 | return None |
|
53 | return None | |
56 |
|
54 | |||
57 |
|
55 | |||
58 | class TabWidget(AccordionWidget): |
|
56 | class TabWidget(AccordionWidget): | |
59 | view_name = Unicode('TabView', sync=True) |
|
57 | view_name = Unicode('TabView', sync=True) |
General Comments 0
You need to be logged in to leave comments.
Login now