Show More
@@ -36,6 +36,7 b' define(["components/underscore/underscore-min",' | |||
|
36 | 36 | this.msg_throttle = 3; |
|
37 | 37 | this.msg_buffer = null; |
|
38 | 38 | this.views = {}; |
|
39 | this._custom_msg_callbacks = []; | |
|
39 | 40 | |
|
40 | 41 | // Remember comm associated with the model. |
|
41 | 42 | this.comm = comm; |
@@ -64,16 +65,18 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 | 71 | // Used the last modified view as the sender of the message. This |
|
70 | 72 | // will insure that any python code triggered by the sent message |
|
71 | 73 | // can create and display widgets and output. |
|
72 |
|
|
|
74 | if (cell === undefined) { | |
|
73 | 75 | if (this.last_modified_view != undefined && |
|
74 | 76 | this.last_modified_view.cell != undefined) { |
|
75 | 77 | cell = this.last_modified_view.cell; |
|
76 | 78 | } |
|
79 | } | |
|
77 | 80 | var callbacks = this._make_callbacks(cell); |
|
78 | 81 | var data = {'custom_content': content}; |
|
79 | 82 | this.comm.send(data, callbacks); |
@@ -90,15 +93,29 b' define(["components/underscore/underscore-min",' | |||
|
90 | 93 | }, |
|
91 | 94 | |
|
92 | 95 | |
|
93 | on_msg: function (callback) { | |
|
94 | this._msg_callback = callback; | |
|
96 | on_msg: function (callback, remove) { | |
|
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 | 115 | _handle_custom_msg: function (content) { |
|
99 |
|
|
|
116 | for (var index in this._custom_msg_callbacks) { | |
|
100 | 117 | try { |
|
101 | this._msg_callback(content); | |
|
118 | this._custom_msg_callbacks[index](content); | |
|
102 | 119 | } catch (e) { |
|
103 | 120 | console.log("Exception in widget model msg callback", e, content); |
|
104 | 121 | } |
@@ -466,6 +483,11 b' define(["components/underscore/underscore-min",' | |||
|
466 | 483 | } |
|
467 | 484 | }, |
|
468 | 485 | |
|
486 | ||
|
487 | send: function(content) { | |
|
488 | this.model.send({event: 'click'}, this.cell); | |
|
489 | }, | |
|
490 | ||
|
469 | 491 | update: function() { |
|
470 | 492 | if (this.model.get('visible') != undefined) { |
|
471 | 493 | if (this.visible != this.model.get('visible')) { |
@@ -50,8 +50,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||
|
50 | 50 | }, |
|
51 | 51 | |
|
52 | 52 | _handle_click: function(){ |
|
53 | this.model.last_modified_view = this; // For callbacks. | |
|
54 | this.model.send({event: 'click'}); | |
|
53 | this.send({event: 'click'}); | |
|
55 | 54 | }, |
|
56 | 55 | }); |
|
57 | 56 |
@@ -53,8 +53,23 b' define(["notebook/js/widget"], function(widget_manager){' | |||
|
53 | 53 | .appendTo(this.$el); |
|
54 | 54 | this.$el_to_style = this.$textbox; // Set default element to style |
|
55 | 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 | }, |
|
57 | 71 | |
|
72 | ||
|
58 | 73 | // Handles: Backend -> Frontend Sync |
|
59 | 74 | // Frontent -> Frontend Sync |
|
60 | 75 |
update |
@@ -62,14 +77,6 b' define(["notebook/js/widget"], function(widget_manager){' | |||
|
62 | 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 | 80 | var disabled = this.model.get('disabled'); |
|
74 | 81 | this.$textbox.prop('disabled', disabled); |
|
75 | 82 | |
@@ -151,8 +158,7 b' define(["notebook/js/widget"], function(widget_manager){' | |||
|
151 | 158 | // Handles text submition |
|
152 | 159 | handleKeypress: function(e) { |
|
153 | 160 | if (e.keyCode == 13) { // Return key |
|
154 | this.model.last_modified_view = this; // For callbacks. | |
|
155 | this.model.send({event: 'submit'}); | |
|
161 | this.send({event: 'submit'}); | |
|
156 | 162 | } |
|
157 | 163 | }, |
|
158 | 164 | }); |
@@ -27,11 +27,10 b' class StringWidget(Widget):' | |||
|
27 | 27 | default_view_name = Unicode('TextBoxView') |
|
28 | 28 | |
|
29 | 29 | # Keys |
|
30 |
_keys = ['value', 'disabled', 'description' |
|
|
30 | _keys = ['value', 'disabled', 'description'] | |
|
31 | 31 | value = Unicode(help="String value") |
|
32 | 32 | disabled = Bool(False, help="Enable or disable user changes") |
|
33 | 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 | 36 | def __init__(self, **kwargs): |
@@ -41,7 +40,7 b' class StringWidget(Widget):' | |||
|
41 | 40 | |
|
42 | 41 | |
|
43 | 42 | def scroll_to_bottom(self): |
|
44 |
self. |
|
|
43 | self._comm.send({"method": "scroll_to_bottom"}) | |
|
45 | 44 | |
|
46 | 45 | |
|
47 | 46 | def on_click(self, callback, remove=False): |
General Comments 0
You need to be logged in to leave comments.
Login now