Skip to content

Commit b78675e

Browse files
committed
Merge pull request #1 from ipython/master
Update from ipython/ipython:master
2 parents d4cfaa6 + 08c8629 commit b78675e

File tree

11 files changed

+59
-34
lines changed

11 files changed

+59
-34
lines changed

IPython/html/static/style/style.min.css

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPython/html/static/widgets/js/widget_bool.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ define([
5959
this.$checkbox.prop('checked', this.model.get('value'));
6060

6161
if (options === undefined || options.updated_view != this) {
62-
var disabled = this.model.get('disabled');
63-
this.$checkbox.prop('disabled', disabled);
62+
this.$checkbox.prop("disabled", this.model.get("disabled"));
6463

65-
var description = this.model.get('description');
64+
var description = this.model.get("description");
6665
if (description.trim().length === 0) {
6766
this.$label.hide();
6867
} else {
@@ -113,7 +112,7 @@ define([
113112
/**
114113
* Update the contents of this view
115114
*
116-
* Called when the model is changed. The model may have been
115+
* Called when the model is changed. The model may have been
117116
* changed by another view or by a state update from the back-end.
118117
*/
119118
if (this.model.get('value')) {
@@ -123,16 +122,16 @@ define([
123122
}
124123

125124
if (options === undefined || options.updated_view != this) {
126-
127-
var disabled = this.model.get('disabled');
128-
this.$el.prop('disabled', disabled);
129-
130-
var description = this.model.get('description');
125+
this.$el.prop("disabled", this.model.get("disabled"));
131126
this.$el.attr("title", this.model.get("tooltip"));
132-
if (description.trim().length === 0) {
127+
128+
var description = this.model.get("description");
129+
var icon = this.model.get("icon");
130+
if (description.trim().length === 0 && icon.trim().length ===0) {
133131
this.$el.html(" "); // Preserve button height
134132
} else {
135133
this.$el.text(description);
134+
$('<i class="fa"></i>').prependTo(this.$el).addClass(icon);
136135
}
137136
}
138137
return ToggleButtonView.__super__.update.apply(this);

IPython/html/static/widgets/js/widget_button.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ define([
2727
/**
2828
* Update the contents of this view
2929
*
30-
* Called when the model is changed. The model may have been
30+
* Called when the model is changed. The model may have been
3131
* changed by another view or by a state update from the back-end.
3232
*/
33-
var description = this.model.get('description');
33+
this.$el.prop("disabled", this.model.get("disabled"));
3434
this.$el.attr("title", this.model.get("tooltip"));
35-
if (description.length === 0) {
35+
36+
var description = this.model.get("description");
37+
var icon = this.model.get("icon");
38+
if (description.trim().length === 0 && icon.trim().length ===0) {
3639
this.$el.html("&nbsp;"); // Preserve button height
3740
} else {
3841
this.$el.text(description);
39-
}
40-
41-
if (this.model.get('disabled')) {
42-
this.$el.attr('disabled','disabled');
43-
} else {
44-
this.$el.removeAttr('disabled');
42+
$('<i class="fa"></i>').prependTo(this.$el).addClass(icon);
4543
}
4644

4745
return ButtonView.__super__.update.apply(this);

IPython/html/static/widgets/js/widget_selection.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,34 +307,44 @@ define([
307307
if (options === undefined || options.updated_view != this) {
308308
// Add missing items to the DOM.
309309
var items = this.model.get('_options_labels');
310+
var icons = this.model.get('icons');
311+
var previous_icons = this.model.previous('icons') || [];
310312
var disabled = this.model.get('disabled');
311313
var that = this;
312314
var item_html;
313315
_.each(items, function(item, index) {
314-
if (item.trim().length === 0) {
316+
if (item.trim().length === 0 && (!icons[index] ||
317+
icons[index].trim().length === 0)) {
315318
item_html = "&nbsp;";
316319
} else {
317320
item_html = utils.escape_html(item);
318321
}
319322
var item_query = '[data-value="' + encodeURIComponent(item) + '"]';
320323
var $item_element = that.$buttongroup.find(item_query);
324+
var $icon_element = $item_element.find('.fa');
321325
if (!$item_element.length) {
322326
$item_element = $('<button/>')
323327
.attr('type', 'button')
324328
.addClass('btn btn-default')
325329
.html(item_html)
326330
.appendTo(that.$buttongroup)
327331
.attr('data-value', encodeURIComponent(item))
332+
.attr('data-toggle', 'tooltip')
328333
.attr('value', item)
329334
.on('click', $.proxy(that.handle_click, that));
330335
that.update_style_traits($item_element);
336+
$icon_element = $('<i class="fa"></i>').prependTo($item_element);
331337
}
332338
if (that.model.get('selected_label') == item) {
333339
$item_element.addClass('active');
334340
} else {
335341
$item_element.removeClass('active');
336342
}
337-
$item_element.prop('disabled', disabled);
343+
$item_element.prop('disabled', disabled);
344+
$item_element.attr('title', that.model.get('tooltips')[index]);
345+
$icon_element
346+
.removeClass(previous_icons[index])
347+
.addClass(icons[index]);
338348
});
339349

340350
// Remove items that no longer exist.

IPython/html/static/widgets/less/widgets.less

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@
271271

272272
label {
273273
margin-top: 0px;
274+
margin-left: 20px;
274275
}
275276
}
276-
277-
.widget-radio {
278-
margin-left: 20px;
279-
}

IPython/html/tests/widgets/widget_bool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ casper.notebook_test(function () {
4949
'Toggle button exists.');
5050

5151
this.test.assert(this.cell_element_function(bool_index,
52-
widget_togglebutton_selector, 'html')=="Title",
52+
widget_togglebutton_selector, 'html')=='<i class="fa"></i>Title',
5353
'Toggle button labeled correctly.');
5454

5555
this.test.assert(this.cell_element_function(bool_index,

IPython/html/tests/widgets/widget_button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ casper.notebook_test(function () {
2929
'Widget button exists.');
3030

3131
this.test.assert(this.cell_element_function(button_index,
32-
widget_button_selector, 'html')=='Title',
32+
widget_button_selector, 'html')=='<i class="fa"></i>Title',
3333
'Set button description.');
3434

3535
this.cell_element_function(button_index,

IPython/html/widgets/widget_bool.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ class ToggleButton(_Bool):
5555
value of the toggle button: True-pressed, False-unpressed
5656
description : str
5757
description displayed next to the button
58+
tooltip: str
59+
tooltip caption of the toggle button
60+
icon: str
61+
font-awesome icon name
5862
"""
5963

6064
_view_name = Unicode('ToggleButtonView', sync=True)
6165
tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True)
66+
icon = Unicode('', help= "Font-awesome icon.", sync=True)
6267

6368
button_style = CaselessStrEnum(
6469
values=['primary', 'success', 'info', 'warning', 'danger', ''],

IPython/html/widgets/widget_button.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,25 @@
2424
@register('IPython.Button')
2525
class Button(DOMWidget):
2626
"""Button widget.
27+
This widget has an `on_click` method that allows you to listen for the
28+
user clicking on the button. The click event itself is stateless.
2729
28-
This widget has an `on_click` method that allows you to listen for the
29-
user clicking on the button. The click event itself is stateless."""
30+
Parameters
31+
----------
32+
description : str
33+
description displayed next to the button
34+
tooltip: str
35+
tooltip caption of the toggle button
36+
icon: str
37+
font-awesome icon name
38+
"""
3039
_view_name = Unicode('ButtonView', sync=True)
3140

3241
# Keys
3342
description = Unicode('', help="Button label.", sync=True)
3443
tooltip = Unicode(help="Tooltip caption of the button.", sync=True)
3544
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
45+
icon = Unicode('', help= "Font-awesome icon.", sync=True)
3646

3747
button_style = CaselessStrEnum(
3848
values=['primary', 'success', 'info', 'warning', 'danger', ''],

IPython/html/widgets/widget_selection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from .widget import DOMWidget, register
2121
from IPython.utils.traitlets import (
22-
Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple
22+
Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List
2323
)
2424
from IPython.utils.py3compat import unicode_type
2525
from IPython.utils.warn import DeprecatedClass
@@ -32,6 +32,12 @@ class _Selection(DOMWidget):
3232
3333
``options`` can be specified as a list or dict. If given as a list,
3434
it will be transformed to a dict of the form ``{str(value):value}``.
35+
36+
When programmatically setting the value, a reverse lookup is performed
37+
among the options to set the value of ``selected_label`` accordingly. The
38+
reverse lookup uses the equality operator by default, but an other
39+
predicate may be provided via the ``equals`` argument. For example, when
40+
dealing with numpy arrays, one may set equals=np.array_equal.
3541
"""
3642

3743
value = Any(help="Selected value")
@@ -194,6 +200,8 @@ class ToggleButtons(_Selection):
194200
"""Group of toggle buttons that represent an enumeration. Only one toggle
195201
button can be toggled at any point in time."""
196202
_view_name = Unicode('ToggleButtonsView', sync=True)
203+
tooltips = List(Unicode(), sync=True)
204+
icons = List(Unicode(), sync=True)
197205

198206
button_style = CaselessStrEnum(
199207
values=['primary', 'success', 'info', 'warning', 'danger', ''],

0 commit comments

Comments
 (0)