mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
More fixes
This commit is contained in:
parent
d694666e66
commit
c085593e2a
@ -25,30 +25,31 @@ define(["notebook/js/widgets/widget"], function(widget_manager){
|
||||
.addClass('widget-hlabel')
|
||||
.appendTo(this.$el)
|
||||
.hide();
|
||||
var that = this;
|
||||
this.$checkbox = $('<input />')
|
||||
.attr('type', 'checkbox')
|
||||
.click(function(el) {
|
||||
|
||||
// Calling model.set will trigger all of the other views of the
|
||||
// model to update.
|
||||
that.model.set('value', that.$checkbox.prop('checked'), {updated_view: this});
|
||||
that.touch();
|
||||
})
|
||||
.appendTo(this.$el);
|
||||
.appendTo(this.$el)
|
||||
.click($.proxy(this.handle_click, this));
|
||||
|
||||
this.$el_to_style = this.$checkbox; // Set default element to style
|
||||
this.update(); // Set defaults.
|
||||
},
|
||||
|
||||
handle_click: function() {
|
||||
// Calling model.set will trigger all of the other views of the
|
||||
// model to update.
|
||||
var value = this.model.get('value');
|
||||
this.model.set('value', ! value, {updated_view: this});
|
||||
this.touch();
|
||||
},
|
||||
|
||||
update : function(options){
|
||||
// Update the contents of this view
|
||||
//
|
||||
// Called when the model is changed. The model may have been
|
||||
// changed by another view or by a state update from the back-end.
|
||||
if (options === undefined || options.updated_view != this) {
|
||||
this.$checkbox.prop('checked', this.model.get('value'));
|
||||
this.$checkbox.prop('checked', this.model.get('value'));
|
||||
|
||||
if (options === undefined || options.updated_view != this) {
|
||||
var disabled = this.model.get('disabled');
|
||||
this.$checkbox.prop('disabled', disabled);
|
||||
|
||||
@ -70,11 +71,15 @@ define(["notebook/js/widgets/widget"], function(widget_manager){
|
||||
var ToggleButtonView = IPython.DOMWidgetView.extend({
|
||||
|
||||
// Called when view is rendered.
|
||||
render : function(){
|
||||
render : function() {
|
||||
var that = this;
|
||||
this.setElement($('<button />')
|
||||
.addClass('btn')
|
||||
.attr('type', 'button')
|
||||
.attr('data-toggle', 'button'));
|
||||
.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
that.handle_click();
|
||||
}));
|
||||
|
||||
this.update(); // Set defaults.
|
||||
},
|
||||
@ -91,6 +96,7 @@ define(["notebook/js/widgets/widget"], function(widget_manager){
|
||||
}
|
||||
|
||||
if (options === undefined || options.updated_view != this) {
|
||||
|
||||
var disabled = this.model.get('disabled');
|
||||
this.$el.prop('disabled', disabled);
|
||||
|
||||
@ -104,14 +110,13 @@ define(["notebook/js/widgets/widget"], function(widget_manager){
|
||||
return ToggleButtonView.__super__.update.apply(this);
|
||||
},
|
||||
|
||||
events: {"click" : "handleClick"},
|
||||
|
||||
// Handles and validates user input.
|
||||
handleClick: function(e) {
|
||||
handle_click: function(e) {
|
||||
|
||||
// Calling model.set will trigger all of the other views of the
|
||||
// model to update.
|
||||
this.model.set('value', ! $(this.$el).hasClass('active'), {updated_view: this});
|
||||
var value = this.model.get('value');
|
||||
this.model.set('value', ! value, {updated_view: this});
|
||||
this.touch();
|
||||
},
|
||||
});
|
||||
|
@ -25,59 +25,9 @@ casper.notebook_test(function () {
|
||||
}), 'Notebook widget manager instanciated');
|
||||
});
|
||||
|
||||
index = this.append_cell(
|
||||
'names = [name for name in dir(widgets)' +
|
||||
' if name.endswith("Widget") and name!= "Widget" and name!= "DOMWidget"]\n' +
|
||||
'for name in names:\n' +
|
||||
' print(name)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
|
||||
// Get the widget names that are registered with the widget manager. Assume
|
||||
// a 1 to 1 mapping of model and widgets names (model names just have 'model'
|
||||
// suffixed).
|
||||
var javascript_names = this.evaluate(function () {
|
||||
names = [];
|
||||
for (var name in IPython.widget_manager._model_types) {
|
||||
names.push(name.replace('Model',''));
|
||||
}
|
||||
return names;
|
||||
});
|
||||
|
||||
// Get the widget names registered in python.
|
||||
var python_names = this.get_output_cell(index).text.split('\n');
|
||||
|
||||
// Make sure the two lists have the same items.
|
||||
for (var i in javascript_names) {
|
||||
var javascript_name = javascript_names[i];
|
||||
var found = false;
|
||||
for (var j in python_names) {
|
||||
var python_name = python_names[j];
|
||||
if (python_name==javascript_name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.test.assert(found, javascript_name + ' exists in python');
|
||||
}
|
||||
for (var i in python_names) {
|
||||
var python_name = python_names[i];
|
||||
if (python_name.length > 0) {
|
||||
var found = false;
|
||||
for (var j in javascript_names) {
|
||||
var javascript_name = javascript_names[j];
|
||||
if (python_name==javascript_name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.test.assert(found, python_name + ' exists in javascript');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
throttle_index = this.append_cell(
|
||||
'import time\n' +
|
||||
'textbox = widgets.StringWidget()\n' +
|
||||
'textbox = widgets.TextBoxWidget()\n' +
|
||||
'display(textbox)\n'+
|
||||
'textbox.add_class("my-throttle-textbox")\n' +
|
||||
'def handle_change(name, old, new):\n' +
|
||||
|
@ -7,15 +7,10 @@ casper.notebook_test(function () {
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var bool_index = this.append_cell(
|
||||
'bool_widgets = [widgets.BoolWidget(description="Title", value=True) for i in range(2)]\n' +
|
||||
'bool_widgets = [widgets.CheckBoxWidget(description="Title", value=True),\n' +
|
||||
' widgets.ToggleButtonWidget(description="Title", value=True)]\n' +
|
||||
'display(bool_widgets[0])\n' +
|
||||
'bool_widgets[1].view_name = "ToggleButtonView"\n' +
|
||||
'display(bool_widgets[1])\n' +
|
||||
'for widget in bool_widgets:\n' +
|
||||
' def handle_change(name,old,new):\n' +
|
||||
' for other_widget in bool_widgets:\n' +
|
||||
' other_widget.value = new\n' +
|
||||
' widget.on_trait_change(handle_change, "value")\n' +
|
||||
'print("Success")');
|
||||
this.execute_cell_then(bool_index, function(index){
|
||||
|
||||
@ -58,6 +53,7 @@ casper.notebook_test(function () {
|
||||
|
||||
index = this.append_cell(
|
||||
'bool_widgets[0].value = False\n' +
|
||||
'bool_widgets[1].value = False\n' +
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index, function(index){
|
||||
|
||||
@ -71,28 +67,20 @@ casper.notebook_test(function () {
|
||||
this.test.assert(! this.cell_element_function(bool_index,
|
||||
'.widget-area .widget-subarea button', 'hasClass', ['active']),
|
||||
'Toggle button is not toggled. (1)');
|
||||
|
||||
// Try toggling the bool by clicking on the toggle button.
|
||||
this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click');
|
||||
|
||||
// Try toggling the bool by clicking on the checkbox.
|
||||
this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
|
||||
|
||||
this.test.assert(this.cell_element_function(bool_index,
|
||||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
|
||||
'Checkbox is checked. (2)');
|
||||
|
||||
// Try toggling the bool by clicking on the toggle button.
|
||||
this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click');
|
||||
|
||||
this.test.assert(this.cell_element_function(bool_index,
|
||||
'.widget-area .widget-subarea button', 'hasClass', ['active']),
|
||||
'Toggle button is toggled. (2)');
|
||||
|
||||
// Try toggling the bool by clicking on the checkbox.
|
||||
this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
|
||||
|
||||
this.test.assert(! this.cell_element_function(bool_index,
|
||||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
|
||||
'Checkbox is not checked. (3)');
|
||||
|
||||
this.test.assert(! this.cell_element_function(bool_index,
|
||||
'.widget-area .widget-subarea button', 'hasClass', ['active']),
|
||||
'Toggle button is not toggled. (3)');
|
||||
'Toggle button is toggled. (3)');
|
||||
|
||||
});
|
||||
});
|
@ -238,8 +238,8 @@ class Widget(LoggingConfigurable):
|
||||
new_list.append(self._unpack_widgets(value))
|
||||
return new_list
|
||||
elif isinstance(values, string_types):
|
||||
if widget.model_id in Widget.widgets:
|
||||
return Widget.widgets[widget.model_id]
|
||||
if values in Widget.widgets:
|
||||
return Widget.widgets[values]
|
||||
else:
|
||||
return values
|
||||
else:
|
||||
|
@ -46,7 +46,7 @@ class TextBoxWidget(HTMLWidget):
|
||||
view_name = Unicode('TextBoxView', sync=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(StringWidget, self).__init__(**kwargs)
|
||||
super(TextBoxWidget, self).__init__(**kwargs)
|
||||
self._submission_callbacks = []
|
||||
self.on_msg(self._handle_string_msg)
|
||||
|
||||
@ -90,5 +90,5 @@ class TextBoxWidget(HTMLWidget):
|
||||
elif nargs == 1:
|
||||
self._submission_callbacks.append(callback)
|
||||
else:
|
||||
raise TypeError('StringWidget submit callback must ' \
|
||||
raise TypeError('TextBoxWidget submit callback must ' \
|
||||
'accept 0 or 1 arguments.')
|
||||
|
Loading…
Reference in New Issue
Block a user