##// END OF EJS Templates
Refactoring of the output and display system....
Brian Granger -
Show More
@@ -29,7 +29,7 time, mark, audio, video {
29 29 margin: 0;
30 30 padding: 0;
31 31 border: 0;
32 font-size: 100%;
32 /* font-size: 100%;*/
33 33 font: inherit;
34 34 vertical-align: baseline;
35 35 }
@@ -62,12 +62,16 input, select { vertical-align: middle; }
62 62 en.wikipedia.org/wiki/MediaWiki_talk:Common.css/Archive_11#Teletype_style_fix_for_Chrome */
63 63 pre, code, kbd, samp { font-family: monospace, sans-serif; }
64 64
65
65 pre {
66 text-align: left;
67 font-family: Monaco, Consolas, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
68 font-size: 12pt;
69 }
66 70
67 71 body {
68 72 background-color: white;
69 font-size: 11pt;
70
73 /* This won't propagate to all children so we also set it below */
74 font-size: 12pt;
71 75 /* This makes sure that the body covers the entire window and needs to
72 76 be in a different element than the display: box in wrapper below */
73 77 position: absolute;
@@ -79,12 +83,11 body {
79 83
80 84 div#wrapper {
81 85 display: box;
82 box-orient: vertical;
83
84 86 display: -webkit-box;
85 -webkit-box-orient: vertical;
86
87 87 display: -moz-box;
88
89 box-orient: vertical;
90 -webkit-box-orient: vertical;
88 91 -moz-box-orient: vertical;
89 92
90 93 /* This is needed to make sure the wrapper fills the body */
@@ -104,7 +107,7 span#ipython_notebook h1 {
104 107 }
105 108
106 109 div#tools {
107 font-size: 10pt;
110 font-size: 11pt;
108 111 }
109 112
110 113 span#kernel_status {
@@ -134,9 +137,8 div.notebook {
134 137 overflow-y: auto;
135 138 overflow-x: hidden;
136 139 padding: 5px;
137 /* padding-top: 5px;*/
138 /* padding-bottom: 5px;*/
139 140 background-color: white;
141 font-size: 12pt;
140 142
141 143 /* Allow the notebook div to take up the rest of the vertical space */
142 144 box-flex: 1;
@@ -152,10 +154,18 div.cell {
152 154 width: 100%;
153 155 padding: 5px;
154 156 position: relative;
155 display: table;
157
156 158 box-sizing: border-box;
157 159 -moz-box-sizing: border-box;
158 160 -webkit-box-sizing: border-box;
161
162 display: box;
163 display: -webkit-box;
164 display: -moz-box;
165
166 box-orient: vertical;
167 -webkit-box-orient: vertical;
168 -moz-box-orient: vertical;
159 169 }
160 170
161 171 div.code_cell {
@@ -163,24 +173,19 div.code_cell {
163 173 }
164 174
165 175 div.prompt {
166 vertical-align: top;
167 display: table-cell;
168 width: 80px;
176 width: 90px;
169 177 padding: 0px;
170 178 margin: 0px;
171 179 font-family: Monaco, Consolas, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
172 font-weight: normal;
173 font-style: normal;
174 180 }
175 181
176 182 div.input {
177 183 display: box;
178 box-orient: horizontal;
179
180 184 display: -webkit-box;
181 -webkit-box-orient: horizontal;
182
183 185 display: -moz-box;
186
187 box-orient: horizontal;
188 -webkit-box-orient: horizontal;
184 189 -moz-box-orient: horizontal;
185 190 }
186 191
@@ -192,6 +197,7 div.input_area {
192 197 box-flex: 1;
193 198 -webkit-box-flex: 1;
194 199 -moz-box-flex: 1;
200
195 201 box-sizing: border-box;
196 202 -moz-box-sizing: border-box;
197 203 -webkit-box-sizing: border-box;
@@ -201,9 +207,8 textarea.input_textarea {
201 207 width: 100%;
202 208 text-align: left;
203 209 font-family: Monaco, Consolas, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
204 font-size: inherit;
210 font-size: 12pt;
205 211 border-style: none;
206 display: table-cell;
207 212 padding: 0px;
208 213 margin: 0px;
209 214 overflow: auto;
@@ -213,12 +218,21 textarea.input_textarea {
213 218
214 219 div.output {
215 220 display: box;
216 box-orient: horizontal;
217
218 221 display: -webkit-box;
219 -webkit-box-orient: horizontal;
222 display: -moz-box;
220 223
224 box-orient: vertical;
225 -webkit-box-orient: vertical;
226 -moz-box-orient: vertical;
227 }
228
229 div.output_pyout {
230 display: box;
231 display: -webkit-box;
221 232 display: -moz-box;
233
234 box-orient: horizontal;
235 -webkit-box-orient: horizontal;
222 236 -moz-box-orient: horizontal;
223 237 }
224 238
@@ -228,8 +242,19 div.output_prompt {
228 242
229 243 div.output_area {
230 244 text-align: left;
245 color: black;
231 246 font-family: Monaco, Consolas, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
232 display: table-cell;
247 font-size: 12pt;
248 }
249
250 div.output_latex {
251 font-size: 13pt;
252 }
253
254 .box_flex1 {
255 box-flex: 1;
256 -webkit-box-flex: 1;
257 -moz-box-flex: 1;
233 258 }
234 259
235 260 div.text_cell {
@@ -237,8 +262,10 div.text_cell {
237 262 }
238 263
239 264 textarea.text_cell_input {
240 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
241 font-size: 12pt;
265 font-family: Monaco, Consolas, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
266 /* font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;*/
267 /* Slightly bigger than the rest of the notebook */
268 font-size: 13pt;
242 269 outline: none;
243 270 resize: none;
244 271 width: inherit;
@@ -250,7 +277,8 textarea.text_cell_input {
250 277
251 278 div.text_cell_render {
252 279 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
253 font-size: 12pt;
280 /* Slightly bigger than the rest of the notebook */
281 font-size: 13pt;
254 282 outline: none;
255 283 resize: none;
256 284 width: inherit;
@@ -103,7 +103,6 Notebook.prototype.bind_events = function () {
103 103 if (cell instanceof CodeCell) {
104 104 event.preventDefault();
105 105 cell.clear_output();
106 cell.hide_output_prompt();
107 106 var code = cell.get_code();
108 107 if (that.notebook_load_re.test(code)) {
109 108 var code_parts = code.split(' ');
@@ -442,7 +441,7 Notebook.prototype._kernel_started = function () {
442 441 var msg_type = reply.msg_type;
443 442 var cell = that.cell_for_msg(reply.parent_header.msg_id);
444 443 if (msg_type === "execute_reply") {
445 cell.set_prompt(reply.content.execution_count);
444 cell.set_input_prompt(reply.content.execution_count);
446 445 };
447 446 };
448 447
@@ -454,10 +453,12 Notebook.prototype._kernel_started = function () {
454 453 if (msg_type === "stream") {
455 454 cell.expand();
456 455 cell.append_stream(reply.content.data + "\n");
457 } else if (msg_type === "pyout" || msg_type === "display_data") {
458 cell.show_output_prompt();
456 } else if (msg_type === "display_data") {
459 457 cell.expand();
460 458 cell.append_display_data(reply.content.data);
459 } else if (msg_type === "pyout") {
460 cell.expand();
461 cell.append_pyout(reply.content.data, reply.content.execution_count)
461 462 } else if (msg_type === "status") {
462 463 if (reply.content.execution_state === "busy") {
463 464 that.kernel.status_busy();
@@ -469,11 +470,6 Notebook.prototype._kernel_started = function () {
469 470 };
470 471
471 472
472 Notebook.prototype._handle_execute_reply = function (reply, cell) {
473 cell.set_prompt(reply.content.execution_count);
474 };
475
476
477 473 // Persistance and loading
478 474
479 475
@@ -624,7 +620,6 Cell.prototype.create_element = function () {};
624 620 var CodeCell = function (notebook) {
625 621 Cell.apply(this, arguments);
626 622 this.input_prompt_number = ' ';
627 this.output_prompt_number = ' ';
628 623 };
629 624
630 625
@@ -638,46 +633,77 CodeCell.prototype.create_element = function () {
638 633 var input_textarea = $('<textarea/>').addClass('input_textarea').attr('rows',1).attr('wrap','hard').autogrow();
639 634 input.append($('<div/>').addClass('input_area').append(input_textarea));
640 635 var output = $('<div></div>').addClass('output');
641 output.append($('<div/>').addClass('prompt output_prompt'));
642 output.append($('<div/>').addClass('output_area'));
643 636 cell.append(input).append(output);
644 637 this.element = cell;
645 638 this.collapse()
646 639 };
647 640
648 641
649 CodeCell.prototype.append_stream = function (data) {
650 var data_list = data.split("\n");
651 console.log(data_list);
652 if (data_list.length > 0) {
653 for (var i=0; i<data_list.length; i++) {
654 console.log(i, data_list[i]);
655 var toinsert = $("<div/>").
656 append(
657 $("<pre/>").append(fixConsole(data_list[i]))
658 );
659 this.element.find("div.output_area").append(toinsert);
660 };
661 }
642 CodeCell.prototype.append_pyout = function (data, n) {
643 var toinsert = $("<div/>").addClass("output_area output_pyout");
644 toinsert.append($('<div/>').
645 addClass('prompt output_prompt').
646 html('Out[' + n + ']:')
647 );
648 this.append_display_data(data, toinsert);
649 toinsert.children().last().addClass("box_flex1");
650 this.element.find("div.output").append(toinsert);
651 // If we just output latex, typeset it.
652 if (data["text/latex"] !== undefined) {
653 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
654 };
662 655 };
663 656
664 657
665 CodeCell.prototype.append_display_data = function (data) {
666 if (data["image/svg+xml"] !== undefined) {
667 this.append_svg(data["image/svg+xml"]);
658 CodeCell.prototype.append_display_data = function (data, element) {
659 if (data["text/latex"] !== undefined) {
660 this.append_latex(data["text/latex"], element);
661 // If it is undefined, then we just appended to div.output, which
662 // makes the latex visible and we can typeset it. The typesetting
663 // has to be done after the latex is on the page.
664 if (element === undefined) {
665 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
666 };
667 } else if (data["image/svg+xml"] !== undefined) {
668 this.append_svg(data["image/svg+xml"], element);
668 669 } else if (data["text/plain"] !== undefined) {
669 console.log(data["text/plain"]);
670 this.append_stream(data["text/plain"]);
670 this.append_stream(data["text/plain"], element);
671 671 };
672 return element;
672 673 };
673 674
674 CodeCell.prototype.append_svg = function (svg) {
675 this.element.find("div.output_area").append(svg);
675
676 CodeCell.prototype.append_stream = function (data, element) {
677 element = element || this.element.find("div.output");
678 var toinsert = $("<div/>").addClass("output_area output_stream");
679 toinsert.append($("<pre/>").html(fixConsole(data)));
680 element.append(toinsert);
681 return element;
676 682 };
677 683
678 684
685 CodeCell.prototype.append_svg = function (svg, element) {
686 element = element || this.element.find("div.output");
687 var toinsert = $("<div/>").addClass("output_area output_svg");
688 toinsert.append(svg);
689 element.append(toinsert);
690 return element;
691 };
692
693
694 CodeCell.prototype.append_latex = function (latex, element) {
695 // This method cannot do the typesetting because the latex first has to
696 // be on the page.
697 element = element || this.element.find("div.output");
698 var toinsert = $("<div/>").addClass("output_area output_latex");
699 toinsert.append(latex);
700 element.append(toinsert);
701 return element;
702 }
703
704
679 705 CodeCell.prototype.clear_output = function () {
680 this.element.find("div.output_area").html("");
706 this.element.find("div.output").html("");
681 707 };
682 708
683 709
@@ -691,11 +717,6 CodeCell.prototype.expand = function () {
691 717 };
692 718
693 719
694 CodeCell.prototype.set_prompt = function (number) {
695 this.set_input_prompt(number);
696 this.set_output_prompt(number);
697 };
698
699 720 CodeCell.prototype.set_input_prompt = function (number) {
700 721 var n = number || ' ';
701 722 this.input_prompt_number = n
@@ -703,23 +724,6 CodeCell.prototype.set_input_prompt = function (number) {
703 724 };
704 725
705 726
706 CodeCell.prototype.set_output_prompt = function (number) {
707 var n = number || ' ';
708 this.output_prompt_number = n
709 this.element.find('div.output_prompt').html('Out[' + n + ']:');
710 };
711
712
713 CodeCell.prototype.hide_output_prompt = function () {
714 this.element.find('div.output_prompt').hide();
715 };
716
717
718 CodeCell.prototype.show_output_prompt = function () {
719 this.element.find('div.output_prompt').show();
720 };
721
722
723 727 CodeCell.prototype.get_code = function () {
724 728 return this.element.find("textarea.input_textarea").val();
725 729 };
@@ -962,7 +966,8 $(document).ready(function () {
962 966 tex2jax: {
963 967 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
964 968 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
965 }
969 },
970 displayAlign: 'left' // Change this to 'center' to center equations.
966 971 });
967 972
968 973 IPYTHON.notebook = new Notebook('div.notebook');
General Comments 0
You need to be logged in to leave comments. Login now