Show More
@@ -13,6 +13,7 b' var IPython = (function (IPython) {' | |||
|
13 | 13 | this.is_completing = false; |
|
14 | 14 | this.completion_cursor = null; |
|
15 | 15 | this.outputs = []; |
|
16 | this.collapsed = false; | |
|
16 | 17 | IPython.Cell.apply(this, arguments); |
|
17 | 18 | }; |
|
18 | 19 | |
@@ -317,12 +318,18 b' var IPython = (function (IPython) {' | |||
|
317 | 318 | |
|
318 | 319 | |
|
319 | 320 | CodeCell.prototype.collapse = function () { |
|
320 | this.element.find('div.output').hide(); | |
|
321 | if (!this.collapsed) { | |
|
322 | this.element.find('div.output').hide(); | |
|
323 | this.collapsed = true; | |
|
324 | }; | |
|
321 | 325 | }; |
|
322 | 326 | |
|
323 | 327 | |
|
324 | 328 | CodeCell.prototype.expand = function () { |
|
325 | this.element.find('div.output').show(); | |
|
329 | if (this.collapsed) { | |
|
330 | this.element.find('div.output').show(); | |
|
331 | this.collapsed = false; | |
|
332 | }; | |
|
326 | 333 | }; |
|
327 | 334 | |
|
328 | 335 | |
@@ -378,6 +385,11 b' var IPython = (function (IPython) {' | |||
|
378 | 385 | for (var i=0; i<len; i++) { |
|
379 | 386 | this.append_output(data.outputs[i]); |
|
380 | 387 | }; |
|
388 | if (data.collapsed !== undefined) { | |
|
389 | if (data.collapsed) { | |
|
390 | this.collapse(); | |
|
391 | }; | |
|
392 | }; | |
|
381 | 393 | }; |
|
382 | 394 | }; |
|
383 | 395 | |
@@ -396,6 +408,7 b' var IPython = (function (IPython) {' | |||
|
396 | 408 | }; |
|
397 | 409 | data.outputs = outputs; |
|
398 | 410 | data.language = 'python'; |
|
411 | data.collapsed = this.collapsed; | |
|
399 | 412 | // console.log('Export to JSON:',data); |
|
400 | 413 | return data; |
|
401 | 414 | }; |
@@ -50,7 +50,8 b' def new_output(output_type=None, output_text=None, output_png=None,' | |||
|
50 | 50 | return output |
|
51 | 51 | |
|
52 | 52 | |
|
53 |
def new_code_cell(input=None, prompt_number=None, outputs=None, |
|
|
53 | def new_code_cell(input=None, prompt_number=None, outputs=None, | |
|
54 | language=u'python', collapsed=False): | |
|
54 | 55 | """Create a new code cell with input and output""" |
|
55 | 56 | cell = NotebookNode() |
|
56 | 57 | cell.cell_type = u'code' |
@@ -64,6 +65,8 b" def new_code_cell(input=None, prompt_number=None, outputs=None, language=u'pytho" | |||
|
64 | 65 | cell.outputs = [] |
|
65 | 66 | else: |
|
66 | 67 | cell.outputs = outputs |
|
68 | if collapsed is not None: | |
|
69 | cell.collapsed = collapsed | |
|
67 | 70 | |
|
68 | 71 | return cell |
|
69 | 72 |
@@ -52,6 +52,23 b' def _set_int(nbnode, attr, parent, tag):' | |||
|
52 | 52 | e.text = unicode(nbnode[attr]) |
|
53 | 53 | |
|
54 | 54 | |
|
55 | def _get_bool(e, tag): | |
|
56 | sub_e = e.find(tag) | |
|
57 | if sub_e is None: | |
|
58 | return None | |
|
59 | else: | |
|
60 | return bool(int(sub_e.text)) | |
|
61 | ||
|
62 | ||
|
63 | def _set_bool(nbnode, attr, parent, tag): | |
|
64 | if attr in nbnode: | |
|
65 | e = ET.SubElement(parent, tag) | |
|
66 | if nbnode[attr]: | |
|
67 | e.text = u'1' | |
|
68 | else: | |
|
69 | e.text = u'0' | |
|
70 | ||
|
71 | ||
|
55 | 72 | def _get_binary(e, tag): |
|
56 | 73 | sub_e = e.find(tag) |
|
57 | 74 | if sub_e is None: |
@@ -84,6 +101,7 b' class XMLReader(NotebookReader):' | |||
|
84 | 101 | if cell_e.tag == 'codecell': |
|
85 | 102 | input = _get_text(cell_e,'input') |
|
86 | 103 | prompt_number = _get_int(cell_e,'prompt_number') |
|
104 | collapsed = _get_bool(cell_e,'collapsed') | |
|
87 | 105 | language = _get_text(cell_e,'language') |
|
88 | 106 | outputs = [] |
|
89 | 107 | for output_e in cell_e.find('outputs').getiterator('output'): |
@@ -105,7 +123,7 b' class XMLReader(NotebookReader):' | |||
|
105 | 123 | ) |
|
106 | 124 | outputs.append(output) |
|
107 | 125 | cc = new_code_cell(input=input,prompt_number=prompt_number, |
|
108 | language=language,outputs=outputs) | |
|
126 | language=language,outputs=outputs,collapsed=collapsed) | |
|
109 | 127 | cells.append(cc) |
|
110 | 128 | if cell_e.tag == 'htmlcell': |
|
111 | 129 | source = _get_text(cell_e,'source') |
@@ -141,6 +159,7 b' class XMLWriter(NotebookWriter):' | |||
|
141 | 159 | _set_text(cell,'input',cell_e,'input') |
|
142 | 160 | _set_text(cell,'language',cell_e,'language') |
|
143 | 161 | _set_int(cell,'prompt_number',cell_e,'prompt_number') |
|
162 | _set_bool(cell,'collapsed',cell_e,'collapsed') | |
|
144 | 163 | outputs_e = ET.SubElement(cell_e, 'outputs') |
|
145 | 164 | for output in cell.outputs: |
|
146 | 165 | output_e = ET.SubElement(outputs_e, 'output') |
@@ -16,7 +16,8 b' ws.cells.append(new_text_cell(' | |||
|
16 | 16 | |
|
17 | 17 | ws.cells.append(new_code_cell( |
|
18 | 18 | input='import numpy', |
|
19 | prompt_number=1 | |
|
19 | prompt_number=1, | |
|
20 | collapsed=False | |
|
20 | 21 | )) |
|
21 | 22 | |
|
22 | 23 | ws.cells.append(new_text_cell( |
@@ -27,12 +28,14 b' ws.cells.append(new_text_cell(' | |||
|
27 | 28 | |
|
28 | 29 | ws.cells.append(new_code_cell( |
|
29 | 30 | input='a = numpy.random.rand(100)', |
|
30 | prompt_number=2 | |
|
31 | prompt_number=2, | |
|
32 | collapsed=True | |
|
31 | 33 | )) |
|
32 | 34 | |
|
33 | 35 | ws.cells.append(new_code_cell( |
|
34 | 36 | input='print a', |
|
35 | 37 | prompt_number=3, |
|
38 | collapsed=False, | |
|
36 | 39 | outputs=[new_output( |
|
37 | 40 | output_type=u'pyout', |
|
38 | 41 | output_text=u'<array a>', |
@@ -1,4 +1,4 b'' | |||
|
1 | ||
|
1 | import pprint | |
|
2 | 2 | from unittest import TestCase |
|
3 | 3 | |
|
4 | 4 | from ..nbjson import reads, writes |
@@ -9,6 +9,12 b' class TestJSON(TestCase):' | |||
|
9 | 9 | |
|
10 | 10 | def test_roundtrip(self): |
|
11 | 11 | s = writes(nb0) |
|
12 | ||
|
13 | # print pprint.pformat(nb0,indent=2) | |
|
14 | ||
|
15 | # print pprint.pformat(reads(s),indent=2) | |
|
16 | ||
|
17 | # print s | |
|
12 | 18 | self.assertEquals(reads(s),nb0) |
|
13 | 19 | |
|
14 | 20 |
@@ -13,9 +13,10 b' class TestCell(TestCase):' | |||
|
13 | 13 | self.assertEquals('input' not in cc, True) |
|
14 | 14 | self.assertEquals('prompt_number' not in cc, True) |
|
15 | 15 | self.assertEquals(cc.outputs, []) |
|
16 | self.assertEquals(cc.collapsed, False) | |
|
16 | 17 | |
|
17 | 18 | def test_code_cell(self): |
|
18 | cc = new_code_cell(input='a=10', prompt_number=0) | |
|
19 | cc = new_code_cell(input='a=10', prompt_number=0, collapsed=True) | |
|
19 | 20 | cc.outputs = [new_output(output_type='pyout', |
|
20 | 21 | output_svg='foo',output_text='10',prompt_number=0)] |
|
21 | 22 | self.assertEquals(cc.input, u'a=10') |
@@ -24,6 +25,8 b' class TestCell(TestCase):' | |||
|
24 | 25 | self.assertEquals(cc.outputs[0].svg, u'foo') |
|
25 | 26 | self.assertEquals(cc.outputs[0].text, u'10') |
|
26 | 27 | self.assertEquals(cc.outputs[0].prompt_number, 0) |
|
28 | self.assertEquals(cc.collapsed, True) | |
|
29 | ||
|
27 | 30 | |
|
28 | 31 | def test_empty_html_cell(self): |
|
29 | 32 | tc = new_text_cell(u'html') |
General Comments 0
You need to be logged in to leave comments.
Login now