From ae55f08db3d4d5cd34626c7773b066e910818320 2015-02-11 02:36:50 From: Sylvain Corlay Date: 2015-02-11 02:36:50 Subject: [PATCH] font awesome icon --- diff --git a/IPython/html/static/widgets/js/widget_bool.js b/IPython/html/static/widgets/js/widget_bool.js index 0234054..27e4928 100644 --- a/IPython/html/static/widgets/js/widget_bool.js +++ b/IPython/html/static/widgets/js/widget_bool.js @@ -129,10 +129,11 @@ define([ var description = this.model.get('description'); this.$el.attr("title", this.model.get("tooltip")); - if (description.trim().length === 0) { + this.$el.text(description); + var icon = this.model.get("icon"); + $('').prependTo(this.$el).addClass(icon); + if (description.trim().length === 0 && icon.trim().length ===0) { this.$el.html(" "); // Preserve button height - } else { - this.$el.text(description); } } return ToggleButtonView.__super__.update.apply(this); diff --git a/IPython/html/static/widgets/js/widget_button.js b/IPython/html/static/widgets/js/widget_button.js index c476581..cc55f47 100644 --- a/IPython/html/static/widgets/js/widget_button.js +++ b/IPython/html/static/widgets/js/widget_button.js @@ -32,12 +32,12 @@ define([ */ var description = this.model.get('description'); this.$el.attr("title", this.model.get("tooltip")); - if (description.length === 0) { + this.$el.text(description); + var icon = this.model.get("icon"); + $('').prependTo(this.$el).addClass(icon); + if (description.trim().length === 0 && icon.trim().length ===0) { this.$el.html(" "); // Preserve button height - } else { - this.$el.text(description); } - if (this.model.get('disabled')) { this.$el.attr('disabled','disabled'); } else { diff --git a/IPython/html/tests/widgets/widget_bool.js b/IPython/html/tests/widgets/widget_bool.js index 1d3ec62..556031c 100644 --- a/IPython/html/tests/widgets/widget_bool.js +++ b/IPython/html/tests/widgets/widget_bool.js @@ -49,7 +49,7 @@ casper.notebook_test(function () { 'Toggle button exists.'); this.test.assert(this.cell_element_function(bool_index, - widget_togglebutton_selector, 'html')=="Title", + widget_togglebutton_selector, 'html')=='Title', 'Toggle button labeled correctly.'); this.test.assert(this.cell_element_function(bool_index, diff --git a/IPython/html/tests/widgets/widget_button.js b/IPython/html/tests/widgets/widget_button.js index e98da48..97ea5ee 100644 --- a/IPython/html/tests/widgets/widget_button.js +++ b/IPython/html/tests/widgets/widget_button.js @@ -29,7 +29,7 @@ casper.notebook_test(function () { 'Widget button exists.'); this.test.assert(this.cell_element_function(button_index, - widget_button_selector, 'html')=='Title', + widget_button_selector, 'html')=='Title', 'Set button description.'); this.cell_element_function(button_index, diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index a6f1ff5..976c721 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -55,10 +55,15 @@ class ToggleButton(_Bool): value of the toggle button: True-pressed, False-unpressed description : str description displayed next to the button + tooltip: str + tooltip caption of the toggle button + icon: str + font-awesome icon name """ _view_name = Unicode('ToggleButtonView', sync=True) tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True) + icon = Unicode('', help= "Font-awesome icon.", sync=True) button_style = CaselessStrEnum( values=['primary', 'success', 'info', 'warning', 'danger', ''], diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index e91f3d2..4d5549c 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -24,15 +24,25 @@ from IPython.utils.warn import DeprecatedClass @register('IPython.Button') class Button(DOMWidget): """Button widget. + This widget has an `on_click` method that allows you to listen for the + user clicking on the button. The click event itself is stateless. - This widget has an `on_click` method that allows you to listen for the - user clicking on the button. The click event itself is stateless.""" + Parameters + ---------- + description : str + description displayed next to the button + tooltip: str + tooltip caption of the toggle button + icon: str + font-awesome icon name + """ _view_name = Unicode('ButtonView', sync=True) # Keys description = Unicode('', help="Button label.", sync=True) tooltip = Unicode(help="Tooltip caption of the button.", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) + icon = Unicode('', help= "Font-awesome icon.", sync=True) button_style = CaselessStrEnum( values=['primary', 'success', 'info', 'warning', 'danger', ''],