Show More
@@ -36,6 +36,7 b' define(["components/underscore/underscore-min",' | |||||
36 | this.msg_throttle = 3; |
|
36 | this.msg_throttle = 3; | |
37 | this.msg_buffer = null; |
|
37 | this.msg_buffer = null; | |
38 | this.views = {}; |
|
38 | this.views = {}; | |
|
39 | this._custom_msg_callbacks = []; | |||
39 |
|
40 | |||
40 | // Remember comm associated with the model. |
|
41 | // Remember comm associated with the model. | |
41 | this.comm = comm; |
|
42 | this.comm = comm; | |
@@ -64,15 +65,17 b' define(["components/underscore/underscore-min",' | |||||
64 | } |
|
65 | } | |
65 | }, |
|
66 | }, | |
66 |
|
67 | |||
67 | send: function(content) { |
|
68 | ||
|
69 | send: function(content, cell) { | |||
68 |
|
70 | |||
69 | // Used the last modified view as the sender of the message. This |
|
71 | // Used the last modified view as the sender of the message. This | |
70 | // will insure that any python code triggered by the sent message |
|
72 | // will insure that any python code triggered by the sent message | |
71 | // can create and display widgets and output. |
|
73 | // can create and display widgets and output. | |
72 |
|
|
74 | if (cell === undefined) { | |
73 | if (this.last_modified_view != undefined && |
|
75 | if (this.last_modified_view != undefined && | |
74 | this.last_modified_view.cell != undefined) { |
|
76 | this.last_modified_view.cell != undefined) { | |
75 | cell = this.last_modified_view.cell; |
|
77 | cell = this.last_modified_view.cell; | |
|
78 | } | |||
76 | } |
|
79 | } | |
77 | var callbacks = this._make_callbacks(cell); |
|
80 | var callbacks = this._make_callbacks(cell); | |
78 | var data = {'custom_content': content}; |
|
81 | var data = {'custom_content': content}; | |
@@ -90,15 +93,29 b' define(["components/underscore/underscore-min",' | |||||
90 | }, |
|
93 | }, | |
91 |
|
94 | |||
92 |
|
95 | |||
93 | on_msg: function (callback) { |
|
96 | on_msg: function (callback, remove) { | |
94 | this._msg_callback = callback; |
|
97 | if (remove) { | |
|
98 | var found_index = -1; | |||
|
99 | for (var index in this._custom_msg_callbacks) { | |||
|
100 | if (callback === this._custom_msg_callbacks[index]) { | |||
|
101 | found_index = index; | |||
|
102 | break; | |||
|
103 | } | |||
|
104 | } | |||
|
105 | ||||
|
106 | if (found_index >= 0) { | |||
|
107 | this._custom_msg_callbacks.splice(found_index, 1); | |||
|
108 | } | |||
|
109 | } else { | |||
|
110 | this._custom_msg_callbacks.push(callback) | |||
|
111 | } | |||
95 | }, |
|
112 | }, | |
96 |
|
113 | |||
97 |
|
114 | |||
98 | _handle_custom_msg: function (content) { |
|
115 | _handle_custom_msg: function (content) { | |
99 |
|
|
116 | for (var index in this._custom_msg_callbacks) { | |
100 | try { |
|
117 | try { | |
101 | this._msg_callback(content); |
|
118 | this._custom_msg_callbacks[index](content); | |
102 | } catch (e) { |
|
119 | } catch (e) { | |
103 | console.log("Exception in widget model msg callback", e, content); |
|
120 | console.log("Exception in widget model msg callback", e, content); | |
104 | } |
|
121 | } | |
@@ -465,6 +482,11 b' define(["components/underscore/underscore-min",' | |||||
465 | elements.removeClass(class_list); |
|
482 | elements.removeClass(class_list); | |
466 | } |
|
483 | } | |
467 | }, |
|
484 | }, | |
|
485 | ||||
|
486 | ||||
|
487 | send: function(content) { | |||
|
488 | this.model.send({event: 'click'}, this.cell); | |||
|
489 | }, | |||
468 |
|
490 | |||
469 | update: function() { |
|
491 | update: function() { | |
470 | if (this.model.get('visible') != undefined) { |
|
492 | if (this.model.get('visible') != undefined) { |
@@ -50,8 +50,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
50 | }, |
|
50 | }, | |
51 |
|
51 | |||
52 | _handle_click: function(){ |
|
52 | _handle_click: function(){ | |
53 | this.model.last_modified_view = this; // For callbacks. |
|
53 | this.send({event: 'click'}); | |
54 | this.model.send({event: 'click'}); |
|
|||
55 | }, |
|
54 | }, | |
56 | }); |
|
55 | }); | |
57 |
|
56 |
@@ -39,7 +39,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
39 | var TextAreaView = IPython.WidgetView.extend({ |
|
39 | var TextAreaView = IPython.WidgetView.extend({ | |
40 |
|
40 | |||
41 | // Called when view is rendered. |
|
41 | // Called when view is rendered. | |
42 |
render |
|
42 | render: function(){ | |
43 | this.$el |
|
43 | this.$el | |
44 | .addClass('widget-hbox') |
|
44 | .addClass('widget-hbox') | |
45 | .html(''); |
|
45 | .html(''); | |
@@ -53,23 +53,30 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
53 | .appendTo(this.$el); |
|
53 | .appendTo(this.$el); | |
54 | this.$el_to_style = this.$textbox; // Set default element to style |
|
54 | this.$el_to_style = this.$textbox; // Set default element to style | |
55 | this.update(); // Set defaults. |
|
55 | this.update(); // Set defaults. | |
|
56 | ||||
|
57 | this.on_msg(); | |||
|
58 | }, | |||
|
59 | ||||
|
60 | ||||
|
61 | _handle_textarea_msg: function (content){ | |||
|
62 | if (content.method == "scroll_to_bottom") { | |||
|
63 | this.scroll_to_bottom(); | |||
|
64 | } | |||
|
65 | }, | |||
|
66 | ||||
|
67 | ||||
|
68 | scroll_to_bottom: function (){ | |||
|
69 | this.$textbox.scrollTop(this.$textbox[0].scrollHeight); | |||
56 | }, |
|
70 | }, | |
|
71 | ||||
57 |
|
72 | |||
58 | // Handles: Backend -> Frontend Sync |
|
73 | // Handles: Backend -> Frontend Sync | |
59 | // Frontent -> Frontend Sync |
|
74 | // Frontent -> Frontend Sync | |
60 |
update |
|
75 | update: function(){ | |
61 | if (!this.user_invoked_update) { |
|
76 | if (!this.user_invoked_update) { | |
62 | this.$textbox.val(this.model.get('value')); |
|
77 | this.$textbox.val(this.model.get('value')); | |
63 | } |
|
78 | } | |
64 |
|
79 | |||
65 | if (this.last_scroll_to_bottom == undefined) { |
|
|||
66 | this.last_scroll_to_bottom = 0; |
|
|||
67 | } |
|
|||
68 | if (this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms')) { |
|
|||
69 | this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms'); |
|
|||
70 | this.$textbox.scrollTop(this.$textbox[0].scrollHeight); |
|
|||
71 | } |
|
|||
72 |
|
||||
73 | var disabled = this.model.get('disabled'); |
|
80 | var disabled = this.model.get('disabled'); | |
74 | this.$textbox.prop('disabled', disabled); |
|
81 | this.$textbox.prop('disabled', disabled); | |
75 |
|
82 | |||
@@ -83,9 +90,9 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
83 | return IPython.WidgetView.prototype.update.call(this); |
|
90 | return IPython.WidgetView.prototype.update.call(this); | |
84 | }, |
|
91 | }, | |
85 |
|
92 | |||
86 |
events: {"keyup textarea" |
|
93 | events: {"keyup textarea": "handleChanging", | |
87 |
"paste textarea" |
|
94 | "paste textarea": "handleChanging", | |
88 |
"cut textarea" |
|
95 | "cut textarea": "handleChanging"}, | |
89 |
|
96 | |||
90 | // Handles and validates user input. |
|
97 | // Handles and validates user input. | |
91 | handleChanging: function(e) { |
|
98 | handleChanging: function(e) { | |
@@ -101,7 +108,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
101 | var TextBoxView = IPython.WidgetView.extend({ |
|
108 | var TextBoxView = IPython.WidgetView.extend({ | |
102 |
|
109 | |||
103 | // Called when view is rendered. |
|
110 | // Called when view is rendered. | |
104 |
render |
|
111 | render: function(){ | |
105 | this.$el |
|
112 | this.$el | |
106 | .addClass('widget-hbox-single') |
|
113 | .addClass('widget-hbox-single') | |
107 | .html(''); |
|
114 | .html(''); | |
@@ -119,7 +126,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
119 |
|
126 | |||
120 | // Handles: Backend -> Frontend Sync |
|
127 | // Handles: Backend -> Frontend Sync | |
121 | // Frontent -> Frontend Sync |
|
128 | // Frontent -> Frontend Sync | |
122 |
update |
|
129 | update: function(){ | |
123 | if (this.$textbox.val() != this.model.get('value')) { |
|
130 | if (this.$textbox.val() != this.model.get('value')) { | |
124 | this.$textbox.val(this.model.get('value')); |
|
131 | this.$textbox.val(this.model.get('value')); | |
125 | } |
|
132 | } | |
@@ -137,10 +144,10 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
137 | return IPython.WidgetView.prototype.update.call(this); |
|
144 | return IPython.WidgetView.prototype.update.call(this); | |
138 | }, |
|
145 | }, | |
139 |
|
146 | |||
140 |
events: {"keyup input" |
|
147 | events: {"keyup input": "handleChanging", | |
141 |
"paste input" |
|
148 | "paste input": "handleChanging", | |
142 |
"cut input" |
|
149 | "cut input": "handleChanging", | |
143 |
"keypress input" |
|
150 | "keypress input": "handleKeypress"}, | |
144 |
|
151 | |||
145 | // Handles and validates user input. |
|
152 | // Handles and validates user input. | |
146 | handleChanging: function(e) { |
|
153 | handleChanging: function(e) { | |
@@ -151,8 +158,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
151 | // Handles text submition |
|
158 | // Handles text submition | |
152 | handleKeypress: function(e) { |
|
159 | handleKeypress: function(e) { | |
153 | if (e.keyCode == 13) { // Return key |
|
160 | if (e.keyCode == 13) { // Return key | |
154 | this.model.last_modified_view = this; // For callbacks. |
|
161 | this.send({event: 'submit'}); | |
155 | this.model.send({event: 'submit'}); |
|
|||
156 | } |
|
162 | } | |
157 | }, |
|
163 | }, | |
158 | }); |
|
164 | }); |
@@ -27,11 +27,10 b' class StringWidget(Widget):' | |||||
27 | default_view_name = Unicode('TextBoxView') |
|
27 | default_view_name = Unicode('TextBoxView') | |
28 |
|
28 | |||
29 | # Keys |
|
29 | # Keys | |
30 |
_keys = ['value', 'disabled', 'description' |
|
30 | _keys = ['value', 'disabled', 'description'] | |
31 | value = Unicode(help="String value") |
|
31 | value = Unicode(help="String value") | |
32 | disabled = Bool(False, help="Enable or disable user changes") |
|
32 | disabled = Bool(False, help="Enable or disable user changes") | |
33 | description = Unicode(help="Description of the value this widget represents") |
|
33 | description = Unicode(help="Description of the value this widget represents") | |
34 | scroll_to_bottoms = Int(0, help="Used to scroll a TextAreaView to the bottom") |
|
|||
35 |
|
34 | |||
36 |
|
35 | |||
37 | def __init__(self, **kwargs): |
|
36 | def __init__(self, **kwargs): | |
@@ -41,7 +40,7 b' class StringWidget(Widget):' | |||||
41 |
|
40 | |||
42 |
|
41 | |||
43 | def scroll_to_bottom(self): |
|
42 | def scroll_to_bottom(self): | |
44 |
self. |
|
43 | self._comm.send({"method": "scroll_to_bottom"}) | |
45 |
|
44 | |||
46 |
|
45 | |||
47 | def on_click(self, callback, remove=False): |
|
46 | def on_click(self, callback, remove=False): |
General Comments 0
You need to be logged in to leave comments.
Login now