This module defines the IPython backends for sage.repl.rich_output.
Bases: sage.repl.rich_output.backend_base.BackendBase
Common base for the IPython UIs
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPython
sage: BackendIPython()._repr_()
Traceback (most recent call last):
NotImplementedError: derived classes must implement this method
Switch the Sage rich output to the IPython backend
INPUT:
No tests since switching away from the doctest rich output backend will break the doctests.
EXAMPLES:
sage: from sage.repl.interpreter import get_test_shell
sage: from sage.repl.rich_output.backend_ipython import BackendIPython
sage: backend = BackendIPython()
sage: shell = get_test_shell();
sage: backend.install(shell=shell)
sage: shell.run_cell('1+1')
2
Set the _ builtin variable.
Since IPython handles the history itself, this does nothing.
INPUT:
EXAMPLES:
sage: from sage.repl.interpreter import get_test_shell
sage: from sage.repl.rich_output.backend_ipython import BackendIPython
sage: backend = BackendIPython()
sage: backend.set_underscore_variable(123)
sage: _
0
Bases: sage.repl.rich_output.backend_ipython.BackendIPython
Backend for the IPython Command Line
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: BackendIPythonCommandline()
IPython command line
Show output without going back to the command line prompt.
This method is similar to the rich output displayhook(), except that it can be invoked at any time. On the Sage command line it launches viewers just like displayhook().
INPUT:
Same as displayhook().
OUTPUT:
This method does not return anything.
EXAMPLES:
sage: from sage.repl.rich_output.output_basic import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: backend.display_immediately(plain_text, plain_text)
Example plain text output
Backend implementation of the displayhook
INPUT:
OUTPUT:
The IPython commandline display hook returns the IPython display data, a pair of dictionaries. The first dictionary contains mime types as keys and the respective output as value. The second dictionary is metadata.
EXAMPLES:
sage: from sage.repl.rich_output.output_basic import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: backend.displayhook(plain_text, plain_text)
({u'text/plain': 'Example plain text output'}, {})
Launch the stand-alone jmol viewer
INPUT:
OUTPUT:
String. Human-readable message indicating that the viewer was launched.
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
sage: backend.launch_jmol(OutputSceneJmol.example(), 'Graphics3d object')
'Launched jmol viewer for Graphics3d object'
Launch the stand-alone java3d viewer
INPUT:
OUTPUT:
String. Human-readable message indicating that the viewer was launched.
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: from sage.repl.rich_output.output_graphics3d import OutputSceneWavefront
sage: backend.launch_sage3d(OutputSceneWavefront.example(), 'Graphics3d object')
'Launched Java 3D viewer for Graphics3d object'
Launch external viewer for the graphics file.
INPUT:
OUTPUT:
String. Human-readable message indicating whether the viewer was launched successfully.
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: backend.launch_viewer('/path/to/foo.bar', 'Graphics object')
'Launched bar viewer for Graphics object'
Return the outputs that are supported by the IPython commandline backend.
OUTPUT:
Iterable of output container classes, that is, subclass of OutputBase). The order is ignored.
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: supp = backend.supported_output(); supp # random output
set([<class 'sage.repl.rich_output.output_graphics.OutputImageGif'>,
...,
<class 'sage.repl.rich_output.output_graphics.OutputImagePng'>])
sage: from sage.repl.rich_output.output_basic import OutputLatex
sage: OutputLatex in supp
True
Bases: sage.repl.rich_output.backend_ipython.BackendIPython
Backend for the IPython Notebook
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: BackendIPythonNotebook()
IPython notebook
Show output immediately.
This method is similar to the rich output displayhook(), except that it can be invoked at any time.
Todo
This does not work currently.
INPUT/OUTPUT:
Same as displayhook().
EXAMPLES:
sage: from sage.repl.rich_output.output_basic import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: backend.display_immediately(plain_text, plain_text)
({u'text/plain': 'Example plain text output'}, {})
Backend implementation of the displayhook
INPUT:
OUTPUT:
The IPython notebook display hook returns the IPython display data, a pair of dictionaries. The first dictionary contains mime types as keys and the respective output as value. The second dictionary is metadata.
EXAMPLES:
sage: from sage.repl.rich_output.output_basic import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: backend.displayhook(plain_text, plain_text)
({u'text/plain': 'Example plain text output'}, {})
Return the outputs that are supported by the IPython notebook backend.
OUTPUT:
Iterable of output container classes, that is, subclass of OutputBase). The order is ignored.
EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: supp = backend.supported_output(); supp # random output
set([<class 'sage.repl.rich_output.output_graphics.OutputPlainText'>,
...,
<class 'sage.repl.rich_output.output_graphics.OutputImagePdf'>])
sage: from sage.repl.rich_output.output_basic import OutputLatex
sage: OutputLatex in supp
True
The IPython notebook cannot display gif images, see https://github.com/ipython/ipython/issues/2115
sage: from sage.repl.rich_output.output_graphics import OutputImageGif
sage: OutputImageGif in supp
False