##// END OF EJS Templates
More fixes
Jonathan Frederic -
Show More
@@ -25,30 +25,31 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
25 .addClass('widget-hlabel')
25 .addClass('widget-hlabel')
26 .appendTo(this.$el)
26 .appendTo(this.$el)
27 .hide();
27 .hide();
28 var that = this;
29 this.$checkbox = $('<input />')
28 this.$checkbox = $('<input />')
30 .attr('type', 'checkbox')
29 .attr('type', 'checkbox')
31 .click(function(el) {
30 .appendTo(this.$el)
32
31 .click($.proxy(this.handle_click, this));
33 // Calling model.set will trigger all of the other views of the
34 // model to update.
35 that.model.set('value', that.$checkbox.prop('checked'), {updated_view: this});
36 that.touch();
37 })
38 .appendTo(this.$el);
39
32
40 this.$el_to_style = this.$checkbox; // Set default element to style
33 this.$el_to_style = this.$checkbox; // Set default element to style
41 this.update(); // Set defaults.
34 this.update(); // Set defaults.
42 },
35 },
43
36
37 handle_click: function() {
38 // Calling model.set will trigger all of the other views of the
39 // model to update.
40 var value = this.model.get('value');
41 this.model.set('value', ! value, {updated_view: this});
42 this.touch();
43 },
44
44 update : function(options){
45 update : function(options){
45 // Update the contents of this view
46 // Update the contents of this view
46 //
47 //
47 // Called when the model is changed. The model may have been
48 // Called when the model is changed. The model may have been
48 // changed by another view or by a state update from the back-end.
49 // changed by another view or by a state update from the back-end.
49 if (options === undefined || options.updated_view != this) {
50 this.$checkbox.prop('checked', this.model.get('value'));
50 this.$checkbox.prop('checked', this.model.get('value'));
51
51
52 if (options === undefined || options.updated_view != this) {
52 var disabled = this.model.get('disabled');
53 var disabled = this.model.get('disabled');
53 this.$checkbox.prop('disabled', disabled);
54 this.$checkbox.prop('disabled', disabled);
54
55
@@ -71,10 +72,14 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
71
72
72 // Called when view is rendered.
73 // Called when view is rendered.
73 render : function(){
74 render : function() {
75 var that = this;
74 this.setElement($('<button />')
76 this.setElement($('<button />')
75 .addClass('btn')
77 .addClass('btn')
76 .attr('type', 'button')
78 .attr('type', 'button')
77 .attr('data-toggle', 'button'));
79 .on('click', function (e) {
80 e.preventDefault();
81 that.handle_click();
82 }));
78
83
79 this.update(); // Set defaults.
84 this.update(); // Set defaults.
80 },
85 },
@@ -91,6 +96,7 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
91 }
96 }
92
97
93 if (options === undefined || options.updated_view != this) {
98 if (options === undefined || options.updated_view != this) {
99
94 var disabled = this.model.get('disabled');
100 var disabled = this.model.get('disabled');
95 this.$el.prop('disabled', disabled);
101 this.$el.prop('disabled', disabled);
96
102
@@ -104,14 +110,13 b' define(["notebook/js/widgets/widget"], function(widget_manager){'
104 return ToggleButtonView.__super__.update.apply(this);
110 return ToggleButtonView.__super__.update.apply(this);
105 },
111 },
106
112
107 events: {"click" : "handleClick"},
108
109 // Handles and validates user input.
113 // Handles and validates user input.
110 handleClick: function(e) {
114 handle_click: function(e) {
111
115
112 // Calling model.set will trigger all of the other views of the
116 // Calling model.set will trigger all of the other views of the
113 // model to update.
117 // model to update.
114 this.model.set('value', ! $(this.$el).hasClass('active'), {updated_view: this});
118 var value = this.model.get('value');
119 this.model.set('value', ! value, {updated_view: this});
115 this.touch();
120 this.touch();
116 },
121 },
117 });
122 });
@@ -25,59 +25,9 b' casper.notebook_test(function () {'
25 }), 'Notebook widget manager instanciated');
25 }), 'Notebook widget manager instanciated');
26 });
26 });
27
27
28 index = this.append_cell(
29 'names = [name for name in dir(widgets)' +
30 ' if name.endswith("Widget") and name!= "Widget" and name!= "DOMWidget"]\n' +
31 'for name in names:\n' +
32 ' print(name)\n');
33 this.execute_cell_then(index, function(index){
34
35 // Get the widget names that are registered with the widget manager. Assume
36 // a 1 to 1 mapping of model and widgets names (model names just have 'model'
37 // suffixed).
38 var javascript_names = this.evaluate(function () {
39 names = [];
40 for (var name in IPython.widget_manager._model_types) {
41 names.push(name.replace('Model',''));
42 }
43 return names;
44 });
45
46 // Get the widget names registered in python.
47 var python_names = this.get_output_cell(index).text.split('\n');
48
49 // Make sure the two lists have the same items.
50 for (var i in javascript_names) {
51 var javascript_name = javascript_names[i];
52 var found = false;
53 for (var j in python_names) {
54 var python_name = python_names[j];
55 if (python_name==javascript_name) {
56 found = true;
57 break;
58 }
59 }
60 this.test.assert(found, javascript_name + ' exists in python');
61 }
62 for (var i in python_names) {
63 var python_name = python_names[i];
64 if (python_name.length > 0) {
65 var found = false;
66 for (var j in javascript_names) {
67 var javascript_name = javascript_names[j];
68 if (python_name==javascript_name) {
69 found = true;
70 break;
71 }
72 }
73 this.test.assert(found, python_name + ' exists in javascript');
74 }
75 }
76 });
77
78 throttle_index = this.append_cell(
28 throttle_index = this.append_cell(
79 'import time\n' +
29 'import time\n' +
80 'textbox = widgets.StringWidget()\n' +
30 'textbox = widgets.TextBoxWidget()\n' +
81 'display(textbox)\n'+
31 'display(textbox)\n'+
82 'textbox.add_class("my-throttle-textbox")\n' +
32 'textbox.add_class("my-throttle-textbox")\n' +
83 'def handle_change(name, old, new):\n' +
33 'def handle_change(name, old, new):\n' +
@@ -7,15 +7,10 b' casper.notebook_test(function () {'
7 this.execute_cell_then(index);
7 this.execute_cell_then(index);
8
8
9 var bool_index = this.append_cell(
9 var bool_index = this.append_cell(
10 'bool_widgets = [widgets.BoolWidget(description="Title", value=True) for i in range(2)]\n' +
10 'bool_widgets = [widgets.CheckBoxWidget(description="Title", value=True),\n' +
11 ' widgets.ToggleButtonWidget(description="Title", value=True)]\n' +
11 'display(bool_widgets[0])\n' +
12 'display(bool_widgets[0])\n' +
12 'bool_widgets[1].view_name = "ToggleButtonView"\n' +
13 'display(bool_widgets[1])\n' +
13 'display(bool_widgets[1])\n' +
14 'for widget in bool_widgets:\n' +
15 ' def handle_change(name,old,new):\n' +
16 ' for other_widget in bool_widgets:\n' +
17 ' other_widget.value = new\n' +
18 ' widget.on_trait_change(handle_change, "value")\n' +
19 'print("Success")');
14 'print("Success")');
20 this.execute_cell_then(bool_index, function(index){
15 this.execute_cell_then(bool_index, function(index){
21
16
@@ -58,6 +53,7 b' casper.notebook_test(function () {'
58
53
59 index = this.append_cell(
54 index = this.append_cell(
60 'bool_widgets[0].value = False\n' +
55 'bool_widgets[0].value = False\n' +
56 'bool_widgets[1].value = False\n' +
61 'print("Success")');
57 'print("Success")');
62 this.execute_cell_then(index, function(index){
58 this.execute_cell_then(index, function(index){
63
59
@@ -72,27 +68,19 b' casper.notebook_test(function () {'
72 '.widget-area .widget-subarea button', 'hasClass', ['active']),
68 '.widget-area .widget-subarea button', 'hasClass', ['active']),
73 'Toggle button is not toggled. (1)');
69 'Toggle button is not toggled. (1)');
74
70
75 // Try toggling the bool by clicking on the toggle button.
71 // Try toggling the bool by clicking on the checkbox.
76 this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click');
72 this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
77
73
78 this.test.assert(this.cell_element_function(bool_index,
74 this.test.assert(this.cell_element_function(bool_index,
79 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
75 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
80 'Checkbox is checked. (2)');
76 'Checkbox is checked. (2)');
81
77
82 this.test.assert(this.cell_element_function(bool_index,
78 // Try toggling the bool by clicking on the toggle button.
83 '.widget-area .widget-subarea button', 'hasClass', ['active']),
79 this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click');
84 'Toggle button is toggled. (2)');
85
86 // Try toggling the bool by clicking on the checkbox.
87 this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
88
89 this.test.assert(! this.cell_element_function(bool_index,
90 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
91 'Checkbox is not checked. (3)');
92
80
93 this.test.assert(! this.cell_element_function(bool_index,
81 this.test.assert(this.cell_element_function(bool_index,
94 '.widget-area .widget-subarea button', 'hasClass', ['active']),
82 '.widget-area .widget-subarea button', 'hasClass', ['active']),
95 'Toggle button is not toggled. (3)');
83 'Toggle button is toggled. (3)');
96
84
97 });
85 });
98 }); No newline at end of file
86 });
@@ -238,8 +238,8 b' class Widget(LoggingConfigurable):'
238 new_list.append(self._unpack_widgets(value))
238 new_list.append(self._unpack_widgets(value))
239 return new_list
239 return new_list
240 elif isinstance(values, string_types):
240 elif isinstance(values, string_types):
241 if widget.model_id in Widget.widgets:
241 if values in Widget.widgets:
242 return Widget.widgets[widget.model_id]
242 return Widget.widgets[values]
243 else:
243 else:
244 return values
244 return values
245 else:
245 else:
@@ -46,7 +46,7 b' class TextBoxWidget(HTMLWidget):'
46 view_name = Unicode('TextBoxView', sync=True)
46 view_name = Unicode('TextBoxView', sync=True)
47
47
48 def __init__(self, **kwargs):
48 def __init__(self, **kwargs):
49 super(StringWidget, self).__init__(**kwargs)
49 super(TextBoxWidget, self).__init__(**kwargs)
50 self._submission_callbacks = []
50 self._submission_callbacks = []
51 self.on_msg(self._handle_string_msg)
51 self.on_msg(self._handle_string_msg)
52
52
@@ -90,5 +90,5 b' class TextBoxWidget(HTMLWidget):'
90 elif nargs == 1:
90 elif nargs == 1:
91 self._submission_callbacks.append(callback)
91 self._submission_callbacks.append(callback)
92 else:
92 else:
93 raise TypeError('StringWidget submit callback must ' \
93 raise TypeError('TextBoxWidget submit callback must ' \
94 'accept 0 or 1 arguments.')
94 'accept 0 or 1 arguments.')
General Comments 0
You need to be logged in to leave comments. Login now