3.2 A Cell

Module: sage.server.notebook.cell

A Cell.

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

Examples in this module are not automatically tested.

Module-level Functions

format_exception( s0, ncols)

Make it so excpetions don't appear expanded by default.

Input:

s0
- string
ncols
- integer
Output: string

If s0 contains "notracebacks" then this function always returns s0

        sage: sage.server.notebook.cell.format_exception(sage.server.notebook.cell.TRACEBACK,80)
        '
Traceback (click to the left for traceback)
...
Traceback (most recent call last):'
        sage: sage.server.notebook.cell.format_exception(sage.server.notebook.cell.TRACEBACK + "notracebacks",80)
        'Traceback (most recent call last):notracebacks'

number_of_rows( txt, ncols)

Class: Cell

class Cell
Cell( self, id, input, out, worksheet)

Functions: cell_output_type,$ \,$ changed_input_text,$ \,$ computing,$ \,$ delete_output,$ \,$ directory,$ \,$ do_time,$ \,$ doc_html,$ \,$ edit_text,$ \,$ evaluate,$ \,$ evaluated,$ \,$ files,$ \,$ files_html,$ \,$ has_output,$ \,$ html,$ \,$ html_in,$ \,$ html_new_cell_after,$ \,$ html_new_cell_before,$ \,$ html_out,$ \,$ id,$ \,$ input_text,$ \,$ interrupt,$ \,$ interrupted,$ \,$ introspect,$ \,$ introspect_html,$ \,$ is_asap,$ \,$ is_auto_cell,$ \,$ is_html,$ \,$ is_interacting,$ \,$ is_interactive_cell,$ \,$ is_last,$ \,$ is_no_output,$ \,$ next_id,$ \,$ notebook,$ \,$ output_html,$ \,$ output_text,$ \,$ parse_html,$ \,$ plain_text,$ \,$ process_cell_urls,$ \,$ sage,$ \,$ set_asap,$ \,$ set_cell_output_type,$ \,$ set_changed_input_text,$ \,$ set_id,$ \,$ set_input_text,$ \,$ set_introspect,$ \,$ set_introspect_html,$ \,$ set_is_html,$ \,$ set_no_output,$ \,$ set_output_text,$ \,$ set_worksheet,$ \,$ stop_interacting,$ \,$ time,$ \,$ unset_introspect,$ \,$ update_html_output,$ \,$ url_to_self,$ \,$ version,$ \,$ word_wrap_cols,$ \,$ worksheet,$ \,$ worksheet_filename

delete_output( self)

Delete all output in this cell.

sage: C = sage.server.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=

doc_html( self, [wrap=None], [div_wrap=True], [do_print=False])
Modified version of self.html for the doc browser. 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 formating) needs attention too.

evaluate( self, [introspect=False], [time=False], [username=None])

Input:

username
- name of user doing the evaluation
time
- if True return time computation takes
introspect
- either False or a pair [before_cursor, after_cursor] of strings.

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

            sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir())
            sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
            sage: W = nb.create_new_worksheet('Test', 'sage')
            sage: W.edit_save('Sage
{{{
3^5
}}}')
            sage: C = W.cell_list()[0]; C
            Cell 0; in=3^5, out=
            sage: C.evaluate(username='sage')
            sage: W.check_comp()
            ('d', Cell 0; in=3^5, out=
            243
            )
            sage: C
            Cell 0; in=3^5, out=
            243

evaluated( self)

Return True if this 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:

bool
- whether or not this cell has been evaluated in this session

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

            sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir())
            sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
            sage: W = nb.create_new_worksheet('Test', 'sage')
            sage: W.edit_save('Sage
{{{
2+3
///
20
}}}')
            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()
('d', Cell 0; in=2+3, out=
5
)

Now the output is right:

sage: C
Cell 0; in=2+3, out=
5

And the cell is considered to have been evaluated.

sage: C.evaluated()
True

interrupt( self)

Record that the calculation running in this cell was interrupted.

is_asap( self)

Return True if this is an asap cell, i.e., evaluation of it is done as soon as possible.

is_interactive_cell( self)

Return True if this cell contains the use of interact either as a function call or a decorator.

is_no_output( self)

Return True if this is an no_output cell, i.e., a cell for which we don't care at all about the output.

update_html_output( self, [output=])

Update the list of files with html-style links or embeddings for this cell.

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.

Special Functions: __cmp__,$ \,$ __init__,$ \,$ __repr__,$ \,$ _directory_name

Class: Cell_generic

class Cell_generic

Functions: delete_output,$ \,$ is_interactive_cell

delete_output( self)

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

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

sage: C = sage.server.notebook.cell.Cell_generic()
sage: C.delete_output()
Traceback (most recent call last):
...
NotImplementedError

Class: ComputeCell

class ComputeCell
ComputeCell( self, id, input, out, worksheet)

Functions: cell_output_type,$ \,$ changed_input_text,$ \,$ computing,$ \,$ delete_output,$ \,$ directory,$ \,$ do_time,$ \,$ doc_html,$ \,$ edit_text,$ \,$ evaluate,$ \,$ evaluated,$ \,$ files,$ \,$ files_html,$ \,$ has_output,$ \,$ html,$ \,$ html_in,$ \,$ html_new_cell_after,$ \,$ html_new_cell_before,$ \,$ html_out,$ \,$ id,$ \,$ input_text,$ \,$ interrupt,$ \,$ interrupted,$ \,$ introspect,$ \,$ introspect_html,$ \,$ is_asap,$ \,$ is_auto_cell,$ \,$ is_html,$ \,$ is_interacting,$ \,$ is_interactive_cell,$ \,$ is_last,$ \,$ is_no_output,$ \,$ next_id,$ \,$ notebook,$ \,$ output_html,$ \,$ output_text,$ \,$ parse_html,$ \,$ plain_text,$ \,$ process_cell_urls,$ \,$ sage,$ \,$ set_asap,$ \,$ set_cell_output_type,$ \,$ set_changed_input_text,$ \,$ set_id,$ \,$ set_input_text,$ \,$ set_introspect,$ \,$ set_introspect_html,$ \,$ set_is_html,$ \,$ set_no_output,$ \,$ set_output_text,$ \,$ set_worksheet,$ \,$ stop_interacting,$ \,$ time,$ \,$ unset_introspect,$ \,$ update_html_output,$ \,$ url_to_self,$ \,$ version,$ \,$ word_wrap_cols,$ \,$ worksheet,$ \,$ worksheet_filename

delete_output( self)

Delete all output in this cell.

sage: C = sage.server.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=

doc_html( self, [wrap=None], [div_wrap=True], [do_print=False])
Modified version of self.html for the doc browser. 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 formating) needs attention too.

evaluate( self, [introspect=False], [time=False], [username=None])

Input:

username
- name of user doing the evaluation
time
- if True return time computation takes
introspect
- either False or a pair [before_cursor, after_cursor] of strings.

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

            sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir())
            sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
            sage: W = nb.create_new_worksheet('Test', 'sage')
            sage: W.edit_save('Sage
{{{
3^5
}}}')
            sage: C = W.cell_list()[0]; C
            Cell 0; in=3^5, out=
            sage: C.evaluate(username='sage')
            sage: W.check_comp()
            ('d', Cell 0; in=3^5, out=
            243
            )
            sage: C
            Cell 0; in=3^5, out=
            243

evaluated( self)

Return True if this 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:

bool
- whether or not this cell has been evaluated in this session

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

            sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir())
            sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
            sage: W = nb.create_new_worksheet('Test', 'sage')
            sage: W.edit_save('Sage
{{{
2+3
///
20
}}}')
            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()
('d', Cell 0; in=2+3, out=
5
)

Now the output is right:

sage: C
Cell 0; in=2+3, out=
5

And the cell is considered to have been evaluated.

sage: C.evaluated()
True

interrupt( self)

Record that the calculation running in this cell was interrupted.

is_asap( self)

Return True if this is an asap cell, i.e., evaluation of it is done as soon as possible.

is_interactive_cell( self)

Return True if this cell contains the use of interact either as a function call or a decorator.

is_no_output( self)

Return True if this is an no_output cell, i.e., a cell for which we don't care at all about the output.

update_html_output( self, [output=])

Update the list of files with html-style links or embeddings for this cell.

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.

Special Functions: __cmp__,$ \,$ __init__,$ \,$ __repr__,$ \,$ _directory_name

Class: TextCell

class TextCell
TextCell( self, id, text, worksheet)

Functions: delete_output,$ \,$ edit_text,$ \,$ html,$ \,$ id,$ \,$ is_auto_cell,$ \,$ plain_text,$ \,$ set_cell_output_type,$ \,$ set_input_text,$ \,$ set_worksheet

delete_output( self)

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

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

html( self, ncols, [do_print=False], [do_math_parse=True])

Input:

do_math_parse
- bool (default: True) If True, call math_parse (defined in cell.py) on the html.

Special Functions: __cmp__,$ \,$ __init__,$ \,$ __repr__

__repr__( self)

String representation of this text cell.

sage: C = sage.server.notebook.cell.TextCell(0, '2+3', None)
sage: C.__repr__()
'TextCell 0: 2+3'

See About this document... for information on suggesting changes.