##// END OF EJS Templates
small CSS adjustments in notebook...
MinRK -
Show More
@@ -1,324 +1,334
1
1
2 /**
2 /**
3 * Primary styles
3 * Primary styles
4 *
4 *
5 * Author: IPython Development Team
5 * Author: IPython Development Team
6 */
6 */
7
7
8
8
9 body {
9 body {
10 background-color: white;
10 background-color: white;
11 /* This makes sure that the body covers the entire window and needs to
11 /* This makes sure that the body covers the entire window and needs to
12 be in a different element than the display: box in wrapper below */
12 be in a different element than the display: box in wrapper below */
13 position: absolute;
13 position: absolute;
14 left: 0px;
14 left: 0px;
15 right: 0px;
15 right: 0px;
16 top: 0px;
16 top: 0px;
17 bottom: 0px;
17 bottom: 0px;
18 overflow: hidden;
18 overflow: hidden;
19 }
19 }
20
20
21 span#save_widget {
21 span#save_widget {
22 position: absolute;
22 position: absolute;
23 left: 0px;
23 left: 0px;
24 padding: 5px 0px;
24 padding: 5px 0px;
25 margin: 0px 0px 0px 0px;
25 margin: 0px 0px 0px 0px;
26 }
26 }
27
27
28 input#notebook_name {
28 input#notebook_name {
29 height: 1em;
29 height: 1em;
30 line-height: 1em;
30 line-height: 1em;
31 padding: 5px;
31 padding: 5px;
32 }
32 }
33
33
34 span#kernel_status {
34 span#kernel_status {
35 position: absolute;
35 position: absolute;
36 padding: 8px 5px 5px 5px;
36 padding: 8px 5px 5px 5px;
37 right: 10px;
37 right: 10px;
38 font-weight: bold;
38 font-weight: bold;
39 }
39 }
40
40
41 .status_idle {
41 .status_idle {
42 color: gray;
42 color: gray;
43 }
43 }
44
44
45 .status_busy {
45 .status_busy {
46 color: red;
46 color: red;
47 }
47 }
48
48
49 .status_restarting {
49 .status_restarting {
50 color: black;
50 color: black;
51 }
51 }
52
52
53 div#left_panel {
53 div#left_panel {
54 overflow-y: auto;
54 overflow-y: auto;
55 top: 0px;
55 top: 0px;
56 left: 0px;
56 left: 0px;
57 margin: 0px;
57 margin: 0px;
58 padding: 0px;
58 padding: 0px;
59 position: absolute;
59 position: absolute;
60 }
60 }
61
61
62 h3.section_header {
62 h3.section_header {
63 padding: 5px;
63 padding: 5px;
64 }
64 }
65
65
66 div.section_content {
66 div.section_content {
67 padding: 5px;
67 padding: 5px;
68 }
68 }
69
69
70 span.section_row_buttons button {
70 span.section_row_buttons button {
71 width: 70px;
71 width: 70px;
72 }
72 }
73
73
74 span.section_row_buttons a {
74 span.section_row_buttons a {
75 width: 70px;
75 width: 70px;
76 }
76 }
77
77
78 .section_row {
78 .section_row {
79 margin: 5px 0px;
79 margin: 5px 0px;
80 }
80 }
81
81
82 .section_row_buttons {
82 .section_row_buttons {
83 float: right;
83 float: right;
84 }
84 }
85
85
86 #kernel_persist {
86 #kernel_persist {
87 float: right;
87 float: right;
88 }
88 }
89
89
90 .help_string {
90 .help_string {
91 float: right;
91 float: right;
92 width: 170px;
92 width: 170px;
93 padding: 0px 5px;
93 padding: 0px 5px;
94 text-align: left;
94 text-align: left;
95 font-size: 85%;
95 font-size: 85%;
96 }
96 }
97
97
98 .help_string_label {
98 .help_string_label {
99 float: right;
99 float: right;
100 font-size: 85%;
100 font-size: 85%;
101 }
101 }
102
102
103 #autoindent_span {
103 #autoindent_span {
104 float: right;
104 float: right;
105 }
105 }
106
106
107 .checkbox_label {
107 .checkbox_label {
108 font-size: 85%;
108 font-size: 85%;
109 float: right;
109 float: right;
110 padding: 0.3em;
110 padding: 0.3em;
111 }
111 }
112
112
113 .section_row_header {
113 .section_row_header {
114 float: left;
114 float: left;
115 font-size: 85%;
115 font-size: 85%;
116 padding: 0.4em 0em;
116 padding: 0.4em 0em;
117 font-weight: bold;
117 font-weight: bold;
118 }
118 }
119
119
120 span.button_label {
120 span.button_label {
121 padding: 0.2em 1em;
121 padding: 0.2em 1em;
122 font-size: 77%;
122 font-size: 77%;
123 float: right;
123 float: right;
124 }
124 }
125
125
126 /* This is needed because FF was adding a 2px margin top and bottom. */
126 /* This is needed because FF was adding a 2px margin top and bottom. */
127 .section_row .ui-button {
127 .section_row .ui-button {
128 margin-top: 0px;
128 margin-top: 0px;
129 margin-bottom: 0px;
129 margin-bottom: 0px;
130 }
130 }
131
131
132 #download_format {
132 #download_format {
133 float: right;
133 float: right;
134 font-size: 85%;
134 font-size: 85%;
135 width: 62px;
135 width: 62px;
136 margin: 1px 5px;
136 margin: 1px 5px;
137 }
137 }
138
138
139 div#left_panel_splitter {
139 div#left_panel_splitter {
140 width: 8px;
140 width: 8px;
141 top: 0px;
141 top: 0px;
142 left: 202px;
142 left: 202px;
143 margin: 0px;
143 margin: 0px;
144 padding: 0px;
144 padding: 0px;
145 position: absolute;
145 position: absolute;
146 }
146 }
147
147
148 div#notebook_panel {
148 div#notebook_panel {
149 /* The L margin will be set in the Javascript code*/
149 /* The L margin will be set in the Javascript code*/
150 margin: 0px 0px 0px 0px;
150 margin: 0px 0px 0px 0px;
151 padding: 0px;
151 padding: 0px;
152 }
152 }
153
153
154 div#notebook {
154 div#notebook {
155 overflow-y: scroll;
155 overflow-y: scroll;
156 overflow-x: auto;
156 overflow-x: auto;
157 width: 100%;
157 width: 100%;
158 /* This spaces the cell away from the edge of the notebook area */
158 /* This spaces the cell away from the edge of the notebook area */
159 padding: 15px 15px 15px 15px;
159 padding: 15px 15px 15px 15px;
160 margin: 0px
160 margin: 0px
161 background-color: white;
161 background-color: white;
162 }
162 }
163
163
164 div#pager_splitter {
164 div#pager_splitter {
165 height: 8px;
165 height: 8px;
166 }
166 }
167
167
168 div#pager {
168 div#pager {
169 padding: 15px;
169 padding: 15px;
170 overflow: auto;
170 overflow: auto;
171 }
171 }
172
172
173 div.cell {
173 div.cell {
174 width: 100%;
174 width: 100%;
175 padding: 5px;
175 padding: 5px;
176 /* This acts as a spacer between cells, that is outside the border */
176 /* This acts as a spacer between cells, that is outside the border */
177 margin: 5px 0px 5px 0px;
177 margin: 5px 0px 5px 0px;
178 }
178 }
179
179
180 div.code_cell {
180 div.code_cell {
181 background-color: white;
181 background-color: white;
182 }
182 }
183
183
184 div.prompt {
184 div.prompt {
185 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
185 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
186 width: 11ex;
186 width: 11ex;
187 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
187 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
188 padding: 0.4em;
188 padding: 0.4em;
189 margin: 0px;
189 margin: 0px;
190 font-family: monospace;
190 font-family: monospace;
191 text-align:right;
191 text-align:right;
192 }
192 }
193
193
194 div.input {
194 div.input {
195 page-break-inside: avoid;
195 page-break-inside: avoid;
196 }
196 }
197
197
198 div.input_area {
198 div.input_area {
199 color: black;
199 color: black;
200 border: 1px solid #ddd;
200 }
201 }
201
202
202 div.input_prompt {
203 div.input_prompt {
203 color: navy;
204 color: navy;
204 }
205 }
205
206
206 div.output {
207 div.output {
207 /* This is a spacer between the input and output of each cell */
208 /* This is a spacer between the input and output of each cell */
208 margin-top: 5px;
209 margin-top: 5px;
209 }
210 }
210
211
211 div.output_prompt {
212 div.output_prompt {
212 color: darkred;
213 color: darkred;
213 }
214 }
214
215
215 /* This class is the outer container of all output sections. */
216 /* This class is the outer container of all output sections. */
216 div.output_area {
217 div.output_area {
217 padding: 0px;
218 padding: 0px;
218 page-break-inside: avoid;
219 page-break-inside: avoid;
219 }
220 }
220
221
221 /* This class is for the output subarea inside the output_area and after
222 /* This class is for the output subarea inside the output_area and after
222 the prompt div. */
223 the prompt div. */
223 div.output_subarea {
224 div.output_subarea {
224 padding: 0.4em;
225 padding: 0.4em;
225 }
226 }
226
227
227 /* The rest of the output_* classes are for special styling of the different
228 /* The rest of the output_* classes are for special styling of the different
228 output types */
229 output types */
229
230
230 div.output_stream {
231 /* all text output has this class: */
232 div.output_text {
231 text-align: left;
233 text-align: left;
232 color: black;
234 color: black;
233 font-family: monospace;
235 font-family: monospace;
234 }
236 }
237
238 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
239 div.output_stream {
240 padding-top: 0.0em;
241 padding-bottom: 0.0em;
242 }
243 div.output_stdout {
244 }
235 div.output_stderr {
245 div.output_stderr {
236 color: darkred;
246 background: #fdd; /* very light red background for stderr */
237 }
247 }
238
248
239 div.output_latex {
249 div.output_latex {
240 text-align: left;
250 text-align: left;
241 color: black;
251 color: black;
242 }
252 }
243
253
244 div.output_html {
254 div.output_html {
245 }
255 }
246
256
247 div.output_png {
257 div.output_png {
248 }
258 }
249
259
250 div.output_jpeg {
260 div.output_jpeg {
251 }
261 }
252
262
253 div.text_cell {
263 div.text_cell {
254 background-color: white;
264 background-color: white;
255 }
265 }
256
266
257 div.text_cell_input {
267 div.text_cell_input {
258 color: black;
268 color: black;
259 }
269 }
260
270
261 div.text_cell_render {
271 div.text_cell_render {
262 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
272 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
263 outline: none;
273 outline: none;
264 resize: none;
274 resize: none;
265 width: inherit;
275 width: inherit;
266 border-style: none;
276 border-style: none;
267 padding: 5px;
277 padding: 5px;
268 color: black;
278 color: black;
269 }
279 }
270
280
271 .CodeMirror {
281 .CodeMirror {
272 line-height: 1.231; /* Changed from 1em to our global default */
282 line-height: 1.231; /* Changed from 1em to our global default */
273 }
283 }
274
284
275 .CodeMirror-scroll {
285 .CodeMirror-scroll {
276 height: auto; /* Changed to auto to autogrow */
286 height: auto; /* Changed to auto to autogrow */
277 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
287 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
278 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
288 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
279 overflow-y: hidden;
289 overflow-y: hidden;
280 overflow-x: auto; /* Changed from auto to remove scrollbar */
290 overflow-x: auto; /* Changed from auto to remove scrollbar */
281 }
291 }
282
292
283 /* CSS font colors for translated ANSI colors. */
293 /* CSS font colors for translated ANSI colors. */
284
294
285
295
286 .ansiblack {color: black;}
296 .ansiblack {color: black;}
287 .ansired {color: darkred;}
297 .ansired {color: darkred;}
288 .ansigreen {color: darkgreen;}
298 .ansigreen {color: darkgreen;}
289 .ansiyellow {color: brown;}
299 .ansiyellow {color: brown;}
290 .ansiblue {color: darkblue;}
300 .ansiblue {color: darkblue;}
291 .ansipurple {color: darkviolet;}
301 .ansipurple {color: darkviolet;}
292 .ansicyan {color: steelblue;}
302 .ansicyan {color: steelblue;}
293 .ansigrey {color: grey;}
303 .ansigrey {color: grey;}
294 .ansibold {font-weight: bold;}
304 .ansibold {font-weight: bold;}
295
305
296 .completions {
306 .completions {
297 position: absolute;
307 position: absolute;
298 z-index: 10;
308 z-index: 10;
299 overflow: auto;
309 overflow: auto;
300 border: 1px solid black;
310 border: 1px solid black;
301 }
311 }
302
312
303 .completions select {
313 .completions select {
304 background: white;
314 background: white;
305 outline: none;
315 outline: none;
306 border: none;
316 border: none;
307 padding: 0px;
317 padding: 0px;
308 margin: 0px;
318 margin: 0px;
309 font-family: monospace;
319 font-family: monospace;
310 }
320 }
311
321
312 @media print {
322 @media print {
313 body { overflow: visible !important; }
323 body { overflow: visible !important; }
314 .ui-widget-content { border: 0px; }
324 .ui-widget-content { border: 0px; }
315 }
325 }
316
326
317 .shortcut_key {
327 .shortcut_key {
318 display: inline-block;
328 display: inline-block;
319 width: 10ex;
329 width: 10ex;
320 text-align: right;
330 text-align: right;
321 }
331 }
322
332
323 .shortcut_descr {
333 .shortcut_descr {
324 } No newline at end of file
334 }
@@ -1,473 +1,473
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // CodeCell
9 // CodeCell
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16 var CodeCell = function (notebook) {
16 var CodeCell = function (notebook) {
17 this.code_mirror = null;
17 this.code_mirror = null;
18 this.input_prompt_number = ' ';
18 this.input_prompt_number = ' ';
19 this.is_completing = false;
19 this.is_completing = false;
20 this.completion_cursor = null;
20 this.completion_cursor = null;
21 this.outputs = [];
21 this.outputs = [];
22 this.collapsed = false;
22 this.collapsed = false;
23 IPython.Cell.apply(this, arguments);
23 IPython.Cell.apply(this, arguments);
24 };
24 };
25
25
26
26
27 CodeCell.prototype = new IPython.Cell();
27 CodeCell.prototype = new IPython.Cell();
28
28
29
29
30 CodeCell.prototype.create_element = function () {
30 CodeCell.prototype.create_element = function () {
31 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
31 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
32 cell.attr('tabindex','2');
32 cell.attr('tabindex','2');
33 var input = $('<div></div>').addClass('input hbox');
33 var input = $('<div></div>').addClass('input hbox');
34 input.append($('<div/>').addClass('prompt input_prompt'));
34 input.append($('<div/>').addClass('prompt input_prompt'));
35 var input_area = $('<div/>').addClass('input_area box-flex1');
35 var input_area = $('<div/>').addClass('input_area box-flex1');
36 this.code_mirror = CodeMirror(input_area.get(0), {
36 this.code_mirror = CodeMirror(input_area.get(0), {
37 indentUnit : 4,
37 indentUnit : 4,
38 mode: 'python',
38 mode: 'python',
39 theme: 'ipython',
39 theme: 'ipython',
40 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
40 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
41 });
41 });
42 input.append(input_area);
42 input.append(input_area);
43 var output = $('<div></div>').addClass('output vbox');
43 var output = $('<div></div>').addClass('output vbox');
44 cell.append(input).append(output);
44 cell.append(input).append(output);
45 this.element = cell;
45 this.element = cell;
46 this.collapse()
46 this.collapse()
47 };
47 };
48
48
49
49
50 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
50 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
51 // This method gets called in CodeMirror's onKeyDown/onKeyPress handlers and
51 // This method gets called in CodeMirror's onKeyDown/onKeyPress handlers and
52 // is used to provide custom key handling. Its return value is used to determine
52 // is used to provide custom key handling. Its return value is used to determine
53 // if CodeMirror should ignore the event: true = ignore, false = don't ignore.
53 // if CodeMirror should ignore the event: true = ignore, false = don't ignore.
54 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
54 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
55 // Always ignore shift-enter in CodeMirror as we handle it.
55 // Always ignore shift-enter in CodeMirror as we handle it.
56 return true;
56 return true;
57 } else if (event.keyCode === 9 && event.type == 'keydown') {
57 } else if (event.keyCode === 9 && event.type == 'keydown') {
58 // Tab completion.
58 // Tab completion.
59 var cur = editor.getCursor();
59 var cur = editor.getCursor();
60 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
60 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
61 if (pre_cursor === "") {
61 if (pre_cursor === "") {
62 // Don't autocomplete if the part of the line before the cursor is empty.
62 // Don't autocomplete if the part of the line before the cursor is empty.
63 // In this case, let CodeMirror handle indentation.
63 // In this case, let CodeMirror handle indentation.
64 return false;
64 return false;
65 } else {
65 } else {
66 // Autocomplete the current line.
66 // Autocomplete the current line.
67 event.stop();
67 event.stop();
68 var line = editor.getLine(cur.line);
68 var line = editor.getLine(cur.line);
69 this.is_completing = true;
69 this.is_completing = true;
70 this.completion_cursor = cur;
70 this.completion_cursor = cur;
71 IPython.notebook.complete_cell(this, line, cur.ch);
71 IPython.notebook.complete_cell(this, line, cur.ch);
72 return true;
72 return true;
73 }
73 }
74 } else if (event.keyCode === 8 && event.type == 'keydown') {
74 } else if (event.keyCode === 8 && event.type == 'keydown') {
75 // If backspace and the line ends with 4 spaces, remove them.
75 // If backspace and the line ends with 4 spaces, remove them.
76 var cur = editor.getCursor();
76 var cur = editor.getCursor();
77 var line = editor.getLine(cur.line);
77 var line = editor.getLine(cur.line);
78 var ending = line.slice(-4);
78 var ending = line.slice(-4);
79 if (ending === ' ') {
79 if (ending === ' ') {
80 editor.replaceRange('',
80 editor.replaceRange('',
81 {line: cur.line, ch: cur.ch-4},
81 {line: cur.line, ch: cur.ch-4},
82 {line: cur.line, ch: cur.ch}
82 {line: cur.line, ch: cur.ch}
83 );
83 );
84 event.stop();
84 event.stop();
85 return true;
85 return true;
86 } else {
86 } else {
87 return false;
87 return false;
88 };
88 };
89 } else {
89 } else {
90 // keypress/keyup also trigger on TAB press, and we don't want to use those
90 // keypress/keyup also trigger on TAB press, and we don't want to use those
91 // to disable tab completion.
91 // to disable tab completion.
92 if (this.is_completing && event.keyCode !== 9) {
92 if (this.is_completing && event.keyCode !== 9) {
93 var ed_cur = editor.getCursor();
93 var ed_cur = editor.getCursor();
94 var cc_cur = this.completion_cursor;
94 var cc_cur = this.completion_cursor;
95 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
95 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
96 this.is_completing = false;
96 this.is_completing = false;
97 this.completion_cursor = null;
97 this.completion_cursor = null;
98 };
98 };
99 };
99 };
100 return false;
100 return false;
101 };
101 };
102 };
102 };
103
103
104
104
105 CodeCell.prototype.finish_completing = function (matched_text, matches) {
105 CodeCell.prototype.finish_completing = function (matched_text, matches) {
106 // console.log("Got matches", matched_text, matches);
106 // console.log("Got matches", matched_text, matches);
107 if (!this.is_completing || matches.length === 0) {return;}
107 if (!this.is_completing || matches.length === 0) {return;}
108
108
109 var that = this;
109 var that = this;
110 var cur = this.completion_cursor;
110 var cur = this.completion_cursor;
111
111
112 var insert = function (selected_text) {
112 var insert = function (selected_text) {
113 that.code_mirror.replaceRange(
113 that.code_mirror.replaceRange(
114 selected_text,
114 selected_text,
115 {line: cur.line, ch: (cur.ch-matched_text.length)},
115 {line: cur.line, ch: (cur.ch-matched_text.length)},
116 {line: cur.line, ch: cur.ch}
116 {line: cur.line, ch: cur.ch}
117 );
117 );
118 };
118 };
119
119
120 if (matches.length === 1) {
120 if (matches.length === 1) {
121 insert(matches[0]);
121 insert(matches[0]);
122 setTimeout(function(){that.code_mirror.focus();}, 50);
122 setTimeout(function(){that.code_mirror.focus();}, 50);
123 return;
123 return;
124 };
124 };
125
125
126 var complete = $('<div/>').addClass('completions');
126 var complete = $('<div/>').addClass('completions');
127 var select = $('<select/>').attr('multiple','true');
127 var select = $('<select/>').attr('multiple','true');
128 for (var i=0; i<matches.length; ++i) {
128 for (var i=0; i<matches.length; ++i) {
129 select.append($('<option/>').text(matches[i]));
129 select.append($('<option/>').text(matches[i]));
130 }
130 }
131 select.children().first().attr('selected','true');
131 select.children().first().attr('selected','true');
132 select.attr('size',Math.min(10,matches.length));
132 select.attr('size',Math.min(10,matches.length));
133 var pos = this.code_mirror.cursorCoords();
133 var pos = this.code_mirror.cursorCoords();
134 complete.css('left',pos.x+'px');
134 complete.css('left',pos.x+'px');
135 complete.css('top',pos.yBot+'px');
135 complete.css('top',pos.yBot+'px');
136 complete.append(select);
136 complete.append(select);
137
137
138 $('body').append(complete);
138 $('body').append(complete);
139 var done = false;
139 var done = false;
140
140
141 var close = function () {
141 var close = function () {
142 if (done) return;
142 if (done) return;
143 done = true;
143 done = true;
144 complete.remove();
144 complete.remove();
145 that.is_completing = false;
145 that.is_completing = false;
146 that.completion_cursor = null;
146 that.completion_cursor = null;
147 };
147 };
148
148
149 var pick = function () {
149 var pick = function () {
150 insert(select.val()[0]);
150 insert(select.val()[0]);
151 close();
151 close();
152 setTimeout(function(){that.code_mirror.focus();}, 50);
152 setTimeout(function(){that.code_mirror.focus();}, 50);
153 };
153 };
154
154
155 select.blur(close);
155 select.blur(close);
156 select.keydown(function (event) {
156 select.keydown(function (event) {
157 var code = event.which;
157 var code = event.which;
158 if (code === 13 || code === 32) {
158 if (code === 13 || code === 32) {
159 // Pressing SPACE or ENTER will cause a pick
159 // Pressing SPACE or ENTER will cause a pick
160 event.stopPropagation();
160 event.stopPropagation();
161 event.preventDefault();
161 event.preventDefault();
162 pick();
162 pick();
163 } else if (code === 38 || code === 40) {
163 } else if (code === 38 || code === 40) {
164 // We don't want the document keydown handler to handle UP/DOWN,
164 // We don't want the document keydown handler to handle UP/DOWN,
165 // but we want the default action.
165 // but we want the default action.
166 event.stopPropagation();
166 event.stopPropagation();
167 } else {
167 } else {
168 // All other key presses exit completion.
168 // All other key presses exit completion.
169 event.stopPropagation();
169 event.stopPropagation();
170 event.preventDefault();
170 event.preventDefault();
171 close();
171 close();
172 that.code_mirror.focus();
172 that.code_mirror.focus();
173 }
173 }
174 });
174 });
175 // Double click also causes a pick.
175 // Double click also causes a pick.
176 select.dblclick(pick);
176 select.dblclick(pick);
177 select.focus();
177 select.focus();
178 };
178 };
179
179
180
180
181 CodeCell.prototype.select = function () {
181 CodeCell.prototype.select = function () {
182 IPython.Cell.prototype.select.apply(this);
182 IPython.Cell.prototype.select.apply(this);
183 // Todo: this dance is needed because as of CodeMirror 2.12, focus is
183 // Todo: this dance is needed because as of CodeMirror 2.12, focus is
184 // not causing the cursor to blink if the editor is empty initially.
184 // not causing the cursor to blink if the editor is empty initially.
185 // While this seems to fix the issue, this should be fixed
185 // While this seems to fix the issue, this should be fixed
186 // in CodeMirror proper.
186 // in CodeMirror proper.
187 var s = this.code_mirror.getValue();
187 var s = this.code_mirror.getValue();
188 this.code_mirror.focus();
188 this.code_mirror.focus();
189 if (s === '') this.code_mirror.setValue('');
189 if (s === '') this.code_mirror.setValue('');
190 };
190 };
191
191
192
192
193 CodeCell.prototype.select_all = function () {
193 CodeCell.prototype.select_all = function () {
194 var start = {line: 0, ch: 0};
194 var start = {line: 0, ch: 0};
195 var nlines = this.code_mirror.lineCount();
195 var nlines = this.code_mirror.lineCount();
196 var last_line = this.code_mirror.getLine(nlines-1);
196 var last_line = this.code_mirror.getLine(nlines-1);
197 var end = {line: nlines-1, ch: last_line.length};
197 var end = {line: nlines-1, ch: last_line.length};
198 this.code_mirror.setSelection(start, end);
198 this.code_mirror.setSelection(start, end);
199 };
199 };
200
200
201
201
202 CodeCell.prototype.append_output = function (json) {
202 CodeCell.prototype.append_output = function (json) {
203 this.expand();
203 this.expand();
204 if (json.output_type === 'pyout') {
204 if (json.output_type === 'pyout') {
205 this.append_pyout(json);
205 this.append_pyout(json);
206 } else if (json.output_type === 'pyerr') {
206 } else if (json.output_type === 'pyerr') {
207 this.append_pyerr(json);
207 this.append_pyerr(json);
208 } else if (json.output_type === 'display_data') {
208 } else if (json.output_type === 'display_data') {
209 this.append_display_data(json);
209 this.append_display_data(json);
210 } else if (json.output_type === 'stream') {
210 } else if (json.output_type === 'stream') {
211 this.append_stream(json);
211 this.append_stream(json);
212 };
212 };
213 this.outputs.push(json);
213 this.outputs.push(json);
214 };
214 };
215
215
216
216
217 CodeCell.prototype.create_output_area = function () {
217 CodeCell.prototype.create_output_area = function () {
218 var oa = $("<div/>").addClass("hbox output_area");
218 var oa = $("<div/>").addClass("hbox output_area");
219 oa.append($('<div/>').addClass('prompt'));
219 oa.append($('<div/>').addClass('prompt'));
220 return oa;
220 return oa;
221 };
221 };
222
222
223
223
224 CodeCell.prototype.append_pyout = function (json) {
224 CodeCell.prototype.append_pyout = function (json) {
225 n = json.prompt_number || ' ';
225 n = json.prompt_number || ' ';
226 var toinsert = this.create_output_area();
226 var toinsert = this.create_output_area();
227 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
227 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
228 this.append_mime_type(json, toinsert);
228 this.append_mime_type(json, toinsert);
229 this.element.find('div.output').append(toinsert);
229 this.element.find('div.output').append(toinsert);
230 // If we just output latex, typeset it.
230 // If we just output latex, typeset it.
231 if (json.latex !== undefined) {
231 if (json.latex !== undefined) {
232 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
232 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
233 };
233 };
234 };
234 };
235
235
236
236
237 CodeCell.prototype.append_pyerr = function (json) {
237 CodeCell.prototype.append_pyerr = function (json) {
238 var tb = json.traceback;
238 var tb = json.traceback;
239 if (tb !== undefined && tb.length > 0) {
239 if (tb !== undefined && tb.length > 0) {
240 var s = '';
240 var s = '';
241 var len = tb.length;
241 var len = tb.length;
242 for (var i=0; i<len; i++) {
242 for (var i=0; i<len; i++) {
243 s = s + tb[i] + '\n';
243 s = s + tb[i] + '\n';
244 }
244 }
245 s = s + '\n';
245 s = s + '\n';
246 var toinsert = this.create_output_area();
246 var toinsert = this.create_output_area();
247 this.append_text(s, toinsert);
247 this.append_text(s, toinsert);
248 this.element.find('div.output').append(toinsert);
248 this.element.find('div.output').append(toinsert);
249 };
249 };
250 };
250 };
251
251
252
252
253 CodeCell.prototype.append_stream = function (json) {
253 CodeCell.prototype.append_stream = function (json) {
254 // temporary fix: if stream undefined (json file written prior to this patch),
254 // temporary fix: if stream undefined (json file written prior to this patch),
255 // default to most likely stdout:
255 // default to most likely stdout:
256 if (json.stream == undefined){
256 if (json.stream == undefined){
257 json.stream = 'stdout';
257 json.stream = 'stdout';
258 }
258 }
259 var subclass = "output_"+json.stream;
259 var subclass = "output_"+json.stream;
260 if (this.outputs.length > 0){
260 if (this.outputs.length > 0){
261 // have at least one output to consider
261 // have at least one output to consider
262 var last = this.outputs[this.outputs.length-1];
262 var last = this.outputs[this.outputs.length-1];
263 if (last.output_type == 'stream' && json.stream == last.stream){
263 if (last.output_type == 'stream' && json.stream == last.stream){
264 // latest output was in the same stream,
264 // latest output was in the same stream,
265 // so append directly into its pre tag
265 // so append directly into its pre tag
266 this.element.find('div.'+subclass).last().find('pre').append(json.text);
266 this.element.find('div.'+subclass).last().find('pre').append(json.text);
267 return;
267 return;
268 }
268 }
269 }
269 }
270
270
271 // If we got here, attach a new div
271 // If we got here, attach a new div
272 var toinsert = this.create_output_area();
272 var toinsert = this.create_output_area();
273 this.append_text(json.text, toinsert, subclass);
273 this.append_text(json.text, toinsert, "output_stream "+subclass);
274 this.element.find('div.output').append(toinsert);
274 this.element.find('div.output').append(toinsert);
275 };
275 };
276
276
277
277
278 CodeCell.prototype.append_display_data = function (json) {
278 CodeCell.prototype.append_display_data = function (json) {
279 var toinsert = this.create_output_area();
279 var toinsert = this.create_output_area();
280 this.append_mime_type(json, toinsert)
280 this.append_mime_type(json, toinsert)
281 this.element.find('div.output').append(toinsert);
281 this.element.find('div.output').append(toinsert);
282 // If we just output latex, typeset it.
282 // If we just output latex, typeset it.
283 if (json.latex !== undefined) {
283 if (json.latex !== undefined) {
284 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
284 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
285 };
285 };
286 };
286 };
287
287
288
288
289 CodeCell.prototype.append_mime_type = function (json, element) {
289 CodeCell.prototype.append_mime_type = function (json, element) {
290 if (json.html !== undefined) {
290 if (json.html !== undefined) {
291 this.append_html(json.html, element);
291 this.append_html(json.html, element);
292 } else if (json.latex !== undefined) {
292 } else if (json.latex !== undefined) {
293 this.append_latex(json.latex, element);
293 this.append_latex(json.latex, element);
294 } else if (json.svg !== undefined) {
294 } else if (json.svg !== undefined) {
295 this.append_svg(json.svg, element);
295 this.append_svg(json.svg, element);
296 } else if (json.png !== undefined) {
296 } else if (json.png !== undefined) {
297 this.append_png(json.png, element);
297 this.append_png(json.png, element);
298 } else if (json.jpeg !== undefined) {
298 } else if (json.jpeg !== undefined) {
299 this.append_jpeg(json.jpeg, element);
299 this.append_jpeg(json.jpeg, element);
300 } else if (json.text !== undefined) {
300 } else if (json.text !== undefined) {
301 this.append_text(json.text, element);
301 this.append_text(json.text, element);
302 };
302 };
303 };
303 };
304
304
305
305
306 CodeCell.prototype.append_html = function (html, element) {
306 CodeCell.prototype.append_html = function (html, element) {
307 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
307 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
308 toinsert.append(html);
308 toinsert.append(html);
309 element.append(toinsert);
309 element.append(toinsert);
310 }
310 }
311
311
312
312
313 CodeCell.prototype.append_text = function (data, element, extra_class) {
313 CodeCell.prototype.append_text = function (data, element, extra_class) {
314 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_stream");
314 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
315 if (extra_class){
315 if (extra_class){
316 toinsert.addClass(extra_class);
316 toinsert.addClass(extra_class);
317 }
317 }
318 toinsert.append($("<pre/>").html(data));
318 toinsert.append($("<pre/>").html(data));
319 element.append(toinsert);
319 element.append(toinsert);
320 };
320 };
321
321
322
322
323 CodeCell.prototype.append_svg = function (svg, element) {
323 CodeCell.prototype.append_svg = function (svg, element) {
324 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_svg");
324 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_svg");
325 toinsert.append(svg);
325 toinsert.append(svg);
326 element.append(toinsert);
326 element.append(toinsert);
327 };
327 };
328
328
329
329
330 CodeCell.prototype.append_png = function (png, element) {
330 CodeCell.prototype.append_png = function (png, element) {
331 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_png");
331 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_png");
332 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
332 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
333 element.append(toinsert);
333 element.append(toinsert);
334 };
334 };
335
335
336
336
337 CodeCell.prototype.append_jpeg = function (jpeg, element) {
337 CodeCell.prototype.append_jpeg = function (jpeg, element) {
338 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_jpeg");
338 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_jpeg");
339 toinsert.append($("<img/>").attr('src','data:image/jpeg;base64,'+jpeg));
339 toinsert.append($("<img/>").attr('src','data:image/jpeg;base64,'+jpeg));
340 element.append(toinsert);
340 element.append(toinsert);
341 };
341 };
342
342
343
343
344 CodeCell.prototype.append_latex = function (latex, element) {
344 CodeCell.prototype.append_latex = function (latex, element) {
345 // This method cannot do the typesetting because the latex first has to
345 // This method cannot do the typesetting because the latex first has to
346 // be on the page.
346 // be on the page.
347 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
347 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
348 toinsert.append(latex);
348 toinsert.append(latex);
349 element.append(toinsert);
349 element.append(toinsert);
350 }
350 }
351
351
352
352
353 CodeCell.prototype.clear_output = function () {
353 CodeCell.prototype.clear_output = function () {
354 this.element.find("div.output").html("");
354 this.element.find("div.output").html("");
355 this.outputs = [];
355 this.outputs = [];
356 };
356 };
357
357
358
358
359 CodeCell.prototype.clear_input = function () {
359 CodeCell.prototype.clear_input = function () {
360 this.code_mirror.setValue('');
360 this.code_mirror.setValue('');
361 };
361 };
362
362
363
363
364 CodeCell.prototype.collapse = function () {
364 CodeCell.prototype.collapse = function () {
365 if (!this.collapsed) {
365 if (!this.collapsed) {
366 this.element.find('div.output').hide();
366 this.element.find('div.output').hide();
367 this.collapsed = true;
367 this.collapsed = true;
368 };
368 };
369 };
369 };
370
370
371
371
372 CodeCell.prototype.expand = function () {
372 CodeCell.prototype.expand = function () {
373 if (this.collapsed) {
373 if (this.collapsed) {
374 this.element.find('div.output').show();
374 this.element.find('div.output').show();
375 this.collapsed = false;
375 this.collapsed = false;
376 };
376 };
377 };
377 };
378
378
379
379
380 CodeCell.prototype.toggle_output = function () {
380 CodeCell.prototype.toggle_output = function () {
381 if (this.collapsed) {
381 if (this.collapsed) {
382 this.expand();
382 this.expand();
383 } else {
383 } else {
384 this.collapse();
384 this.collapse();
385 };
385 };
386 };
386 };
387
387
388 CodeCell.prototype.set_input_prompt = function (number) {
388 CodeCell.prototype.set_input_prompt = function (number) {
389 var n = number || ' ';
389 var n = number || ' ';
390 this.input_prompt_number = n
390 this.input_prompt_number = n
391 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
391 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
392 };
392 };
393
393
394
394
395 CodeCell.prototype.get_code = function () {
395 CodeCell.prototype.get_code = function () {
396 return this.code_mirror.getValue();
396 return this.code_mirror.getValue();
397 };
397 };
398
398
399
399
400 CodeCell.prototype.set_code = function (code) {
400 CodeCell.prototype.set_code = function (code) {
401 return this.code_mirror.setValue(code);
401 return this.code_mirror.setValue(code);
402 };
402 };
403
403
404
404
405 CodeCell.prototype.at_top = function () {
405 CodeCell.prototype.at_top = function () {
406 var cursor = this.code_mirror.getCursor();
406 var cursor = this.code_mirror.getCursor();
407 if (cursor.line === 0) {
407 if (cursor.line === 0) {
408 return true;
408 return true;
409 } else {
409 } else {
410 return false;
410 return false;
411 }
411 }
412 };
412 };
413
413
414
414
415 CodeCell.prototype.at_bottom = function () {
415 CodeCell.prototype.at_bottom = function () {
416 var cursor = this.code_mirror.getCursor();
416 var cursor = this.code_mirror.getCursor();
417 if (cursor.line === (this.code_mirror.lineCount()-1)) {
417 if (cursor.line === (this.code_mirror.lineCount()-1)) {
418 return true;
418 return true;
419 } else {
419 } else {
420 return false;
420 return false;
421 }
421 }
422 };
422 };
423
423
424
424
425 CodeCell.prototype.fromJSON = function (data) {
425 CodeCell.prototype.fromJSON = function (data) {
426 console.log('Import from JSON:', data);
426 console.log('Import from JSON:', data);
427 if (data.cell_type === 'code') {
427 if (data.cell_type === 'code') {
428 if (data.input !== undefined) {
428 if (data.input !== undefined) {
429 this.set_code(data.input);
429 this.set_code(data.input);
430 }
430 }
431 if (data.prompt_number !== undefined) {
431 if (data.prompt_number !== undefined) {
432 this.set_input_prompt(data.prompt_number);
432 this.set_input_prompt(data.prompt_number);
433 } else {
433 } else {
434 this.set_input_prompt();
434 this.set_input_prompt();
435 };
435 };
436 var len = data.outputs.length;
436 var len = data.outputs.length;
437 for (var i=0; i<len; i++) {
437 for (var i=0; i<len; i++) {
438 this.append_output(data.outputs[i]);
438 this.append_output(data.outputs[i]);
439 };
439 };
440 if (data.collapsed !== undefined) {
440 if (data.collapsed !== undefined) {
441 if (data.collapsed) {
441 if (data.collapsed) {
442 this.collapse();
442 this.collapse();
443 };
443 };
444 };
444 };
445 };
445 };
446 };
446 };
447
447
448
448
449 CodeCell.prototype.toJSON = function () {
449 CodeCell.prototype.toJSON = function () {
450 var data = {};
450 var data = {};
451 data.input = this.get_code();
451 data.input = this.get_code();
452 data.cell_type = 'code';
452 data.cell_type = 'code';
453 if (this.input_prompt_number !== ' ') {
453 if (this.input_prompt_number !== ' ') {
454 data.prompt_number = this.input_prompt_number
454 data.prompt_number = this.input_prompt_number
455 };
455 };
456 var outputs = [];
456 var outputs = [];
457 var len = this.outputs.length;
457 var len = this.outputs.length;
458 for (var i=0; i<len; i++) {
458 for (var i=0; i<len; i++) {
459 outputs[i] = this.outputs[i];
459 outputs[i] = this.outputs[i];
460 };
460 };
461 data.outputs = outputs;
461 data.outputs = outputs;
462 data.language = 'python';
462 data.language = 'python';
463 data.collapsed = this.collapsed;
463 data.collapsed = this.collapsed;
464 // console.log('Export to JSON:',data);
464 // console.log('Export to JSON:',data);
465 return data;
465 return data;
466 };
466 };
467
467
468
468
469 IPython.CodeCell = CodeCell;
469 IPython.CodeCell = CodeCell;
470
470
471 return IPython;
471 return IPython;
472 }(IPython));
472 }(IPython));
473
473
General Comments 0
You need to be logged in to leave comments. Login now