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