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