##// END OF EJS Templates
Handle unrecognized outputs and cells from the future
Min RK -
Show More
@@ -53,8 +53,10 b' define(['
53 53 get: function() { return that._metadata; },
54 54 set: function(value) {
55 55 that._metadata = value;
56 if (that.celltoolbar) {
56 57 that.celltoolbar.rebuild();
57 58 }
59 }
58 60 });
59 61
60 62 // load this from metadata later ?
@@ -194,10 +196,10 b' define(['
194 196 if((cur.line !== 0 || cur.ch !==0) && event.keyCode === 38){
195 197 event._ipkmIgnore = true;
196 198 }
197 var nLastLine = editor.lastLine()
198 if( ( event.keyCode === 40)
199 && (( cur.line !== nLastLine)
200 || ( cur.ch !== editor.getLineHandle(nLastLine).text.length))
199 var nLastLine = editor.lastLine();
200 if ((event.keyCode === 40) &&
201 ((cur.line !== nLastLine) ||
202 (cur.ch !== editor.getLineHandle(nLastLine).text.length))
201 203 ){
202 204 event._ipkmIgnore = true;
203 205 }
@@ -255,6 +257,14 b' define(['
255 257 };
256 258
257 259 /**
260 * should be overritten by subclass
261 * @method execute
262 */
263 Cell.prototype.execute = function () {
264 return;
265 };
266
267 /**
258 268 * handle cell level logic when a cell is rendered
259 269 * @method render
260 270 * @return is the action being taken
@@ -386,7 +396,9 b' define(['
386 396 * @method refresh
387 397 */
388 398 Cell.prototype.refresh = function () {
399 if (this.code_mirror) {
389 400 this.code_mirror.refresh();
401 }
390 402 };
391 403
392 404 /**
@@ -590,8 +602,61 b' define(['
590 602 this.code_mirror.setOption('mode', default_mode);
591 603 };
592 604
605 var UnrecognizedCell = function (options) {
606 /** Constructor for unrecognized cells */
607 Cell.apply(this, arguments);
608 this.cell_type = 'unrecognized';
609 this.celltoolbar = null;
610 this.data = {};
611
612 Object.seal(this);
613 };
614
615 UnrecognizedCell.prototype = Object.create(Cell.prototype);
616
617
618 // cannot merge or split unrecognized cells
619 UnrecognizedCell.prototype.is_mergeable = function () {
620 return false;
621 };
622
623 UnrecognizedCell.prototype.is_splittable = function () {
624 return false;
625 };
626
627 UnrecognizedCell.prototype.toJSON = function () {
628 // deepcopy the metadata so copied cells don't share the same object
629 return JSON.parse(JSON.stringify(this.data));
630 };
631
632 UnrecognizedCell.prototype.fromJSON = function (data) {
633 this.data = data;
634 if (data.metadata !== undefined) {
635 this.metadata = data.metadata;
636 } else {
637 data.metadata = this.metadata;
638 }
639 this.element.find('.inner_cell').text("Unrecognized cell type: " + data.cell_type);
640 };
641
642 UnrecognizedCell.prototype.create_element = function () {
643 Cell.prototype.create_element.apply(this, arguments);
644 var cell = this.element = $("<div>").addClass('cell unrecognized_cell');
645 cell.attr('tabindex','2');
646
647 var prompt = $('<div/>').addClass('prompt input_prompt');
648 cell.append(prompt);
649 var inner_cell = $('<div/>').addClass('inner_cell');
650 inner_cell.text("Unrecognized cell type");
651 cell.append(inner_cell);
652 this.element = cell;
653 };
654
593 655 // Backwards compatibility.
594 656 IPython.Cell = Cell;
595 657
596 return {'Cell': Cell};
658 return {
659 Cell: Cell,
660 UnrecognizedCell: UnrecognizedCell
661 };
597 662 });
@@ -6,6 +6,7 b' define(['
6 6 'jquery',
7 7 'base/js/utils',
8 8 'base/js/dialog',
9 'notebook/js/cell',
9 10 'notebook/js/textcell',
10 11 'notebook/js/codecell',
11 12 'services/sessions/session',
@@ -25,6 +26,7 b' define(['
25 26 $,
26 27 utils,
27 28 dialog,
29 cellmod,
28 30 textcell,
29 31 codecell,
30 32 session,
@@ -894,7 +896,8 b' define(['
894 896 cell = new textcell.RawCell(cell_options);
895 897 break;
896 898 default:
897 console.log("invalid cell type: ", type);
899 console.log("Unrecognized cell type: ", type, cellmod);
900 cell = new cellmod.UnrecognizedCell(cell_options);
898 901 }
899 902
900 903 if(this._insert_element_at_index(cell.element,index)) {
@@ -245,7 +245,7 b' define(['
245 245 'text/plain'
246 246 ];
247 247
248 OutputArea.prototype.validate_output = function (json) {
248 OutputArea.prototype.validate_mimebundle = function (json) {
249 249 // scrub invalid outputs
250 250 var data = json.data;
251 251 $.map(OutputArea.output_types, function(key){
@@ -263,11 +263,6 b' define(['
263 263 OutputArea.prototype.append_output = function (json) {
264 264 this.expand();
265 265
266 // validate output data types
267 if (json.data) {
268 json = this.validate_output(json);
269 }
270
271 266 // Clear the output if clear is queued.
272 267 var needs_height_reset = false;
273 268 if (this.clear_queued) {
@@ -276,14 +271,26 b' define(['
276 271 }
277 272
278 273 var record_output = true;
279
280 if (json.output_type === 'execute_result') {
274 console.log("appending", json);
275 switch(json.output_type) {
276 case 'execute_result':
277 json = this.validate_mimebundle(json);
281 278 this.append_execute_result(json);
282 } else if (json.output_type === 'error') {
283 this.append_error(json);
284 } else if (json.output_type === 'stream') {
279 break;
280 case 'stream':
285 281 // append_stream might have merged the output with earlier stream output
286 282 record_output = this.append_stream(json);
283 break;
284 case 'error':
285 this.append_error(json);
286 break;
287 case 'display_data':
288 // append handled below
289 json = this.validate_mimebundle(json);
290 break;
291 default:
292 console.log("unrecognized output type: " + json.output_type);
293 this.append_unrecognized(json);
287 294 }
288 295
289 296 // We must release the animation fixed height in a callback since Gecko
@@ -482,6 +489,15 b' define(['
482 489 };
483 490
484 491
492 OutputArea.prototype.append_unrecognized = function (json) {
493 var toinsert = this.create_output_area();
494 var subarea = $('<div/>').addClass('output_subarea output_unrecognized');
495 toinsert.append(subarea);
496 subarea.text("Unrecognized output: " + json.output_type);
497 this._safe_append(toinsert);
498 };
499
500
485 501 OutputArea.prototype.append_display_data = function (json, handle_inserted) {
486 502 var toinsert = this.create_output_area();
487 503 if (this.append_mime_type(json, toinsert, handle_inserted)) {
@@ -340,7 +340,7 b' define(['
340 340 var textcell = {
341 341 TextCell: TextCell,
342 342 MarkdownCell: MarkdownCell,
343 RawCell: RawCell,
343 RawCell: RawCell
344 344 };
345 345 return textcell;
346 346 });
@@ -61,3 +61,24 b' div.prompt:empty {'
61 61 padding-top: 0;
62 62 padding-bottom: 0;
63 63 }
64
65 div.unrecognized_cell {
66 // from text_cell
67 padding: 5px 5px 5px 0px;
68 .hbox();
69
70 .inner_cell {
71 .border-radius(@border-radius-base);
72 padding: 5px;
73 font-weight: bold;
74 color: red;
75 border: 1px solid @light_border_color;
76 background: darken(@cell_background, 5%);
77 }
78 }
79 @media (max-width: 480px) {
80 // remove prompt indentation on small screens
81 div.unrecognized_cell > div.prompt {
82 display: none;
83 }
84 }
@@ -172,3 +172,9 b' input.raw_input:focus {'
172 172 p.p-space {
173 173 margin-bottom: 10px;
174 174 }
175
176 div.output_unrecognized {
177 padding: 5px;
178 font-weight: bold;
179 color: red;
180 } No newline at end of file
@@ -419,6 +419,36 b' div.prompt:empty {'
419 419 padding-top: 0;
420 420 padding-bottom: 0;
421 421 }
422 div.unrecognized_cell {
423 padding: 5px 5px 5px 0px;
424 /* Old browsers */
425 display: -webkit-box;
426 -webkit-box-orient: horizontal;
427 -webkit-box-align: stretch;
428 display: -moz-box;
429 -moz-box-orient: horizontal;
430 -moz-box-align: stretch;
431 display: box;
432 box-orient: horizontal;
433 box-align: stretch;
434 /* Modern browsers */
435 display: flex;
436 flex-direction: row;
437 align-items: stretch;
438 }
439 div.unrecognized_cell .inner_cell {
440 border-radius: 4px;
441 padding: 5px;
442 font-weight: bold;
443 color: red;
444 border: 1px solid #cfcfcf;
445 background: #eaeaea;
446 }
447 @media (max-width: 480px) {
448 div.unrecognized_cell > div.prompt {
449 display: none;
450 }
451 }
422 452 /* any special styling for code cells that are currently running goes here */
423 453 div.input {
424 454 page-break-inside: avoid;
@@ -888,6 +918,12 b' input.raw_input:focus {'
888 918 p.p-space {
889 919 margin-bottom: 10px;
890 920 }
921 div.output_unrecognized {
922 border-radius: 4px;
923 padding: 5px;
924 font-weight: bold;
925 color: red;
926 }
891 927 .rendered_html {
892 928 color: #000000;
893 929 /* any extras will just be numbers: */
@@ -8288,6 +8288,36 b' div.prompt:empty {'
8288 8288 padding-top: 0;
8289 8289 padding-bottom: 0;
8290 8290 }
8291 div.unrecognized_cell {
8292 padding: 5px 5px 5px 0px;
8293 /* Old browsers */
8294 display: -webkit-box;
8295 -webkit-box-orient: horizontal;
8296 -webkit-box-align: stretch;
8297 display: -moz-box;
8298 -moz-box-orient: horizontal;
8299 -moz-box-align: stretch;
8300 display: box;
8301 box-orient: horizontal;
8302 box-align: stretch;
8303 /* Modern browsers */
8304 display: flex;
8305 flex-direction: row;
8306 align-items: stretch;
8307 }
8308 div.unrecognized_cell .inner_cell {
8309 border-radius: 4px;
8310 padding: 5px;
8311 font-weight: bold;
8312 color: red;
8313 border: 1px solid #cfcfcf;
8314 background: #eaeaea;
8315 }
8316 @media (max-width: 480px) {
8317 div.unrecognized_cell > div.prompt {
8318 display: none;
8319 }
8320 }
8291 8321 /* any special styling for code cells that are currently running goes here */
8292 8322 div.input {
8293 8323 page-break-inside: avoid;
@@ -8757,6 +8787,12 b' input.raw_input:focus {'
8757 8787 p.p-space {
8758 8788 margin-bottom: 10px;
8759 8789 }
8790 div.output_unrecognized {
8791 border-radius: 4px;
8792 padding: 5px;
8793 font-weight: bold;
8794 color: red;
8795 }
8760 8796 .rendered_html {
8761 8797 color: #000000;
8762 8798 /* any extras will just be numbers: */
General Comments 0
You need to be logged in to leave comments. Login now