Show More
@@ -8,6 +8,12 b'' | |||
|
8 | 8 | //============================================================================ |
|
9 | 9 | // CodeCell |
|
10 | 10 | //============================================================================ |
|
11 | /** | |
|
12 | * An extendable module that provide base functionnality to create cell for notebook. | |
|
13 | * @module IPython | |
|
14 | * @namespace IPython | |
|
15 | * @submodule CodeCell | |
|
16 | */ | |
|
11 | 17 | |
|
12 | 18 | var IPython = (function (IPython) { |
|
13 | 19 | "use strict"; |
@@ -16,9 +22,18 b' var IPython = (function (IPython) {' | |||
|
16 | 22 | var key = IPython.utils.keycodes; |
|
17 | 23 | CodeMirror.modeURL = "/static/codemirror/mode/%N/%N.js"; |
|
18 | 24 | |
|
25 | /** | |
|
26 | * A Cell conceived to write code. | |
|
27 | * | |
|
28 | * The kernel doesn't have to be set at creation time, in that case | |
|
29 | * it will be null and set_kernel has to be called later. | |
|
30 | * @class CodeCell | |
|
31 | * @extends IPython.Cell | |
|
32 | * | |
|
33 | * @constructor | |
|
34 | * @param {Object|null} kernel | |
|
35 | */ | |
|
19 | 36 | var CodeCell = function (kernel) { |
|
20 | // The kernel doesn't have to be set at creation time, in that case | |
|
21 | // it will be null and set_kernel has to be called later. | |
|
22 | 37 | this.kernel = kernel || null; |
|
23 | 38 | this.code_mirror = null; |
|
24 | 39 | this.input_prompt_number = null; |
@@ -36,11 +51,14 b' var IPython = (function (IPython) {' | |||
|
36 | 51 | |
|
37 | 52 | CodeCell.prototype = new IPython.Cell(); |
|
38 | 53 | |
|
39 | ||
|
54 | /** | |
|
55 | * @method auto_highlight | |
|
56 | */ | |
|
40 | 57 | CodeCell.prototype.auto_highlight = function () { |
|
41 | 58 | this._auto_highlight(IPython.config.cell_magic_highlight) |
|
42 | 59 | }; |
|
43 | 60 | |
|
61 | /** @method create_element */ | |
|
44 | 62 | CodeCell.prototype.create_element = function () { |
|
45 | 63 | var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox'); |
|
46 | 64 | cell.attr('tabindex','2'); |
@@ -69,11 +87,14 b' var IPython = (function (IPython) {' | |||
|
69 | 87 | } |
|
70 | 88 | }; |
|
71 | 89 | |
|
90 | /** | |
|
91 | * This method gets called in CodeMirror's onKeyDown/onKeyPress | |
|
92 | * handlers and is used to provide custom key handling. Its return | |
|
93 | * value is used to determine if CodeMirror should ignore the event: | |
|
94 | * true = ignore, false = don't ignore. | |
|
95 | * @method handle_codemirror_keyevent | |
|
96 | */ | |
|
72 | 97 | CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
73 | // This method gets called in CodeMirror's onKeyDown/onKeyPress | |
|
74 | // handlers and is used to provide custom key handling. Its return | |
|
75 | // value is used to determine if CodeMirror should ignore the event: | |
|
76 | // true = ignore, false = don't ignore. | |
|
77 | 98 | |
|
78 | 99 | if (this.read_only){ |
|
79 | 100 | return false; |
@@ -155,7 +176,10 b' var IPython = (function (IPython) {' | |||
|
155 | 176 | this.kernel = kernel; |
|
156 | 177 | } |
|
157 | 178 | |
|
158 | ||
|
179 | /** | |
|
180 | * Execute current code cell to the kernel | |
|
181 | * @method execute | |
|
182 | */ | |
|
159 | 183 | CodeCell.prototype.execute = function () { |
|
160 | 184 | this.output_area.clear_output(true, true, true); |
|
161 | 185 | this.set_input_prompt('*'); |
@@ -169,7 +193,10 b' var IPython = (function (IPython) {' | |||
|
169 | 193 | var msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false}); |
|
170 | 194 | }; |
|
171 | 195 | |
|
172 | ||
|
196 | /** | |
|
197 | * @method _handle_execute_reply | |
|
198 | * @private | |
|
199 | */ | |
|
173 | 200 | CodeCell.prototype._handle_execute_reply = function (content) { |
|
174 | 201 | this.set_input_prompt(content.execution_count); |
|
175 | 202 | this.element.removeClass("running"); |
@@ -226,20 +253,17 b' var IPython = (function (IPython) {' | |||
|
226 | 253 | }; |
|
227 | 254 | |
|
228 | 255 | |
|
229 | ||
|
230 | ||
|
231 | ||
|
232 | 256 | CodeCell.input_prompt_classical = function (prompt_value, lines_number) { |
|
233 | 257 | var ns = prompt_value || " "; |
|
234 | 258 | return 'In [' + ns + ']:' |
|
235 | 259 | }; |
|
236 | ||
|
260 | ||
|
237 | 261 | CodeCell.input_prompt_continuation = function (prompt_value, lines_number) { |
|
238 | 262 | var html = [CodeCell.input_prompt_classical(prompt_value, lines_number)]; |
|
239 | 263 | for(var i=1; i < lines_number; i++){html.push(['...:'])}; |
|
240 | 264 | return html.join('</br>') |
|
241 | 265 | }; |
|
242 | ||
|
266 | ||
|
243 | 267 | CodeCell.input_prompt_function = CodeCell.input_prompt_classical; |
|
244 | 268 | |
|
245 | 269 |
@@ -9,12 +9,22 b'' | |||
|
9 | 9 | // Kernel |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | /** | |
|
13 | * An extendable module that provide base functionnality to create cell for notebook. | |
|
14 | * @module IPython | |
|
15 | * @namespace IPython | |
|
16 | * @submodule Kernel | |
|
17 | */ | |
|
18 | ||
|
12 | 19 | var IPython = (function (IPython) { |
|
13 | 20 | |
|
14 | 21 | var utils = IPython.utils; |
|
15 | 22 | |
|
16 | 23 | // Initialization and connection. |
|
17 | ||
|
24 | /** | |
|
25 | * A Kernel Class to communicate with the Python kernel | |
|
26 | * @Class Kernel | |
|
27 | */ | |
|
18 | 28 | var Kernel = function (base_url) { |
|
19 | 29 | this.kernel_id = null; |
|
20 | 30 | this.shell_channel = null; |
@@ -50,6 +60,10 b' var IPython = (function (IPython) {' | |||
|
50 | 60 | return msg; |
|
51 | 61 | }; |
|
52 | 62 | |
|
63 | /** | |
|
64 | * Start the Python kernel | |
|
65 | * @method start | |
|
66 | */ | |
|
53 | 67 | Kernel.prototype.start = function (notebook_id) { |
|
54 | 68 | var that = this; |
|
55 | 69 | if (!this.running) { |
@@ -62,7 +76,14 b' var IPython = (function (IPython) {' | |||
|
62 | 76 | }; |
|
63 | 77 | }; |
|
64 | 78 | |
|
65 | ||
|
79 | /** | |
|
80 | * Restart the python kernel. | |
|
81 | * | |
|
82 | * Emit a 'status_restarting.Kernel' event with | |
|
83 | * the current object as parameter | |
|
84 | * | |
|
85 | * @method restart | |
|
86 | */ | |
|
66 | 87 | Kernel.prototype.restart = function () { |
|
67 | 88 | $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); |
|
68 | 89 | var that = this; |
@@ -122,6 +143,12 b' var IPython = (function (IPython) {' | |||
|
122 | 143 | |
|
123 | 144 | }; |
|
124 | 145 | |
|
146 | /** | |
|
147 | * Start the `shell`and `iopub` channels. | |
|
148 | * Will stop and restart them if they already exist. | |
|
149 | * | |
|
150 | * @method start_channels | |
|
151 | */ | |
|
125 | 152 | Kernel.prototype.start_channels = function () { |
|
126 | 153 | var that = this; |
|
127 | 154 | this.stop_channels(); |
@@ -162,7 +189,10 b' var IPython = (function (IPython) {' | |||
|
162 | 189 | }, 1000); |
|
163 | 190 | }; |
|
164 | 191 | |
|
165 | ||
|
192 | /** | |
|
193 | * Start the `shell`and `iopub` channels. | |
|
194 | * @method stop_channels | |
|
195 | */ | |
|
166 | 196 | Kernel.prototype.stop_channels = function () { |
|
167 | 197 | if (this.shell_channel !== null) { |
|
168 | 198 | this.shell_channel.onclose = function (evt) {}; |
@@ -178,17 +208,28 b' var IPython = (function (IPython) {' | |||
|
178 | 208 | |
|
179 | 209 | // Main public methods. |
|
180 | 210 | |
|
211 | /** | |
|
212 | * Get info on object asynchronoulsy | |
|
213 | * | |
|
214 | * @async | |
|
215 | * @param objname {string} | |
|
216 | * @param callback {dict} | |
|
217 | * @method object_info_request | |
|
218 | * | |
|
219 | * @example | |
|
220 | * | |
|
221 | * When calling this method pass a callbacks structure of the form: | |
|
222 | * | |
|
223 | * callbacks = { | |
|
224 | * 'object_info_reply': object_info_reply_callback | |
|
225 | * } | |
|
226 | * | |
|
227 | * The `object_info_reply_callback` will be passed the content object of the | |
|
228 | * | |
|
229 | * `object_into_reply` message documented in | |
|
230 | * [IPython dev documentation](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information) | |
|
231 | */ | |
|
181 | 232 | Kernel.prototype.object_info_request = function (objname, callbacks) { |
|
182 | // When calling this method pass a callbacks structure of the form: | |
|
183 | // | |
|
184 | // callbacks = { | |
|
185 | // 'object_info_reply': object_into_reply_callback | |
|
186 | // } | |
|
187 | // | |
|
188 | // The object_info_reply_callback will be passed the content object of the | |
|
189 | // object_into_reply message documented here: | |
|
190 | // | |
|
191 | // http://ipython.org/ipython-doc/dev/development/messaging.html#object-information | |
|
192 | 233 | if(typeof(objname)!=null && objname!=null) |
|
193 | 234 | { |
|
194 | 235 | var content = { |
@@ -202,42 +243,61 b' var IPython = (function (IPython) {' | |||
|
202 | 243 | return; |
|
203 | 244 | } |
|
204 | 245 | |
|
246 | /** | |
|
247 | * Execute given code into kernel, and pass result to callback. | |
|
248 | * | |
|
249 | * @async | |
|
250 | * @method execute | |
|
251 | * @param {string} code | |
|
252 | * @param callback {Object} With the following keys | |
|
253 | * @param callback.'execute_reply' {function} | |
|
254 | * @param callback.'output' {function} | |
|
255 | * @param callback.'clear_output' {function} | |
|
256 | * @param callback.'set_next_input' {function} | |
|
257 | * @param {object} [options] | |
|
258 | * @param [options.silent=false] {Boolean} | |
|
259 | * @param [options.user_expressions=empty_dict] {Dict} | |
|
260 | * @param [options.user_variables=empty_list] {List od Strings} | |
|
261 | * @param [options.allow_stdin=false] {Boolean} true|false | |
|
262 | * | |
|
263 | * @example | |
|
264 | * | |
|
265 | * The options object should contain the options for the execute call. Its default | |
|
266 | * values are: | |
|
267 | * | |
|
268 | * options = { | |
|
269 | * silent : true, | |
|
270 | * user_variables : [], | |
|
271 | * user_expressions : {}, | |
|
272 | * allow_stdin : false | |
|
273 | * } | |
|
274 | * | |
|
275 | * When calling this method pass a callbacks structure of the form: | |
|
276 | * | |
|
277 | * callbacks = { | |
|
278 | * 'execute_reply': execute_reply_callback, | |
|
279 | * 'output': output_callback, | |
|
280 | * 'clear_output': clear_output_callback, | |
|
281 | * 'set_next_input': set_next_input_callback | |
|
282 | * } | |
|
283 | * | |
|
284 | * The `execute_reply_callback` will be passed the content and metadata | |
|
285 | * objects of the `execute_reply` message documented | |
|
286 | * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#execute) | |
|
287 | * | |
|
288 | * The `output_callback` will be passed `msg_type` ('stream','display_data','pyout','pyerr') | |
|
289 | * of the output and the content and metadata objects of the PUB/SUB channel that contains the | |
|
290 | * output: | |
|
291 | * | |
|
292 | * http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket | |
|
293 | * | |
|
294 | * The `clear_output_callback` will be passed a content object that contains | |
|
295 | * stdout, stderr and other fields that are booleans, as well as the metadata object. | |
|
296 | * | |
|
297 | * The `set_next_input_callback` will be passed the text that should become the next | |
|
298 | * input cell. | |
|
299 | */ | |
|
205 | 300 | Kernel.prototype.execute = function (code, callbacks, options) { |
|
206 | // The options object should contain the options for the execute call. Its default | |
|
207 | // values are: | |
|
208 | // | |
|
209 | // options = { | |
|
210 | // silent : true, | |
|
211 | // user_variables : [], | |
|
212 | // user_expressions : {}, | |
|
213 | // allow_stdin : false | |
|
214 | // } | |
|
215 | // | |
|
216 | // When calling this method pass a callbacks structure of the form: | |
|
217 | // | |
|
218 | // callbacks = { | |
|
219 | // 'execute_reply': execute_reply_callback, | |
|
220 | // 'output': output_callback, | |
|
221 | // 'clear_output': clear_output_callback, | |
|
222 | // 'set_next_input': set_next_input_callback | |
|
223 | // } | |
|
224 | // | |
|
225 | // The execute_reply_callback will be passed the content and metadata objects of the execute_reply | |
|
226 | // message documented here: | |
|
227 | // | |
|
228 | // http://ipython.org/ipython-doc/dev/development/messaging.html#execute | |
|
229 | // | |
|
230 | // The output_callback will be passed msg_type ('stream','display_data','pyout','pyerr') | |
|
231 | // of the output and the content and metadata objects of the PUB/SUB channel that contains the | |
|
232 | // output: | |
|
233 | // | |
|
234 | // http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket | |
|
235 | // | |
|
236 | // The clear_output_callback will be passed a content object that contains | |
|
237 | // stdout, stderr and other fields that are booleans, as well as the metadata object. | |
|
238 | // | |
|
239 | // The set_next_input_callback will be passed the text that should become the next | |
|
240 | // input cell. | |
|
241 | 301 | |
|
242 | 302 | var content = { |
|
243 | 303 | code : code, |
@@ -254,18 +314,25 b' var IPython = (function (IPython) {' | |||
|
254 | 314 | return msg.header.msg_id; |
|
255 | 315 | }; |
|
256 | 316 | |
|
257 | ||
|
317 | /** | |
|
318 | * When calling this method pass a callbacks structure of the form: | |
|
319 | * | |
|
320 | * callbacks = { | |
|
321 | * 'complete_reply': complete_reply_callback | |
|
322 | * } | |
|
323 | * | |
|
324 | * The `complete_reply_callback` will be passed the content object of the | |
|
325 | * `complete_reply` message documented | |
|
326 | * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#complete) | |
|
327 | * | |
|
328 | * @method complete | |
|
329 | * @param line {integer} | |
|
330 | * @param cursor_pos {integer} | |
|
331 | * @param {dict} callbacks | |
|
332 | * @param callbacks.complete_reply {function} `complete_reply_callback` | |
|
333 | * | |
|
334 | */ | |
|
258 | 335 | Kernel.prototype.complete = function (line, cursor_pos, callbacks) { |
|
259 | // When calling this method pass a callbacks structure of the form: | |
|
260 | // | |
|
261 | // callbacks = { | |
|
262 | // 'complete_reply': complete_reply_callback | |
|
263 | // } | |
|
264 | // | |
|
265 | // The complete_reply_callback will be passed the content object of the | |
|
266 | // complete_reply message documented here: | |
|
267 | // | |
|
268 | // http://ipython.org/ipython-doc/dev/development/messaging.html#complete | |
|
269 | 336 | callbacks = callbacks || {}; |
|
270 | 337 | var content = { |
|
271 | 338 | text : '', |
@@ -25,7 +25,7 b' var IPython = (function (IPython) {' | |||
|
25 | 25 | * |
|
26 | 26 | * @class TextCell |
|
27 | 27 | * @constructor TextCell |
|
28 | * @extend Cell | |
|
28 | * @extend Ipython.Cell | |
|
29 | 29 | */ |
|
30 | 30 | var TextCell = function () { |
|
31 | 31 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
@@ -260,7 +260,7 b' var IPython = (function (IPython) {' | |||
|
260 | 260 | /** |
|
261 | 261 | * @constructor HtmlCell |
|
262 | 262 | * @class HtmlCell |
|
263 | * @extends TextCell | |
|
263 | * @extends Ipython.TextCell | |
|
264 | 264 | */ |
|
265 | 265 | var HTMLCell = function () { |
|
266 | 266 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; |
@@ -290,7 +290,7 b' var IPython = (function (IPython) {' | |||
|
290 | 290 | /** |
|
291 | 291 | * @class MarkdownCell |
|
292 | 292 | * @constructor MarkdownCell |
|
293 | * @extends HtmlCell | |
|
293 | * @extends Ipython.HtmlCell | |
|
294 | 294 | */ |
|
295 | 295 | var MarkdownCell = function () { |
|
296 | 296 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; |
@@ -345,7 +345,7 b' var IPython = (function (IPython) {' | |||
|
345 | 345 | /** |
|
346 | 346 | * @class RawCell |
|
347 | 347 | * @constructor RawCell |
|
348 | * @extends TextCell | |
|
348 | * @extends Ipython.TextCell | |
|
349 | 349 | */ |
|
350 | 350 | var RawCell = function () { |
|
351 | 351 | this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; |
@@ -434,12 +434,12 b' var IPython = (function (IPython) {' | |||
|
434 | 434 | |
|
435 | 435 | /** |
|
436 | 436 | * @class HeadingCell |
|
437 | * @extends TextCell | |
|
437 | * @extends Ipython.TextCell | |
|
438 | 438 | */ |
|
439 | 439 | |
|
440 | 440 | /** |
|
441 | 441 | * @constructor HeadingCell |
|
442 | * @extends TextCell | |
|
442 | * @extends Ipython.TextCell | |
|
443 | 443 | */ |
|
444 | 444 | var HeadingCell = function () { |
|
445 | 445 | this.placeholder = "Type Heading Here"; |
General Comments 0
You need to be logged in to leave comments.
Login now