Skip to content

Commit f4e4bc6

Browse files
committed
Iterate on gridbox
1 parent 4fbe473 commit f4e4bc6

18 files changed

+15006
-1008
lines changed

docs/source/examples/Widget Styling.ipynb

Lines changed: 14976 additions & 869 deletions
Large diffs are not rendered by default.
239 Bytes
Loading
246 Bytes
Loading
Loading
Loading
Loading
Loading
249 Bytes
Loading
2.86 KB
Loading
2.86 KB
Loading
2.93 KB
Loading
243 Bytes
Loading

ipywidgets/widgets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
from .widget_controller import Controller
2424
from .interaction import interact, interactive, fixed, interact_manual, interactive_output
2525
from .widget_link import jslink, jsdlink
26-
from .widget_layout import Layout, GridLayout, GridItemLayout
26+
from .widget_layout import Layout
2727
from .widget_style import Style

ipywidgets/widgets/domwidget.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from traitlets import Unicode
77
from .widget import Widget, widget_serialization
88
from .trait_types import InstanceDict, TypedTuple
9-
from .widget_layout import Layout, GridLayout, GridItemLayout
9+
from .widget_layout import Layout
1010
from .widget_style import Style
1111

1212

@@ -16,8 +16,6 @@ class DOMWidget(Widget):
1616
_model_name = Unicode('DOMWidgetModel').tag(sync=True)
1717
_dom_classes = TypedTuple(trait=Unicode(), help="CSS classes applied to widget DOM element").tag(sync=True)
1818
layout = InstanceDict(Layout).tag(sync=True, **widget_serialization)
19-
grid_layout = InstanceDict(GridLayout).tag(sync=True, **widget_serialization)
20-
grid_item_layout = InstanceDict(GridItemLayout).tag(sync=True, **widget_serialization)
2119

2220
def add_class(self, className):
2321
"""

ipywidgets/widgets/widget_box.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class HBox(Box):
108108
_model_name = Unicode('HBoxModel').tag(sync=True)
109109
_view_name = Unicode('HBoxView').tag(sync=True)
110110

111+
111112
@register
112113
class GridBox(Box):
113114
_model_name = Unicode('GridBoxModel').tag(sync=True)

ipywidgets/widgets/widget_layout.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class Layout(Widget):
6161
visibility = CaselessStrEnum(['visible', 'hidden']+CSS_PROPERTIES, allow_none=True, help="The visibility CSS attribute.").tag(sync=True)
6262
width = Unicode(None, allow_none=True, help="The width CSS attribute.").tag(sync=True)
6363

64+
grid_auto_columns = Unicode(None, allow_none=True, help="The grid-auto-columns CSS attribute.").tag(sync=True)
65+
grid_auto_flow = CaselessStrEnum(['column','row','row dense','column dense']+ CSS_PROPERTIES, allow_none=True, help="The grid-auto-flow CSS attribute.").tag(sync=True)
66+
grid_auto_rows = Unicode(None, allow_none=True, help="The grid-auto-rows CSS attribute.").tag(sync=True)
67+
grid_gap = Unicode(None, allow_none=True, help="The grid-gap CSS attribute.").tag(sync=True)
68+
grid_template = Unicode(None, allow_none=True, help="The grid-template CSS attribute.").tag(sync=True)
69+
grid_row = Unicode(None, allow_none=True, help="The grid-row CSS attribute.").tag(sync=True)
70+
grid_column = Unicode(None, allow_none=True, help="The grid-column CSS attribute.").tag(sync=True)
71+
6472

6573
class LayoutTraitType(Instance):
6674

@@ -71,34 +79,3 @@ def validate(self, obj, value):
7179
return super(LayoutTraitType, self).validate(obj, self.klass(**value))
7280
else:
7381
return super(LayoutTraitType, self).validate(obj, value)
74-
75-
@register
76-
class GridLayout(Widget):
77-
78-
_view_name = Unicode('GridLayoutView').tag(sync=True)
79-
_view_module = Unicode('@jupyter-widgets/base').tag(sync=True)
80-
_view_module_version = Unicode(__jupyter_widgets_base_version__).tag(sync=True)
81-
_model_name = Unicode('GridLayoutModel').tag(sync=True)
82-
83-
# Keys
84-
auto_columns = Unicode(None, allow_none=True, help="The grid-auto-columns CSS attribute.").tag(sync=True)
85-
auto_flow = CaselessStrEnum(['column','row','row dense','column dense']+ CSS_PROPERTIES, allow_none=True, help="The grid-auto-flow CSS attribute.").tag(sync=True)
86-
auto_rows = Unicode(None, allow_none=True, help="The grid-auto-rows CSS attribute.").tag(sync=True)
87-
row_gap = Unicode(None, allow_none=True, help="The grid-row-gap CSS attribute.").tag(sync=True)
88-
column_gap = Unicode(None, allow_none=True, help="The grid-column-gap CSS attribute.").tag(sync=True)
89-
template_areas = Unicode(None, allow_none=True, help="The grid-template-areas CSS attribute.").tag(sync=True)
90-
template_columns = Unicode(None, allow_none=True, help="The grid-template-columns CSS attribute.").tag(sync=True)
91-
template_rows = Unicode(None, allow_none=True, help="The grid-template-rows CSS attribute.").tag(sync=True)
92-
93-
94-
@register
95-
class GridItemLayout(Widget):
96-
_view_name = Unicode('GridItemLayoutView').tag(sync=True)
97-
_view_module = Unicode('@jupyter-widgets/base').tag(sync=True)
98-
_view_module_version = Unicode(__jupyter_widgets_base_version__).tag(sync=True)
99-
_model_name = Unicode('GridItemLayoutModel').tag(sync=True)
100-
101-
row_start = Unicode(None, allow_none=True, help="The row-start CSS attribute.").tag(sync=True)
102-
column_start = Unicode(None, allow_none=True, help="The grid-column-start CSS attribute.").tag(sync=True)
103-
row_end = Unicode(None, allow_none=True, help="The grid-row-end CSS attribute.").tag(sync=True)
104-
column_end = Unicode(None, allow_none=True, help="The grid-column-end CSS attribute.").tag(sync=True)

packages/base/src/widget.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,6 @@ class DOMWidgetModel extends WidgetModel {
566566
static serializers: ISerializers = {
567567
...WidgetModel.serializers,
568568
layout: {deserialize: unpack_models},
569-
grid_layout: {deserialize: unpack_models},
570-
grid_item_layout: {deserialize: unpack_models},
571569
style: {deserialize: unpack_models},
572570
};
573571

@@ -751,17 +749,7 @@ class DOMWidgetView extends WidgetView {
751749

752750
this.layoutPromise = Promise.resolve();
753751
this.listenTo(this.model, 'change:layout', (model, value) => {
754-
this.setLayout('layoutPromise', value, model.previous('layout'));
755-
});
756-
757-
this.gridLayoutPromise = Promise.resolve();
758-
this.listenTo(this.model, 'change:grid_layout', (model, value) => {
759-
this.setLayout('gridLayoutPromise', value, model.previous('grid_layout'));
760-
});
761-
762-
this.gridItemLayoutPromise = Promise.resolve();
763-
this.listenTo(this.model, 'change:grid_item_layout', (model, value) => {
764-
this.setLayout('gridItemLayoutPromise', value, model.previous('grid_item_layout'));
752+
this.setLayout(value, model.previous('layout'));
765753
});
766754

767755
this.stylePromise = Promise.resolve();
@@ -771,9 +759,7 @@ class DOMWidgetView extends WidgetView {
771759

772760
this.displayed.then(() => {
773761
this.update_classes([], this.model.get('_dom_classes'));
774-
this.setLayout('layoutPromise', this.model.get('layout'));
775-
this.setLayout('gridLayoutPromise', this.model.get('grid_layout'));
776-
this.setLayout('gridItemLayoutPromise', this.model.get('grid_item_layout'));
762+
this.setLayout(this.model.get('layout'));
777763
this.setStyle(this.model.get('style'));
778764
});
779765

@@ -783,9 +769,9 @@ class DOMWidgetView extends WidgetView {
783769
});
784770
}
785771

786-
setLayout(layoutAttrName, layout, oldLayout?) {
772+
setLayout(layout, oldLayout?) {
787773
if (layout) {
788-
this[layoutAttrName] = this[layoutAttrName].then((oldLayoutView) => {
774+
this.layoutPromise = this.layoutPromise.then((oldLayoutView) => {
789775
if (oldLayoutView) {
790776
oldLayoutView.unlayout();
791777
this.stopListening(oldLayoutView.model);
@@ -932,7 +918,5 @@ class DOMWidgetView extends WidgetView {
932918
'$el': any;
933919
pWidget: Widget;
934920
layoutPromise: Promise<any>;
935-
gridLayoutPromise: Promise<any>;
936-
gridItemLayoutPromise: Promise<any>;
937921
stylePromise: Promise<any>;
938922
}

packages/base/src/widget_layout.ts

Lines changed: 15 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,20 @@ let css_properties = {
3838
right: null,
3939
top: null,
4040
visibility: null,
41-
width: null
41+
width: null,
42+
43+
// container
44+
grid_auto_columns: null,
45+
grid_auto_flow: null,
46+
grid_auto_rows: null,
47+
grid_gap: null,
48+
grid_template: null,
49+
50+
// items
51+
grid_row: null,
52+
grid_column: null
4253
};
4354

44-
let grid_css_properties = {
45-
auto_columns: null,
46-
auto_flow: null,
47-
auto_rows: null,
48-
row_gap: null,
49-
column_gap: null,
50-
template_areas: null,
51-
template_columns: null,
52-
template_rows: null
53-
};
54-
55-
let grid_item_css_properties = {
56-
row_start: null,
57-
column_start: null,
58-
row_end: null,
59-
column_end: null
60-
}
61-
62-
6355
export
6456
class LayoutModel extends WidgetModel {
6557
defaults() {
@@ -72,19 +64,14 @@ class LayoutModel extends WidgetModel {
7264

7365
export
7466
class LayoutView extends WidgetView {
75-
constructor(options?: Backbone.ViewOptions<LayoutModel> & {options?: any}) {
76-
super(options);
77-
}
7867
/**
7968
* Public constructor
8069
*/
8170
initialize(parameters) {
8271
this._traitNames = [];
8372
super.initialize(parameters);
84-
// Allowing override of default css_properties
85-
const {options: {css_props = css_properties}} = parameters;
8673
// Register the traits that live on the Python side
87-
for (let key of Object.keys(css_props)) {
74+
for (let key of Object.keys(css_properties)) {
8875
this.registerTrait(key);
8976
}
9077
}
@@ -111,7 +98,7 @@ class LayoutView extends WidgetView {
11198
* @return css property name
11299
*/
113100
css_name(trait: string): string {
114-
return trait.replace(new RegExp('_', 'g'), '-');
101+
return trait.replace('_', '-');
115102
}
116103

117104
/**
@@ -145,61 +132,5 @@ class LayoutView extends WidgetView {
145132
}, this);
146133
}
147134

148-
protected _traitNames: string[];
149-
}
150-
151-
export
152-
class GridLayoutModel extends WidgetModel {
153-
defaults() {
154-
return assign(super.defaults(), {
155-
_model_name: 'GridLayoutModel',
156-
_view_name: 'GridLayoutView'
157-
}, grid_css_properties);
158-
}
159-
}
160-
161-
export
162-
class GridLayoutView extends LayoutView {
163-
/**
164-
* Public constructor
165-
*/
166-
initialize(parameters) {
167-
const options = {...parameters.options, css_props: grid_css_properties};
168-
super.initialize({...parameters, options});
169-
}
170-
171-
/**
172-
* Get the the name of the css property from the trait name
173-
* @param model attribute name
174-
* @return css property name
175-
*/
176-
css_name(trait: string): string {
177-
return `grid-${trait.replace(new RegExp('_', 'g'), '-')}`;
178-
}
179-
}
180-
181-
182-
export
183-
class GridItemLayoutModel extends WidgetModel {
184-
defaults() {
185-
return assign(super.defaults(), {
186-
_model_name: 'GridItemLayoutModel',
187-
_view_name: 'GridItemLayoutView'
188-
}, grid_item_css_properties);
189-
}
190-
}
191-
192-
export
193-
class GridItemLayoutView extends LayoutView {
194-
/**
195-
* Public constructor
196-
*/
197-
initialize(parameters) {
198-
const options = {...parameters.options, css_props: grid_item_css_properties};
199-
super.initialize({...parameters, options});
200-
}
201-
202-
css_name(trait: string): string {
203-
return `grid-${trait.replace(new RegExp('_', 'g'), '-')}`;
204-
}
135+
private _traitNames: string[];
205136
}

0 commit comments

Comments
 (0)