mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Added labels to basic widgets
This commit is contained in:
parent
9b891d4018
commit
f2d77f3b78
@ -13,12 +13,14 @@ require(["notebook/js/widget"], function(){
|
||||
|
||||
var $label = $('<label />')
|
||||
.addClass('checkbox')
|
||||
.addClass('widget-label')
|
||||
.appendTo(this.$el);
|
||||
this.$checkbox_label = $('<div />')
|
||||
.appendTo($label)
|
||||
.hide();
|
||||
this.$checkbox = $('<input />')
|
||||
.attr('type', 'checkbox')
|
||||
.appendTo($label);
|
||||
this.$checkbox_label = $('<div />')
|
||||
.appendTo($label);
|
||||
|
||||
this.update(); // Set defaults.
|
||||
},
|
||||
@ -28,7 +30,14 @@ require(["notebook/js/widget"], function(){
|
||||
update : function(){
|
||||
if (!this.user_invoked_update) {
|
||||
this.$checkbox.prop('checked', this.model.get('value'));
|
||||
this.$checkbox_label.html(this.model.get('description'));
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$checkbox_label.hide();
|
||||
} else {
|
||||
this.$checkbox_label.html(description);
|
||||
this.$checkbox_label.show();
|
||||
}
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
@ -71,7 +80,13 @@ require(["notebook/js/widget"], function(){
|
||||
} else {
|
||||
this.$button.removeClass('active');
|
||||
}
|
||||
this.$button.html(this.model.get('description'));
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$button.html(' '); // Preserve button height
|
||||
} else {
|
||||
this.$button.html(description);
|
||||
}
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
@ -22,7 +22,13 @@ require(["notebook/js/widget"], function(){
|
||||
// Handles: Backend -> Frontend Sync
|
||||
// Frontent -> Frontend Sync
|
||||
update : function(){
|
||||
this.$el.html(this.model.get('description'));
|
||||
var description = this.model.get('description');
|
||||
if (description.length==0) {
|
||||
this.$el.html(' '); // Preserve button height
|
||||
} else {
|
||||
this.$el.html(description);
|
||||
}
|
||||
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
|
@ -9,6 +9,10 @@ require(["notebook/js/widget"], function(){
|
||||
|
||||
this.$el
|
||||
.html('');
|
||||
this.$label = $('<div />')
|
||||
.appendTo(this.$el)
|
||||
.addClass('widget-label')
|
||||
.hide();
|
||||
this.$buttongroup = $('<div />')
|
||||
.addClass('widget_item')
|
||||
.addClass('btn-group')
|
||||
@ -60,6 +64,14 @@ require(["notebook/js/widget"], function(){
|
||||
this.$dropbutton.removeAttr('disabled');
|
||||
this.$droplist.removeAttr('disabled');
|
||||
}
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.html(description);
|
||||
this.$label.show();
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
@ -73,6 +85,10 @@ require(["notebook/js/widget"], function(){
|
||||
render : function(){
|
||||
this.$el
|
||||
.html('');
|
||||
this.$label = $('<div />')
|
||||
.appendTo(this.$el)
|
||||
.addClass('widget-label')
|
||||
.hide();
|
||||
this.update();
|
||||
},
|
||||
|
||||
@ -124,6 +140,14 @@ require(["notebook/js/widget"], function(){
|
||||
$(obj).parent().remove();
|
||||
}
|
||||
});
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.html(description);
|
||||
this.$label.show();
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
@ -138,6 +162,10 @@ require(["notebook/js/widget"], function(){
|
||||
render : function(){
|
||||
this.$el
|
||||
.html('');
|
||||
this.$label = $('<div />')
|
||||
.appendTo(this.$el)
|
||||
.addClass('widget-label')
|
||||
.hide();
|
||||
this.$buttongroup = $('<div />')
|
||||
.addClass('btn-group')
|
||||
.attr('data-toggle', 'buttons-radio')
|
||||
@ -189,6 +217,14 @@ require(["notebook/js/widget"], function(){
|
||||
$(obj).remove();
|
||||
}
|
||||
});
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.html(description);
|
||||
this.$label.show();
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
|
@ -27,6 +27,10 @@ require(["notebook/js/widget"], function(){
|
||||
render : function(){
|
||||
this.$el
|
||||
.html('');
|
||||
this.$label = $('<div />')
|
||||
.appendTo(this.$el)
|
||||
.addClass('widget-label')
|
||||
.hide();
|
||||
this.$textbox = $('<textarea />')
|
||||
.attr('rows', 5)
|
||||
.appendTo(this.$el);
|
||||
@ -39,6 +43,14 @@ require(["notebook/js/widget"], function(){
|
||||
if (!this.user_invoked_update) {
|
||||
this.$textbox.val(this.model.get('value'));
|
||||
}
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.html(description);
|
||||
this.$label.show();
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
@ -63,6 +75,10 @@ require(["notebook/js/widget"], function(){
|
||||
render : function(){
|
||||
this.$el
|
||||
.html('');
|
||||
this.$label = $('<div />')
|
||||
.addClass('widget-label')
|
||||
.appendTo(this.$el)
|
||||
.hide();
|
||||
this.$textbox = $('<input type="text" />')
|
||||
.addClass('input')
|
||||
.appendTo(this.$el);
|
||||
@ -75,6 +91,14 @@ require(["notebook/js/widget"], function(){
|
||||
if (!this.user_invoked_update) {
|
||||
this.$textbox.val(this.model.get('value'));
|
||||
}
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length == 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.html(description);
|
||||
this.$label.show();
|
||||
}
|
||||
return IPython.WidgetView.prototype.update.call(this);
|
||||
},
|
||||
|
||||
|
@ -24,6 +24,7 @@ class FloatWidget(Widget):
|
||||
default_view_name = Unicode('FloatTextView')
|
||||
|
||||
# Keys
|
||||
_keys = ['value', 'disabled']
|
||||
_keys = ['value', 'disabled', 'description']
|
||||
value = Float(0.0, help="Float value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
|
@ -24,6 +24,7 @@ class IntWidget(Widget):
|
||||
default_view_name = Unicode('IntTextView')
|
||||
|
||||
# Keys
|
||||
_keys = ['value', 'disabled']
|
||||
_keys = ['value', 'disabled', 'description']
|
||||
value = Int(0, help="Int value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
|
@ -24,8 +24,9 @@ class SelectionWidget(Widget):
|
||||
default_view_name = Unicode('DropdownView')
|
||||
|
||||
# Keys
|
||||
_keys = ['value', 'values', 'disabled']
|
||||
_keys = ['value', 'values', 'disabled', 'description']
|
||||
value = Unicode(help="Selected value")
|
||||
values = List(help="List of values the user can select")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
|
@ -24,6 +24,7 @@ class StringWidget(Widget):
|
||||
default_view_name = Unicode('TextBoxView')
|
||||
|
||||
# Keys
|
||||
_keys = ['value', 'disabled']
|
||||
_keys = ['value', 'disabled', 'description']
|
||||
value = Unicode(help="String value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
|
Loading…
Reference in New Issue
Block a user