Show More
@@ -59,10 +59,9 b' define([' | |||||
59 | this.$checkbox.prop('checked', this.model.get('value')); |
|
59 | this.$checkbox.prop('checked', this.model.get('value')); | |
60 |
|
60 | |||
61 | if (options === undefined || options.updated_view != this) { |
|
61 | if (options === undefined || options.updated_view != this) { | |
62 |
|
|
62 | this.$checkbox.prop("disabled", this.model.get("disabled")); | |
63 | this.$checkbox.prop('disabled', disabled); |
|
|||
64 |
|
63 | |||
65 |
var description = this.model.get( |
|
64 | var description = this.model.get("description"); | |
66 | if (description.trim().length === 0) { |
|
65 | if (description.trim().length === 0) { | |
67 | this.$label.hide(); |
|
66 | this.$label.hide(); | |
68 | } else { |
|
67 | } else { | |
@@ -113,7 +112,7 b' define([' | |||||
113 | /** |
|
112 | /** | |
114 | * Update the contents of this view |
|
113 | * Update the contents of this view | |
115 | * |
|
114 | * | |
116 |
* Called when the model is changed. |
|
115 | * Called when the model is changed. The model may have been | |
117 | * changed by another view or by a state update from the back-end. |
|
116 | * changed by another view or by a state update from the back-end. | |
118 | */ |
|
117 | */ | |
119 | if (this.model.get('value')) { |
|
118 | if (this.model.get('value')) { | |
@@ -123,16 +122,16 b' define([' | |||||
123 | } |
|
122 | } | |
124 |
|
123 | |||
125 | if (options === undefined || options.updated_view != this) { |
|
124 | if (options === undefined || options.updated_view != this) { | |
126 |
|
125 | this.$el.prop("disabled", this.model.get("disabled")); | ||
127 | var disabled = this.model.get('disabled'); |
|
|||
128 | this.$el.prop('disabled', disabled); |
|
|||
129 |
|
||||
130 | var description = this.model.get('description'); |
|
|||
131 | this.$el.attr("title", this.model.get("tooltip")); |
|
126 | 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) { | |||
133 | this.$el.html(" "); // Preserve button height |
|
131 | this.$el.html(" "); // Preserve button height | |
134 | } else { |
|
132 | } else { | |
135 | this.$el.text(description); |
|
133 | this.$el.text(description); | |
|
134 | $('<i class="fa"></i>').prependTo(this.$el).addClass(icon); | |||
136 | } |
|
135 | } | |
137 | } |
|
136 | } | |
138 | return ToggleButtonView.__super__.update.apply(this); |
|
137 | return ToggleButtonView.__super__.update.apply(this); |
@@ -27,21 +27,19 b' define([' | |||||
27 | /** |
|
27 | /** | |
28 | * Update the contents of this view |
|
28 | * Update the contents of this view | |
29 | * |
|
29 | * | |
30 |
* Called when the model is changed. |
|
30 | * Called when the model is changed. The model may have been | |
31 | * changed by another view or by a state update from the back-end. |
|
31 | * changed by another view or by a state update from the back-end. | |
32 | */ |
|
32 | */ | |
33 | var description = this.model.get('description'); |
|
33 | this.$el.prop("disabled", this.model.get("disabled")); | |
34 | this.$el.attr("title", this.model.get("tooltip")); |
|
34 | 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) { | |||
36 | this.$el.html(" "); // Preserve button height |
|
39 | this.$el.html(" "); // Preserve button height | |
37 | } else { |
|
40 | } else { | |
38 | this.$el.text(description); |
|
41 | this.$el.text(description); | |
39 | } |
|
42 | $('<i class="fa"></i>').prependTo(this.$el).addClass(icon); | |
40 |
|
||||
41 | if (this.model.get('disabled')) { |
|
|||
42 | this.$el.attr('disabled','disabled'); |
|
|||
43 | } else { |
|
|||
44 | this.$el.removeAttr('disabled'); |
|
|||
45 | } |
|
43 | } | |
46 |
|
44 | |||
47 | return ButtonView.__super__.update.apply(this); |
|
45 | return ButtonView.__super__.update.apply(this); |
@@ -307,17 +307,21 b' define([' | |||||
307 | if (options === undefined || options.updated_view != this) { |
|
307 | if (options === undefined || options.updated_view != this) { | |
308 | // Add missing items to the DOM. |
|
308 | // Add missing items to the DOM. | |
309 | var items = this.model.get('_options_labels'); |
|
309 | var items = this.model.get('_options_labels'); | |
|
310 | var icons = this.model.get('icons'); | |||
|
311 | var previous_icons = this.model.previous('icons') || []; | |||
310 | var disabled = this.model.get('disabled'); |
|
312 | var disabled = this.model.get('disabled'); | |
311 | var that = this; |
|
313 | var that = this; | |
312 | var item_html; |
|
314 | var item_html; | |
313 | _.each(items, function(item, index) { |
|
315 | _.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)) { | |||
315 | item_html = " "; |
|
318 | item_html = " "; | |
316 | } else { |
|
319 | } else { | |
317 | item_html = utils.escape_html(item); |
|
320 | item_html = utils.escape_html(item); | |
318 | } |
|
321 | } | |
319 | var item_query = '[data-value="' + encodeURIComponent(item) + '"]'; |
|
322 | var item_query = '[data-value="' + encodeURIComponent(item) + '"]'; | |
320 | var $item_element = that.$buttongroup.find(item_query); |
|
323 | var $item_element = that.$buttongroup.find(item_query); | |
|
324 | var $icon_element = $item_element.find('.fa'); | |||
321 | if (!$item_element.length) { |
|
325 | if (!$item_element.length) { | |
322 | $item_element = $('<button/>') |
|
326 | $item_element = $('<button/>') | |
323 | .attr('type', 'button') |
|
327 | .attr('type', 'button') | |
@@ -325,16 +329,22 b' define([' | |||||
325 | .html(item_html) |
|
329 | .html(item_html) | |
326 | .appendTo(that.$buttongroup) |
|
330 | .appendTo(that.$buttongroup) | |
327 | .attr('data-value', encodeURIComponent(item)) |
|
331 | .attr('data-value', encodeURIComponent(item)) | |
|
332 | .attr('data-toggle', 'tooltip') | |||
328 | .attr('value', item) |
|
333 | .attr('value', item) | |
329 | .on('click', $.proxy(that.handle_click, that)); |
|
334 | .on('click', $.proxy(that.handle_click, that)); | |
330 | that.update_style_traits($item_element); |
|
335 | that.update_style_traits($item_element); | |
|
336 | $icon_element = $('<i class="fa"></i>').prependTo($item_element); | |||
331 | } |
|
337 | } | |
332 | if (that.model.get('selected_label') == item) { |
|
338 | if (that.model.get('selected_label') == item) { | |
333 | $item_element.addClass('active'); |
|
339 | $item_element.addClass('active'); | |
334 | } else { |
|
340 | } else { | |
335 | $item_element.removeClass('active'); |
|
341 | $item_element.removeClass('active'); | |
336 | } |
|
342 | } | |
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]); | |||
338 | }); |
|
348 | }); | |
339 |
|
349 | |||
340 | // Remove items that no longer exist. |
|
350 | // Remove items that no longer exist. |
@@ -49,7 +49,7 b' casper.notebook_test(function () {' | |||||
49 | 'Toggle button exists.'); |
|
49 | 'Toggle button exists.'); | |
50 |
|
50 | |||
51 | this.test.assert(this.cell_element_function(bool_index, |
|
51 | this.test.assert(this.cell_element_function(bool_index, | |
52 |
widget_togglebutton_selector, 'html')== |
|
52 | widget_togglebutton_selector, 'html')=='<i class="fa"></i>Title', | |
53 | 'Toggle button labeled correctly.'); |
|
53 | 'Toggle button labeled correctly.'); | |
54 |
|
54 | |||
55 | this.test.assert(this.cell_element_function(bool_index, |
|
55 | this.test.assert(this.cell_element_function(bool_index, |
@@ -29,7 +29,7 b' casper.notebook_test(function () {' | |||||
29 | 'Widget button exists.'); |
|
29 | 'Widget button exists.'); | |
30 |
|
30 | |||
31 | this.test.assert(this.cell_element_function(button_index, |
|
31 | 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', | |
33 | 'Set button description.'); |
|
33 | 'Set button description.'); | |
34 |
|
34 | |||
35 | this.cell_element_function(button_index, |
|
35 | this.cell_element_function(button_index, |
@@ -55,10 +55,15 b' class ToggleButton(_Bool):' | |||||
55 | value of the toggle button: True-pressed, False-unpressed |
|
55 | value of the toggle button: True-pressed, False-unpressed | |
56 | description : str |
|
56 | description : str | |
57 | description displayed next to the button |
|
57 | description displayed next to the button | |
|
58 | tooltip: str | |||
|
59 | tooltip caption of the toggle button | |||
|
60 | icon: str | |||
|
61 | font-awesome icon name | |||
58 | """ |
|
62 | """ | |
59 |
|
63 | |||
60 | _view_name = Unicode('ToggleButtonView', sync=True) |
|
64 | _view_name = Unicode('ToggleButtonView', sync=True) | |
61 | tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True) |
|
65 | tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True) | |
|
66 | icon = Unicode('', help= "Font-awesome icon.", sync=True) | |||
62 |
|
67 | |||
63 | button_style = CaselessStrEnum( |
|
68 | button_style = CaselessStrEnum( | |
64 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
|
69 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
@@ -24,15 +24,25 b' from IPython.utils.warn import DeprecatedClass' | |||||
24 | @register('IPython.Button') |
|
24 | @register('IPython.Button') | |
25 | class Button(DOMWidget): |
|
25 | class Button(DOMWidget): | |
26 | """Button widget. |
|
26 | """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. | |||
27 |
|
29 | |||
28 | This widget has an `on_click` method that allows you to listen for the |
|
30 | Parameters | |
29 | user clicking on the button. The click event itself is stateless.""" |
|
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 | """ | |||
30 | _view_name = Unicode('ButtonView', sync=True) |
|
39 | _view_name = Unicode('ButtonView', sync=True) | |
31 |
|
40 | |||
32 | # Keys |
|
41 | # Keys | |
33 | description = Unicode('', help="Button label.", sync=True) |
|
42 | description = Unicode('', help="Button label.", sync=True) | |
34 | tooltip = Unicode(help="Tooltip caption of the button.", sync=True) |
|
43 | tooltip = Unicode(help="Tooltip caption of the button.", sync=True) | |
35 | disabled = Bool(False, help="Enable or disable user changes.", sync=True) |
|
44 | disabled = Bool(False, help="Enable or disable user changes.", sync=True) | |
|
45 | icon = Unicode('', help= "Font-awesome icon.", sync=True) | |||
36 |
|
46 | |||
37 | button_style = CaselessStrEnum( |
|
47 | button_style = CaselessStrEnum( | |
38 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
|
48 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
@@ -19,7 +19,7 b' from threading import Lock' | |||||
19 |
|
19 | |||
20 | from .widget import DOMWidget, register |
|
20 | from .widget import DOMWidget, register | |
21 | from IPython.utils.traitlets import ( |
|
21 | from IPython.utils.traitlets import ( | |
22 | Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple |
|
22 | Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List | |
23 | ) |
|
23 | ) | |
24 | from IPython.utils.py3compat import unicode_type |
|
24 | from IPython.utils.py3compat import unicode_type | |
25 | from IPython.utils.warn import DeprecatedClass |
|
25 | from IPython.utils.warn import DeprecatedClass | |
@@ -32,6 +32,12 b' class _Selection(DOMWidget):' | |||||
32 |
|
32 | |||
33 | ``options`` can be specified as a list or dict. If given as a list, |
|
33 | ``options`` can be specified as a list or dict. If given as a list, | |
34 | it will be transformed to a dict of the form ``{str(value):value}``. |
|
34 | 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. | |||
35 | """ |
|
41 | """ | |
36 |
|
42 | |||
37 | value = Any(help="Selected value") |
|
43 | value = Any(help="Selected value") | |
@@ -194,6 +200,8 b' class ToggleButtons(_Selection):' | |||||
194 | """Group of toggle buttons that represent an enumeration. Only one toggle |
|
200 | """Group of toggle buttons that represent an enumeration. Only one toggle | |
195 | button can be toggled at any point in time.""" |
|
201 | button can be toggled at any point in time.""" | |
196 | _view_name = Unicode('ToggleButtonsView', sync=True) |
|
202 | _view_name = Unicode('ToggleButtonsView', sync=True) | |
|
203 | tooltips = List(Unicode(), sync=True) | |||
|
204 | icons = List(Unicode(), sync=True) | |||
197 |
|
205 | |||
198 | button_style = CaselessStrEnum( |
|
206 | button_style = CaselessStrEnum( | |
199 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
|
207 | values=['primary', 'success', 'info', 'warning', 'danger', ''], |
General Comments 0
You need to be logged in to leave comments.
Login now