Skip to content

Commit 82d1a14

Browse files
committed
Merge pull request #305 from SylvainCorlay/box_style-fix
Box predefined styling was not updating correctly
2 parents 78a0347 + 3ddee09 commit 82d1a14

File tree

9 files changed

+55
-70
lines changed

9 files changed

+55
-70
lines changed

ipywidgets/static/widgets/js/widget.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ define(["./utils",
714714
});
715715
},
716716

717-
update_mapped_classes: function(class_map, trait_name, previous_trait_value, el) {
717+
update_mapped_classes: function(class_map, trait_name, el) {
718718
/**
719719
* Update the DOM classes applied to the widget based on a single
720720
* trait's value.
@@ -736,15 +736,10 @@ define(["./utils",
736736
* };
737737
* trait_name: string
738738
* Name of the trait to check the value of.
739-
* previous_trait_value: optional string, default ''
740-
* Last trait value
741739
* el: optional DOM element handle, defaults to this.$el
742740
* Element that the classes are applied to.
743741
*/
744-
var key = previous_trait_value;
745-
if (key === undefined) {
746-
key = this.model.previous(trait_name);
747-
}
742+
var key = this.model.previous(trait_name);
748743
var old_classes = class_map[key] ? class_map[key] : [];
749744
key = this.model.get(trait_name);
750745
var new_classes = class_map[key] ? class_map[key] : [];

ipywidgets/static/widgets/js/widget_bool.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,21 @@ define([
9191
that.handle_click();
9292
}));
9393
this.$el.attr("data-toggle", "tooltip");
94-
this.listenTo(this.model, 'change:button_style', function(model, value) {
95-
this.update_button_style();
96-
}, this);
97-
this.update_button_style('');
94+
this.listenTo(this.model, "change:button_style", this.update_button_style, this);
95+
this.update_button_style();
9896

9997
this.update(); // Set defaults.
10098
},
10199

102-
update_button_style: function(previous_trait_value) {
100+
update_button_style: function() {
103101
var class_map = {
104102
primary: ['btn-primary'],
105103
success: ['btn-success'],
106104
info: ['btn-info'],
107105
warning: ['btn-warning'],
108106
danger: ['btn-danger']
109107
};
110-
this.update_mapped_classes(class_map, 'button_style', previous_trait_value);
108+
this.update_mapped_classes(class_map, 'button_style');
111109
},
112110

113111
update : function(options){

ipywidgets/static/widgets/js/widget_box.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ define([
113113
}, this);
114114
this.listenTo(this.model, 'change:overflow_x', this.update_overflow_x, this);
115115
this.listenTo(this.model, 'change:overflow_y', this.update_overflow_y, this);
116-
this.listenTo(this.model, 'change:box_style', this.update_box_style, this);
116+
this.listenTo(this.model, "change:box_style", this.update_box_style, this);
117117
},
118118

119119
update_attr: function(name, value) { // TODO: Deprecated in 5.0
@@ -132,7 +132,7 @@ define([
132132
this.children_views.update(this.model.get('children'));
133133
this.update_overflow_x();
134134
this.update_overflow_y();
135-
this.update_box_style('');
135+
this.update_box_style();
136136
},
137137

138138
update_overflow_x: function() {
@@ -149,14 +149,14 @@ define([
149149
this.$box.css('overflow-y', this.model.get('overflow_y'));
150150
},
151151

152-
update_box_style: function(previous_trait_value) {
152+
update_box_style: function() {
153153
var class_map = {
154154
success: ['alert', 'alert-success'],
155155
info: ['alert', 'alert-info'],
156156
warning: ['alert', 'alert-warning'],
157157
danger: ['alert', 'alert-danger']
158158
};
159-
this.update_mapped_classes(class_map, 'box_style', previous_trait_value, this.$box[0]);
159+
this.update_mapped_classes(class_map, 'box_style', this.$box[0]);
160160
},
161161

162162
add_child_model: function(model) {

ipywidgets/static/widgets/js/widget_button.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ define([
1818
this.setElement($("<button />")
1919
.addClass('ipy-widget widget-button btn btn-default'));
2020
this.$el.attr("data-toggle", "tooltip");
21-
this.listenTo(this.model, 'change:button_style', function(model, value) {
22-
this.update_button_style();
23-
}, this);
24-
this.update_button_style('');
21+
this.listenTo(this.model, "change:button_style", this.update_button_style, this);
22+
this.update_button_style();
2523

2624
this.update(); // Set defaults.
2725
},
@@ -48,15 +46,15 @@ define([
4846
return ButtonView.__super__.update.apply(this);
4947
},
5048

51-
update_button_style: function(previous_trait_value) {
49+
update_button_style: function() {
5250
var class_map = {
5351
primary: ['btn-primary'],
5452
success: ['btn-success'],
5553
info: ['btn-info'],
5654
warning: ['btn-warning'],
5755
danger: ['btn-danger']
5856
};
59-
this.update_mapped_classes(class_map, 'button_style', previous_trait_value);
57+
this.update_mapped_classes(class_map, 'button_style');
6058
},
6159

6260
events: {

ipywidgets/static/widgets/js/widget_int.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,12 @@ define([
492492
this.update();
493493
this.updateDescription();
494494

495-
this.listenTo(this.model, 'change:bar_style', function(model, value) {
496-
this.update_bar_style();
497-
}, this);
498-
this.listenTo(this.model, 'change:description', function(sender, value) {
495+
this.listenTo(this.model, "change:bar_style", this.update_bar_style, this);
496+
this.listenTo(this.model, "change:description", function(sender, value) {
499497
this.updateDescription();
500498
}, this);
501499

502-
this.update_bar_style('');
500+
this.update_bar_style();
503501
},
504502

505503
updateDescription: function() {
@@ -548,14 +546,14 @@ define([
548546
return ProgressView.__super__.update.apply(this);
549547
},
550548

551-
update_bar_style: function(previous_trait_value) {
549+
update_bar_style: function() {
552550
var class_map = {
553551
success: ['progress-bar-success'],
554552
info: ['progress-bar-info'],
555553
warning: ['progress-bar-warning'],
556554
danger: ['progress-bar-danger']
557555
};
558-
this.update_mapped_classes(class_map, 'bar_style', previous_trait_value, this.$bar[0]);
556+
this.update_mapped_classes(class_map, 'bar_style', this.$bar[0]);
559557
},
560558

561559
update_attr: function(name, value) { // TODO: Deprecated in 5.0

ipywidgets/static/widgets/js/widget_selection.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ define([
4343
.addClass('dropdown-menu')
4444
.appendTo(this.$buttongroup);
4545

46-
this.listenTo(this.model, 'change:button_style', function(model, value) {
47-
this.update_button_style();
48-
}, this);
49-
this.update_button_style('');
46+
this.listenTo(this.model, "change:button_style", this.update_button_style, this);
47+
this.update_button_style();
5048

5149
// Set defaults.
5250
this.update();
@@ -108,16 +106,16 @@ define([
108106
return DropdownView.__super__.update.apply(this);
109107
},
110108

111-
update_button_style: function(previous_trait_value) {
109+
update_button_style: function() {
112110
var class_map = {
113111
primary: ['btn-primary'],
114112
success: ['btn-success'],
115113
info: ['btn-info'],
116114
warning: ['btn-warning'],
117115
danger: ['btn-danger']
118116
};
119-
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$droplabel[0]);
120-
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$dropbutton[0]);
117+
this.update_mapped_classes(class_map, 'button_style', this.$droplabel[0]);
118+
this.update_mapped_classes(class_map, 'button_style', this.$dropbutton[0]);
121119
},
122120

123121
update_attr: function(name, value) { // TODO: Deprecated in 5.0
@@ -278,10 +276,8 @@ define([
278276
.addClass('btn-group')
279277
.appendTo(this.$el);
280278

281-
this.listenTo(this.model, 'change:button_style', function(model, value) {
282-
this.update_button_style();
283-
}, this);
284-
this.update_button_style('');
279+
this.listenTo(this.model, 'change:button_style', this.update_button_style, this);
280+
this.update_button_style();
285281
this.update();
286282
},
287283

@@ -391,15 +387,15 @@ define([
391387
}
392388
},
393389

394-
update_button_style: function(previous_trait_value) {
390+
update_button_style: function() {
395391
var class_map = {
396392
primary: ['btn-primary'],
397393
success: ['btn-success'],
398394
info: ['btn-info'],
399395
warning: ['btn-warning'],
400396
danger: ['btn-danger']
401397
};
402-
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$buttongroup.find('button')[0]);
398+
this.update_mapped_classes(class_map, 'button_style', this.$buttongroup.find('button')[0]);
403399
},
404400

405401
handle_click: function (e) {
@@ -416,7 +412,7 @@ define([
416412

417413

418414
var SelectView = widget.DOMWidgetView.extend({
419-
render : function() {
415+
render: function() {
420416
/**
421417
* Called when view is rendered.
422418
*/
@@ -434,7 +430,7 @@ define([
434430
this.update();
435431
},
436432

437-
update : function(options) {
433+
update: function(options) {
438434
/**
439435
* Update the contents of this view
440436
*

ipywidgets/widgets/widget_bool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ class ToggleButton(_Bool):
5757
icon = Unicode('', help= "Font-awesome icon.", sync=True)
5858

5959
button_style = CaselessStrEnum(
60-
values=['primary', 'success', 'info', 'warning', 'danger', ''],
61-
default_value='', allow_none=True, sync=True, help="""Use a
62-
predefined styling for the button.""")
60+
values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='',
61+
sync=True, help="""Use a predefined styling for the button.""")
6362

6463

6564
@register('Jupyter.Valid')

ipywidgets/widgets/widget_box.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ class Box(DOMWidget):
3434
happens to content that is too large for the rendered region.""")
3535

3636
box_style = CaselessStrEnum(
37-
values=['success', 'info', 'warning', 'danger', ''],
38-
default_value='', allow_none=True, sync=True, help="""Use a
39-
predefined styling for the box.""")
37+
values=['success', 'info', 'warning', 'danger', ''], default_value='',
38+
sync=True, help="""Use a predefined styling for the box.""")
4039

4140
def __init__(self, children = (), **kwargs):
4241
kwargs['children'] = children

ipywidgets/widgets/widget_button.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
@register('Jupyter.Button')
1616
class Button(DOMWidget):
1717
"""Button widget.
18-
This widget has an `on_click` method that allows you to listen for the
19-
user clicking on the button. The click event itself is stateless.
2018
21-
Parameters
22-
----------
23-
description : str
24-
description displayed next to the button
25-
tooltip: str
26-
tooltip caption of the toggle button
27-
icon: str
28-
font-awesome icon name
19+
This widget has an `on_click` method that allows you to listen for the
20+
user clicking on the button. The click event itself is stateless.
21+
22+
Parameters
23+
----------
24+
description: str
25+
description displayed next to the button
26+
tooltip: str
27+
tooltip caption of the toggle button
28+
icon: str
29+
font-awesome icon name
2930
"""
3031
_view_name = Unicode('ButtonView', sync=True)
3132

3233
# Keys
3334
description = Unicode('', help="Button label.", sync=True)
3435
tooltip = Unicode(help="Tooltip caption of the button.", sync=True)
3536
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
36-
icon = Unicode('', help= "Font-awesome icon.", sync=True)
37+
icon = Unicode('', help="Font-awesome icon.", sync=True)
3738

3839
button_style = CaselessStrEnum(
39-
values=['primary', 'success', 'info', 'warning', 'danger', ''],
40-
default_value='', allow_none=True, sync=True, help="""Use a
41-
predefined styling for the button.""")
40+
values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='',
41+
sync=True, help="""Use a predefined styling for the button.""")
4242

4343
def __init__(self, **kwargs):
4444
"""Constructor"""
@@ -49,13 +49,14 @@ def __init__(self, **kwargs):
4949
def on_click(self, callback, remove=False):
5050
"""Register a callback to execute when the button is clicked.
5151
52-
The callback will be called with one argument,
53-
the clicked button widget instance.
52+
The callback will be called with one argument, the clicked button
53+
widget instance.
5454
5555
Parameters
5656
----------
57-
remove : bool (optional)
58-
Set to true to remove the callback from the list of callbacks."""
57+
remove: bool (optional)
58+
Set to true to remove the callback from the list of callbacks.
59+
"""
5960
self._click_handlers.register_callback(callback, remove=remove)
6061

6162
def _handle_button_msg(self, _, content, buffers):
@@ -64,6 +65,7 @@ def _handle_button_msg(self, _, content, buffers):
6465
Parameters
6566
----------
6667
content: dict
67-
Content of the msg."""
68+
Content of the msg.
69+
"""
6870
if content.get('event', '') == 'click':
6971
self._click_handlers(self)

0 commit comments

Comments
 (0)