##// END OF EJS Templates
Make HBox and VBox helper functions
Jonathan Frederic -
Show More
@@ -1,65 +1,67 b''
1 """Container class.
1 """Container 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) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 from .widget import DOMWidget
9 from .widget import DOMWidget
10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
11 from IPython.utils.warn import DeprecatedClass
11 from IPython.utils.warn import DeprecatedClass
12
12
13 class Container(DOMWidget):
13 class Container(DOMWidget):
14 _view_name = Unicode('ContainerView', sync=True)
14 _view_name = Unicode('ContainerView', sync=True)
15
15
16 # Child widgets in the container.
16 # Child widgets in the container.
17 # Using a tuple here to force reassignment to update the list.
17 # Using a tuple here to force reassignment to update the list.
18 # When a proper notifying-list trait exists, that is what should be used here.
18 # When a proper notifying-list trait exists, that is what should be used here.
19 children = Tuple(sync=True, allow_none=False)
19 children = Tuple(sync=True, allow_none=False)
20
20
21 def __init__(self, children = (), **kwargs):
21 def __init__(self, children = (), **kwargs):
22 kwargs['children'] = children
22 kwargs['children'] = children
23 super(Container, self).__init__(**kwargs)
23 super(Container, self).__init__(**kwargs)
24 self.on_displayed(Container._fire_children_displayed)
24 self.on_displayed(Container._fire_children_displayed)
25
25
26 def _fire_children_displayed(self):
26 def _fire_children_displayed(self):
27 for child in self.children:
27 for child in self.children:
28 child._handle_displayed()
28 child._handle_displayed()
29
29
30
30
31 class Popup(Container):
31 class Popup(Container):
32 _view_name = Unicode('PopupView', sync=True)
32 _view_name = Unicode('PopupView', sync=True)
33
33
34 description = Unicode(sync=True)
34 description = Unicode(sync=True)
35 button_text = Unicode(sync=True)
35 button_text = Unicode(sync=True)
36
36
37
37
38 class FlexContainer(Container):
38 class FlexContainer(Container):
39 _view_name = Unicode('FlexContainerView', sync=True)
39 _view_name = Unicode('FlexContainerView', sync=True)
40 orientation = Unicode('vertical', sync=True)
40 orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True)
41 flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""")
41 flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""")
42 def _flex_changed(self, name, old, new):
42 def _flex_changed(self, name, old, new):
43 new = min(max(0, new), 2)
43 new = min(max(0, new), 2)
44 if self.flex != new:
44 if self.flex != new:
45 self.flex = new
45 self.flex = new
46
46
47 _locations = ['start', 'center', 'end', 'baseline', 'stretch']
47 _locations = ['start', 'center', 'end', 'baseline', 'stretch']
48 pack = CaselessStrEnum(
48 pack = CaselessStrEnum(
49 values=_locations,
49 values=_locations,
50 default_value='start', allow_none=False, sync=True)
50 default_value='start', allow_none=False, sync=True)
51 align = CaselessStrEnum(
51 align = CaselessStrEnum(
52 values=_locations,
52 values=_locations,
53 default_value='start', allow_none=False, sync=True)
53 default_value='start', allow_none=False, sync=True)
54
54
55
55
56 class VBox(FlexContainer):
56 def VBox(*pargs, **kwargs):
57 _view_name = Unicode('VBoxContainerView', sync=True)
57 kwargs['orientation'] = 'vertical'
58 return FlexContainer(*pargs, **kwargs)
58
59
60 def HBox(*pargs, **kwargs):
61 kwargs['orientation'] = 'horizontal'
62 return FlexContainer(*pargs, **kwargs)
59
63
60 class HBox(FlexContainer):
61 _view_name = Unicode('HBoxContainerView', sync=True)
62
64
63 ContainerWidget = DeprecatedClass(Container, 'ContainerWidget')
65 ContainerWidget = DeprecatedClass(Container, 'ContainerWidget')
64 PopupWidget = DeprecatedClass(Popup, 'PopupWidget')
66 PopupWidget = DeprecatedClass(Popup, 'PopupWidget')
65
67
General Comments 0
You need to be logged in to leave comments. Login now