Show More
@@ -24,11 +24,29 b' class ContainerWidget(DOMWidget):' | |||||
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 | _children = List(Instance(DOMWidget), sync=True) | |||
28 |
|
29 | |||
29 | description = Unicode(sync=True) |
|
30 | def __init__(self, *pargs, **kwargs): | |
30 | button_text = Unicode(sync=True) |
|
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) |
@@ -14,21 +14,19 b' pages.' | |||||
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. |
General Comments 0
You need to be logged in to leave comments.
Login now