Show More
@@ -19,7 +19,7 b' define([' | |||||
19 |
|
19 | |||
20 | render: function(){ |
|
20 | render: function(){ | |
21 | // Called when view is rendered. |
|
21 | // Called when view is rendered. | |
22 |
this.$el.addClass('widget-container') |
|
22 | this.$el.addClass('widget-container'); | |
23 | }, |
|
23 | }, | |
24 |
|
24 | |||
25 | update_children: function(old_list, new_list) { |
|
25 | update_children: function(old_list, new_list) { | |
@@ -45,6 +45,56 b' define([' | |||||
45 | }); |
|
45 | }); | |
46 | }, |
|
46 | }, | |
47 | }); |
|
47 | }); | |
|
48 | ||||
|
49 | ||||
|
50 | var FlexContainerView = ContainerView.extend({ | |||
|
51 | render: function(){ | |||
|
52 | FlexContainerView.__super__.render.apply(this); | |||
|
53 | this.model.on('change:flex', this._flex_changed, this); | |||
|
54 | this.model.on('change:pack', this._pack_changed, this); | |||
|
55 | this.model.on('change:align', this._align_changed, this); | |||
|
56 | this._flex_changed(); | |||
|
57 | this._pack_changed(); | |||
|
58 | this._align_changed(); | |||
|
59 | }, | |||
|
60 | ||||
|
61 | _flex_changed: function(){ | |||
|
62 | if (this.model.previous('flex')) { | |||
|
63 | this.$el.removeClass('box-flex' + this.model.previous('flex')); | |||
|
64 | } | |||
|
65 | this.$el.addClass('box-flex' + this.model.get('flex')); | |||
|
66 | }, | |||
|
67 | ||||
|
68 | _pack_changed: function(){ | |||
|
69 | if (this.model.previous('pack')) { | |||
|
70 | this.$el.removeClass(this.model.previous('pack')); | |||
|
71 | } | |||
|
72 | this.$el.addClass(this.model.get('pack')); | |||
|
73 | }, | |||
|
74 | ||||
|
75 | _align_changed: function(){ | |||
|
76 | if (this.model.previous('align')) { | |||
|
77 | this.$el.removeClass('align-' + this.model.previous('align')); | |||
|
78 | } | |||
|
79 | this.$el.addClass('align-' + this.model.get('align')); | |||
|
80 | }, | |||
|
81 | }); | |||
|
82 | ||||
|
83 | ||||
|
84 | var VBoxContainerView = FlexContainerView.extend({ | |||
|
85 | render: function(){ | |||
|
86 | this.$el.addClass('vbox'); | |||
|
87 | FlexContainerView.__super__.render.apply(this); | |||
|
88 | }, | |||
|
89 | }); | |||
|
90 | ||||
|
91 | ||||
|
92 | var HBoxContainerView = FlexContainerView.extend({ | |||
|
93 | render: function(){ | |||
|
94 | this.$el.addClass('hbox'); | |||
|
95 | FlexContainerView.__super__.render.apply(this); | |||
|
96 | }, | |||
|
97 | }); | |||
48 |
|
98 | |||
49 |
|
99 | |||
50 | var PopupView = widget.DOMWidgetView.extend({ |
|
100 | var PopupView = widget.DOMWidgetView.extend({ | |
@@ -279,5 +329,8 b' define([' | |||||
279 | return { |
|
329 | return { | |
280 | 'ContainerView': ContainerView, |
|
330 | 'ContainerView': ContainerView, | |
281 | 'PopupView': PopupView, |
|
331 | 'PopupView': PopupView, | |
|
332 | 'FlexContainerView': FlexContainerView, | |||
|
333 | 'VBoxContainerView': VBoxContainerView, | |||
|
334 | 'HBoxContainerView': HBoxContainerView, | |||
282 | }; |
|
335 | }; | |
283 | }); |
|
336 | }); |
@@ -2,7 +2,7 b' from .widget import Widget, DOMWidget, CallbackDispatcher' | |||||
2 |
|
2 | |||
3 | from .widget_bool import CheckboxWidget, ToggleButtonWidget |
|
3 | from .widget_bool import CheckboxWidget, ToggleButtonWidget | |
4 | from .widget_button import ButtonWidget |
|
4 | from .widget_button import ButtonWidget | |
5 | from .widget_container import ContainerWidget, PopupWidget |
|
5 | from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxContainerWidget, VBoxContainerWidget | |
6 | from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget |
|
6 | from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget | |
7 | from .widget_image import ImageWidget |
|
7 | from .widget_image import ImageWidget | |
8 | from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget |
|
8 | from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget |
@@ -7,7 +7,7 b' Represents a container that can be used to group other widgets.' | |||||
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 |
|
10 | from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum | |
11 |
|
11 | |||
12 | class ContainerWidget(DOMWidget): |
|
12 | class ContainerWidget(DOMWidget): | |
13 | _view_name = Unicode('ContainerView', sync=True) |
|
13 | _view_name = Unicode('ContainerView', sync=True) | |
@@ -32,3 +32,24 b' class PopupWidget(ContainerWidget):' | |||||
32 |
|
32 | |||
33 | description = Unicode(sync=True) |
|
33 | description = Unicode(sync=True) | |
34 | button_text = Unicode(sync=True) |
|
34 | button_text = Unicode(sync=True) | |
|
35 | ||||
|
36 | ||||
|
37 | class FlexContainerWidget(ContainerWidget): | |||
|
38 | _view_name = Unicode('FlexContainerView', sync=True) | |||
|
39 | flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") | |||
|
40 | def _flex_changed(self, name, old, new): | |||
|
41 | new = min(max(0, new), 2) | |||
|
42 | if self.flex != new: | |||
|
43 | self.flex = new | |||
|
44 | ||||
|
45 | _locations = ['start', 'center', 'end'] | |||
|
46 | pack = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) | |||
|
47 | align = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) | |||
|
48 | ||||
|
49 | ||||
|
50 | class VBoxContainerWidget(FlexContainerWidget): | |||
|
51 | _view_name = Unicode('VBoxContainerView', sync=True) | |||
|
52 | ||||
|
53 | ||||
|
54 | class HBoxContainerWidget(FlexContainerWidget): | |||
|
55 | _view_name = Unicode('HBoxContainerView', sync=True) |
General Comments 0
You need to be logged in to leave comments.
Login now