A Cell.

A cell is a single input/output block. Worksheets are built out of a list of cells.

class sagenb.notebook.cell.Cell(id, input, out, worksheet)

Bases: sagenb.notebook.cell.Cell_generic

cell_output_type()

Returns this compute cell’s output type.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.cell_output_type()
'wrap'
sage: C.set_cell_output_type('nowrap')
sage: C.cell_output_type()
'nowrap'
changed_input_text()

Returns the changed input text for this compute cell. If there is any changed input text, it is reset to ‘’ before this method returns.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.changed_input_text()
''
sage: C.set_changed_input_text('3+3')
sage: C.input_text()
u'3+3'
sage: C.changed_input_text()
u'3+3'
sage: C.changed_input_text()
''
sage: C.version()
0
cleaned_input_text()

Returns this compute cell’s “cleaned” input text, i.e., its input with all of its percent directives removed. If this cell is interacting, it returns the interacting text.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '%hide\n%maxima\n2+3', '5', None)
sage: C.cleaned_input_text()
u'2+3'
computing()

Returns whether this compute cell is queued for evaluation by its worksheet object.

OUTPUT:

  • a boolean

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "2^2")
sage: C.computing()
False
sage: nb.delete()
delete_files()

Deletes all of the files associated with this compute cell.

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W)
sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 0; in=plot(sin(x),0,5), out=
<html><font color='black'><img src='cell://sage0.png'></font></html>
<BLANKLINE>
)
sage: C.files()     # random output -- depends on computer speed
['sage0.png']
sage: C.delete_files()
sage: C.files()
[]
sage: W.quit()
sage: nb.delete()
delete_output()

Deletes all output in this compute cell.

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None); C
Cell 0; in=2+3, out=5
sage: C.delete_output()
sage: C
Cell 0; in=2+3, out=
directory()

Returns the name of this compute cell’s directory, creating it, if it doesn’t already exist.

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.directory()
'.../home/sage/0/cells/0'
sage: nb.delete()
doc_html(wrap=None, div_wrap=True, do_print=False)

Returns HTML for a doc browser cell. This is a modified version of :meth:html.

This is a hack and needs to be improved. The problem is how to get the documentation HTML to display nicely between the example cells. The type setting (jsMath formatting) needs attention too.

TODO: Remove this hack (doc_html())

INPUT:

  • wrap - an integer (default: None); the number of word wrap columns
  • div_wrap - a boolean (default: True); whether to wrap the output in outer div elements
  • do_print - a boolean (default: False); whether to return output suitable for printing

OUTPUT:

  • a string
edit_text(ncols=0, prompts=False, max_out=None)

Returns the text displayed for this compute cell in the Edit window.

INPUT:

  • ncols - an integer (default: 0); the number of word wrap columns
  • prompts - a boolean (default: False); whether to strip interpreter prompts from the beginning of each line
  • max_out - an integer (default: None); the maximum number of characters to return

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.edit_text()
u'{{{id=0|\n2+3\n///\n5\n}}}'
sage: C = sagenb.notebook.cell.Cell(0, 'ěščřžýáíéďĎ', 'ěščřžýáíéďĎ', None)
sage: C.edit_text()
u'{{{id=0|\něščřž\xfd\xe1\xed\xe9ďĎ\n///\něščřž\xfd\xe1\xed\xe9ďĎ\n}}}'
evaluate(introspect=False, time=None, username=None)

Evaluates this compute cell.

INPUT:

  • introspect - a pair [before_cursor,

    after_cursor] of strings (default: False)

  • time - a boolean (default: None); whether to return the time the computation takes

  • username - a string (default: None); name of user doing

    the evaluation

EXAMPLES:

We create a notebook, worksheet, and cell and evaluate it in order to compute 3^5:

sage: nb = sagenb.notebook.notebook.load_notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: W.edit_save('{{{\n3^5\n}}}')
sage: C = W.cell_list()[0]; C
Cell 0; in=3^5, out=
sage: C.evaluate(username='sage')
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 0; in=3^5, out=
243
)
sage: C     # random output -- depends on computer speed
Cell 0; in=3^5, out=
243
sage: W.quit()
sage: nb.delete()
evaluated()

Returns whether this compute cell has been successfully evaluated in a currently running session. This is not about whether the output of the cell is valid given the input.

OUTPUT:

  • a boolean

EXAMPLES: We create a worksheet with a cell that has wrong output:

sage: nb = sagenb.notebook.notebook.load_notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: W.edit_save('{{{\n2+3\n///\n20\n}}}')
sage: C = W.cell_list()[0]
sage: C
Cell 0; in=2+3, out=
20

We re-evaluate that input cell:

sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('w', Cell 0; in=2+3, out=)

Now the output is right:

sage: C     # random output -- depends on computer speed
Cell 0; in=2+3, out=

And the cell is considered to have been evaluated.

sage: C.evaluated()     # random output -- depends on computer speed
True
sage: W.quit()
sage: nb.delete()
files()

Returns a list of all the files in this compute cell’s directory.

OUTPUT:

  • a list of strings

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W)
sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 0; in=plot(sin(x),0,5), out=
<html><font color='black'><img src='cell://sage0.png'></font></html>
<BLANKLINE>
)
sage: C.files()     # random output -- depends on computer speed
['sage0.png']
sage: W.quit()
sage: nb.delete()
files_html(out)

Returns HTML to display the files in this compute cell’s directory.

INPUT:

  • out - a string; files to exclude. To exclude bar, foo, ..., use the format 'cell://bar cell://foo ...'

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W)
sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 0; in=plot(sin(x),0,5), out=
<html><font color='black'><img src='cell://sage0.png'></font></html>
<BLANKLINE>
)
sage: C.files_html('')     # random output -- depends on computer speed
'<img src="/home/sage/0/cells/0/sage0.png?...">'
sage: W.quit()
sage: nb.delete()
has_output()

Returns whether this compute cell has any output.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.has_output()
True
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '', None)
sage: C.has_output()
False
html(wrap=None, div_wrap=True, do_print=False)

Returns the HTML for this compute cell.

INPUT:

  • wrap - an integer (default: None); the number of word wrap columns
  • div_wrap - a boolean (default: True); whether to wrap the output in outer div elements
  • do_print - a boolean (default: False); whether to return output suitable for printing

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.load_notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.html()
u'...cell_outer_0...2+3...5...'
id()

Returns this compute cell’s ID.

OUTPUT:

  • an integer or string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.id()
0
input_text()

Returns this compute cell’s input text.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.input_text()
u'2+3'
interrupt()

Sets this compute cell’s evaluation as interrupted.

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "2^2")
sage: C.interrupt()
sage: C.interrupted()
True
sage: C.evaluated()
False
sage: nb.delete()
interrupted()

Returns whether this compute cell’s evaluation has been interrupted.

OUTPUT:

  • a boolean

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "2^2")
sage: C.interrupt()
sage: C.interrupted()
True
sage: nb.delete()
introspect()

Returns compute cell’s introspection text.

OUTPUT:

  • a string 2-tuple (“before” and “after” text) or boolean (not introspecting)

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'sage?', '', W)
sage: C.introspect()
False
sage: C.evaluate(username='sage')
sage: W.check_comp(9999)     # random output -- depends on computer speed
('d', Cell 0; in=sage?, out=)
sage: C.introspect()
[u'sage?', '']
sage: W.quit()
sage: nb.delete()
introspect_html()

Returns this compute cell’s introspection text, setting it to ‘’, if none is available.

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'sage?', '', W)
sage: C.introspect()
False
sage: C.evaluate(username='sage')
sage: W.check_comp(9999)     # random output -- depends on computer speed
('d', Cell 0; in=sage?, out=)
sage: C.introspect_html()     # random output -- depends on computer speed
u'...<div class="docstring">...sage...</pre></div>...'
sage: W.quit()
sage: nb.delete()
is_asap()

Returns whether this compute cell is to be evaluated as soon as possible (ASAP).

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.is_asap()
False
sage: C.set_asap(True)
sage: C.is_asap()
True
is_auto_cell()

Returns whether this compute cell is evaluated automatically when its worksheet object starts up.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.is_auto_cell()
False
sage: C = sagenb.notebook.cell.Cell(0, '#auto\n2+3', '5', None)
sage: C.is_auto_cell()
True
is_html()

Returns whether this is an HTML compute cell, e.g., its system is ‘html’. This is typically specified by the percent directive %html.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, "%html\nTest HTML", None, None)
sage: C.system()
u'html'
sage: C.is_html()
True
sage: C = sagenb.notebook.cell.Cell(0, "Test HTML", None, None)
sage: C.is_html()
False
is_interacting()

Returns whether this compute cell is currently sagenb.notebook.interact.interact()ing.

OUTPUT:

  • a boolean

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "@interact\ndef f(a=slider(0,10,1,5):\n    print a^2")
sage: C.is_interacting()
False
is_interactive_cell()

Returns whether this compute cell contains sagenb.notebook.interact.interact() either as a function call or decorator.

OUTPUT:

  • a boolean

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "@interact\ndef f(a=slider(0,10,1,5):\n    print a^2")
sage: C.is_interactive_cell()
True
sage: C = W.new_cell_after(C.id(), "2+2")
sage: C.is_interactive_cell()
False
sage: nb.delete()
is_last()

Returns whether this compute cell is the last cell in its worksheet object.

OUTPUT:

  • a boolean

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "2^2"); C
Cell 2; in=2^2, out=
sage: C.is_last()
True
sage: C = W.get_cell_with_id(0)
sage: C.is_last()
False
sage: nb.delete()
is_no_output()

Returns whether this is a “no output” compute cell, i.e., we don’t care about its output.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.is_no_output()
False
sage: C.set_no_output(True)
sage: C.is_no_output()
True
next_id()

Returns the ID of the next cell in this compute cell’s worksheet object. If this cell is not in the worksheet or is the last cell, it returns the ID of the worksheet’s first cell.

OUTPUT:

  • an integer or string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(1, "2^2")
sage: C = W.get_cell_with_id(1)
sage: C.next_id()
2
sage: C = W.get_cell_with_id(2)
sage: C.next_id()
1
sage: nb.delete()
notebook()

Returns this compute cell’s associated notebook object.

OUTPUT:

EXAMPLES:

sage: nb = sagenb.notebook.notebook.load_notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.notebook() is nb
True
sage: nb.delete()
output_html()

Returns this compute cell’s HTML output.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.output_html()
''
sage: C.set_output_text('5', '<strong>5</strong>')
sage: C.output_html()
u'<strong>5</strong>'
output_text(ncols=0, html=True, raw=False, allow_interact=True)

Returns this compute cell’s output text.

INPUT:

  • ncols - an integer (default: 0); the number of word wrap columns
  • html - a boolean (default: True); whether to output HTML
  • raw - a boolean (default: False); whether to output raw text (takes precedence over HTML)
  • allow_interact - a boolean (default: True); whether to allow sagenb.notebook.interact.interact()ion

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.output_text()
u'<pre class="shrunk">5</pre>'
sage: C.output_text(html=False)
u'<pre class="shrunk">5</pre>'
sage: C.output_text(raw=True)
u'5'
sage: C = sagenb.notebook.cell.Cell(0, 'ěščřžýáíéďĎ', 'ěščřžýáíéďĎ', W)
sage: C.output_text()
u'<pre class="shrunk">ěščřž\xfd\xe1\xed\xe9ďĎ</pre>'
sage: C.output_text(raw=True)
u'ěščřž\xfd\xe1\xed\xe9ďĎ'
parse_html(s, ncols)

Parses HTML for output, escaping and wrapping HTML and removing script elements.

INPUT:

  • s - a string; the HTML to parse
  • ncols - an integer; the number of word wrap columns

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.parse_html('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">\n<html><head></head><body>Test</body></html>', 80)
'&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0...Test</body>'
parse_percent_directives()

Parses this compute cell’s percent directives, determines its system (if any), and returns the “cleaned” input text.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '%hide\n%maxima\n%pi+3', '5', None)
sage: C.parse_percent_directives()
u'%pi+3'
sage: C.percent_directives()
[u'hide', u'maxima']
percent_directives()

Returns a list of this compute cell’s percent directives.

OUTPUT:

  • a list of strings

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '%hide\n%maxima\n2+3', '5', None)
sage: C.percent_directives()
[u'hide', u'maxima']
plain_text(ncols=0, prompts=True, max_out=None)

Returns the plain text version of this compute cell.

INPUT:

  • ncols - an integer (default: 0); the number of word wrap columns
  • prompts - a boolean (default: False); whether to strip interpreter prompts from the beginning of each line
  • max_out - an integer (default: None); the maximum number of characters to return

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: len(C.plain_text())
11
process_cell_urls(urls)

Processes this compute cell’s 'cell://.*?' URLs, replacing the protocol with the cell’s path and appending the cell’s version number.

INPUT:

  • urls - a string; the URLs to process

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.process_cell_urls('"cell://foobar"')
'/home/sage/0/cells/0/foobar?0'
sage()

Returns the sage instance for this compute cell(?).

OUTPUT:

  • an instance of sage

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.sage() is None
True
set_asap(asap)

Sets whether to evaluate this compute cell as soon as possible (ASAP).

INPUT:

  • asap - a boolean convertible

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.is_asap()
False
sage: C.set_asap(True)
sage: C.is_asap()
True
set_cell_output_type(typ='wrap')

Sets this compute cell’s output type.

INPUT:

  • typ - a string (default: ‘wrap’); the target output type

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.cell_output_type()
'wrap'
sage: C.set_cell_output_type('nowrap')
sage: C.cell_output_type()
'nowrap'
set_changed_input_text(new_text)

Updates this compute cell’s changed input text. Note: This does not update the version of the cell. It’s typically used, e.g., for tab completion.

INPUT:

  • new_text - a string; the new changed input text

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.set_changed_input_text('3+3')
sage: C.input_text()
u'3+3'
sage: C.changed_input_text()
u'3+3'
set_id(id)

Sets this compute cell’s ID.

INPUT:

  • id - an integer or string; the new ID

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.set_id(2)
sage: C.id()
2
set_input_text(input)

Sets the input text of this compute cell.

INPUT:

  • input - a string; the new input text

TODO: Add doctests for the code dealing with interact.

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = W.new_cell_after(0, "2^2")
sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 1; in=2^2, out=
4
)
sage: C.version()
0
sage: C.set_input_text('3+3')
sage: C.input_text()
u'3+3'
sage: C.evaluated()
False
sage: C.version()
1
sage: W.quit()
sage: nb.delete()
set_introspect(before_prompt, after_prompt)

Set this compute cell’s introspection text.

INPUT:

  • before_prompt - a string
  • after_prompt - a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.set_introspect("a", "b")
sage: C.introspect()
['a', 'b']
set_introspect_html(html, completing=False, raw=False)

Sets this compute cell’s introspection text.

INPUT:

  • html - a string; the updated text
  • completing - a boolean (default: False); whether the completions menu is open
  • raw - a boolean (default: False)

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'sage?', '', W)
sage: C.introspect()
False
sage: C.evaluate(username='sage')
sage: W.check_comp(9999)     # random output -- depends on computer speed
('d', Cell 0; in=sage?, out=)
sage: C.set_introspect_html('foobar')
sage: C.introspect_html()
u'foobar'
sage: C.set_introspect_html('`foobar`')
sage: C.introspect_html()
u'`foobar`'
sage: C.set_introspect_html('ěščřžýáíéďĎ')
sage: C.introspect_html()
u'ěščřž\xfd\xe1\xed\xe9ďĎ'
sage: W.quit()
sage: nb.delete()
set_no_output(no_output)

Sets whether this is a “no output” compute cell, i.e., we don’t care about its output.

INPUT:

  • no_output - a boolean convertible

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.is_no_output()
False
sage: C.set_no_output(True)
sage: C.is_no_output()
True
set_output_text(output, html, sage=None)

Sets this compute cell’s output text.

INPUT:

  • output - a string; the updated output text
  • html - a string; updated output HTML
  • sage - a sage instance (default: None); the sage instance to use for this cell(?)

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: len(C.plain_text())
11
sage: C.set_output_text('10', '10')
sage: len(C.plain_text())
12
set_worksheet(worksheet, id=None)

Sets this compute cell’s worksheet object and, optionally, its ID.

INPUT:

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: W = "worksheet object"
sage: C.set_worksheet(W)
sage: C.worksheet()
'worksheet object'
sage: C.set_worksheet(None, id=2)
sage: C.id()
2
stop_interacting()

Stops sagenb.notebook.interact.interact()ion for this compute cell.

TODO: Add doctests.

system()

Returns the system used to evaluate this compute cell. The system is specified by a percent directive like ‘%maxima’ at the top of a cell.

Returns None, if no system is explicitly specified. In this case, the notebook evaluates the cell using the worksheet’s default system.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '%maxima\n2+3', '5', None)
sage: C.system()
u'maxima'
sage: prefixes = ['%hide', '%time', '']
sage: cells = [sagenb.notebook.cell.Cell(0, '%s\n2+3'%prefix, '5', None) for prefix in prefixes]
sage: [(C, C.system()) for C in cells if C.system() is not None]
[]
time()

Returns whether to print timing information about the evaluation of this compute cell.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.time()
False
sage: C = sagenb.notebook.cell.Cell(0, '%time\n2+3', '5', None)
sage: C.time()
True
unset_introspect()

Clears this compute cell’s introspection text.

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'sage?', '', W)
sage: C.introspect()
False
sage: C.evaluate(username='sage')
sage: W.check_comp(9999)     # random output -- depends on computer speed
('d', Cell 0; in=sage?, out=)
sage: C.introspect()
[u'sage?', '']
sage: C.unset_introspect()
sage: C.introspect()
False
sage: W.quit()
sage: nb.delete()
update_html_output(output='')

Updates this compute cell’s the file list with HTML-style links or embeddings.

For interactive cells, the HTML output section is always empty, mainly because there is no good way to distinguish content (e.g., images in the current directory) that goes into the interactive template and content that would go here.

INPUT:

  • output - a string (default: ‘’); the new output

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W)
sage: C.evaluate()
sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
('d', Cell 0; in=plot(sin(x),0,5), out=
<html><font color='black'><img src='cell://sage0.png'></font></html>
<BLANKLINE>
)
sage: C.update_html_output()
sage: C.output_html()     # random output -- depends on computer speed
'<img src="/home/sage/0/cells/0/sage0.png?...">'
sage: W.quit()
sage: nb.delete()
url_to_self()

Returns a notebook URL for this compute cell.

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.url_to_self()
'/home/sage/0/cells/0'
version()

Returns this compute cell’s version number.

OUTPUT:

  • an integer

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.version()
0
sage: C.set_input_text('2+3')
sage: C.version()
1
word_wrap_cols()

Returns the number of columns for word wrapping this compute cell. This defaults to 70, but the default setting for a notebook is 72.

OUTPUT:

  • an integer

EXAMPLES:

sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', None)
sage: C.word_wrap_cols()
70
sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.word_wrap_cols()
72
sage: nb.delete()
worksheet()

Returns this compute cell’s worksheet object.

OUTPUT:

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.worksheet() is W
True
sage: nb.delete()
worksheet_filename()

Returns the filename of this compute cell’s worksheet object.

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.Cell(0, '2+3', '5', W)
sage: C.worksheet_filename()
'sage/0'
sage: nb.delete()
class sagenb.notebook.cell.Cell_generic
delete_output()

Delete all output in this cell. This is not executed - it is an abstract function that must be overwritten in a derived class.

EXAMPLES:

This function just raises a NotImplementedError, since it must be defined in a derived class.

sage: C = sagenb.notebook.cell.Cell_generic()
sage: C.delete_output()
...
NotImplementedError
is_interactive_cell()

Returns whether this cell uses sagenb.notebook.interact.interact() as a function call or decorator.

OUTPUT:

  • a boolean

EXAMPLES:

sage: from sagenb.notebook.cell import Cell_generic
sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: Cell_generic.is_interactive_cell(C)
False
sagenb.notebook.cell.ComputeCell
alias of Cell
class sagenb.notebook.cell.TextCell(id, text, worksheet)

Bases: sagenb.notebook.cell.Cell_generic

delete_output()

Delete all output in this text cell. This does nothing since text cells have no output.

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C
TextCell 0: 2+3
sage: C.delete_output()
sage: C
TextCell 0: 2+3
edit_text()

Returns the text to be displayed for this text cell in the Edit window.

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C.edit_text()
u'2+3'
html(wrap=None, div_wrap=True, do_print=False, do_math_parse=True, editing=False)

Returns HTML code for this text cell, including its contents and associated script elements.

INPUT:

  • wrap – an integer (default: None); number of columns to wrap at (not used)
  • div_wrap – a boolean (default: True); whether to wrap in a div (not used)
  • do_print - a boolean (default: False); whether to render the cell for printing
  • do_math_parse - a boolean (default: True); whether to process the contents for JSMath (see sagenb.notebook.jsmath.math_parse())
  • editing - a boolean (default: False); whether to open an editor for this cell

OUTPUT:

  • a string

EXAMPLES:

sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = nb.create_new_worksheet('Test', 'sage')
sage: C = sagenb.notebook.cell.TextCell(0, '2+3', W)
sage: C.html()
u'...text_cell...2+3...'
sage: C.set_input_text("$2+3$")
sage: C.html(do_math_parse=True)
u'...text_cell...class="math"...2+3...'
id()

Returns this text cell’s ID.

OUTPUT:

  • an integer or string

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C.id()
0
is_auto_cell()

Returns whether this is an automatically evaluated text cell. This is always false for TextCells.

OUTPUT:

  • a boolean

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C.is_auto_cell()
False
plain_text(prompts=False)

Returns a plain text version of this ext cell.

INPUT:

  • prompts - a boolean (default: False); whether to strip interpreter prompts from the beginning of each line

OUTPUT:

  • a string

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C.plain_text()
u'2+3'
sage: C = sagenb.notebook.cell.TextCell(0, 'ěščřžýáíéďĎ', None)
sage: C.plain_text()
u'ěščřž\xfd\xe1\xed\xe9ďĎ'
set_cell_output_type(typ='wrap')

Sets this text cell’s output type. This does nothing for TextCells.

INPUT:

  • typ - a string (default: ‘wrap’); the target output type

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C.set_cell_output_type("wrap")
set_input_text(input_text)

Sets the input text of this text cell.

INPUT:

  • input_text - a string; the new input text for this cell

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: C
TextCell 0: 2+3
sage: C.set_input_text("3+2")
sage: C
TextCell 0: 3+2
set_worksheet(worksheet, id=None)

Updates this text cell’s worksheet object and, optionally, its ID.

INPUT:

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', None)
sage: W = "worksheet object"
sage: C.set_worksheet(W)
sage: C.worksheet()
'worksheet object'
sage: C.set_worksheet(None, id=2)
sage: C.id()
2
worksheet()

Returns this text cell’s worksheet object

OUTPUT:

EXAMPLES:

sage: C = sagenb.notebook.cell.TextCell(0, '2+3', 'worksheet object')
sage: C.worksheet()
'worksheet object'
sagenb.notebook.cell.format_exception(s0, ncols)

Formats exceptions so they do not appear expanded by default.

INPUT:

  • s0 - a string
  • ncols - an integer; number of word wrap columns

OUTPUT:

  • a string

If s0 contains “notracebacks,” this function simply returns s0.

EXAMPLES:

sage: sagenb.notebook.cell.format_exception(sagenb.notebook.cell.TRACEBACK,80)
'\nTraceback (click to the left of this block for traceback)\n...\nTraceback (most recent call last):'
sage: sagenb.notebook.cell.format_exception(sagenb.notebook.cell.TRACEBACK + "notracebacks",80)
'Traceback (most recent call last):notracebacks'
sagenb.notebook.cell.number_of_rows(txt, ncols)

Returns the number of rows needed to display a string, given a maximum number of columns per row.

INPUT:

  • txt - a string; the text to “wrap”
  • ncols - an integer; the number of word wrap columns

OUTPUT:

  • an integer

EXAMPLES:

sage: from sagenb.notebook.cell import number_of_rows
sage: s = "asdfasdf\nasdfasdf\n"
sage: number_of_rows(s, 8)
2
sage: number_of_rows(s, 5)
4
sage: number_of_rows(s, 4)
4

Previous topic

Interact Functions in the Notebook

Next topic

A Worksheet.

This Page