Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Rich output framework
Browse files Browse the repository at this point in the history
This framework separates the construction of rich output (images,
mathjax, 3d scenes, ...) from the viewer details. Displaying rich
output is handled by interchangeable plugins that encapsulate the
differences between various notebooks, the command line, etc.
  • Loading branch information
vbraun committed Feb 15, 2015
1 parent ec265ac commit 7747261
Show file tree
Hide file tree
Showing 56 changed files with 4,690 additions and 972 deletions.
1 change: 1 addition & 0 deletions src/bin/sage-ipython
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Sage IPython startup script.
"""

from sage.repl.interpreter import SageTerminalApp

# installs the extra readline commands before the IPython initialization begins.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Enjoy Sage!
Table of Contents
=================

* :doc:`The Sage Command Line <repl/index>`
* :doc:`The Sage Command Line (REPL) <repl/index>`
* :doc:`The Sage Notebook <notebook/index>`

Calculus, Plotting
Expand Down
21 changes: 20 additions & 1 deletion src/doc/en/reference/repl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,26 @@ this works using a modified displayhook in Python.
sage/repl/display/pretty_print
sage/repl/display/fancy_repr
sage/repl/display/util
sage/repl/display/python_hook


Display Backend Infrastructure
------------------------------

.. toctree::
:maxdepth: 2

sage/repl/rich_output/display_manager
sage/repl/rich_output/preferences
sage/repl/rich_output/buffer
sage/repl/rich_output/output_basic
sage/repl/rich_output/output_graphics
sage/repl/rich_output/output_graphics3d
sage/repl/rich_output/output_catalog

sage/repl/rich_output/backend_base
sage/repl/rich_output/backend_test
sage/repl/rich_output/backend_doctest
sage/repl/rich_output/backend_ipython


.. include:: ../footer.txt
1 change: 0 additions & 1 deletion src/doc/en/reference/structure/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Basic Structures
sage/structure/element_wrapper
sage/structure/indexed_generators
sage/structure/global_options
sage/structure/graphics_file

sage/sets/cartesian_product
sage/sets/family
Expand Down
32 changes: 16 additions & 16 deletions src/doc/en/thematic_tutorials/polytutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Of course, you want to know what this object looks like:

::

sage: show(P1)
sage: P1.plot()
Graphics object consisting of 6 graphics primitives

.. end of output
Expand Down Expand Up @@ -70,7 +70,7 @@ translate each inequality into a vector. For example,
::

sage: altP1 = Polyhedron(ieqs=[(12, -4, 1), (26, 1, 7),(5,1,0), (28, 2, -9)])
sage: show(altP1)
sage: altP1.plot()
Graphics object consisting of 6 graphics primitives

.. end of output
Expand Down Expand Up @@ -119,15 +119,15 @@ to a rational\-lattice polytope. Let's look at that.

::

sage: show(P1dual)
sage: P1dual.plot()
Graphics object consisting of 6 graphics primitives


.. end of output
::

sage: show(P1)+show(P1dual)
sage: P1.plot() + P1dual.plot()
Graphics object consisting of 12 graphics primitives


Expand All @@ -139,7 +139,7 @@ very different size. Let's rescale.

::

sage: show((1/4)*P1)+show(4*P1dual)
sage: ((1/4)*P1).plot() + (4*P1dual).plot()
Graphics object consisting of 12 graphics primitives

.. end of output
Expand All @@ -155,7 +155,7 @@ example that makes the issue a bit clearer.
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 5 vertices
sage: P2dual = P2.polar(); P2dual
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 5 vertices
sage: show(P2)+show(P2dual)
sage: P2.plot() + P2dual.plot()
Graphics object consisting of 14 graphics primitives

.. end of output
Expand All @@ -166,7 +166,7 @@ at this...

::

sage: show(P2)+show(-1*P2dual)
sage: P2.plot() + (-1*P2dual).plot()
Graphics object consisting of 14 graphics primitives

.. end of output
Expand Down Expand Up @@ -223,14 +223,14 @@ visualization software such as Javaview and Jmol installed.)
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 5 vertices
sage: P4 = Polyhedron(vertices=[(-1,1,0),(1,1,0),(-1,0,1), (1,0,1),(0,-1,1),(0,1,1)]); P4
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices
sage: show(P3)+show(P4)
sage: P3.plot() + P4.plot()
Graphics3d Object

.. end of output
::

sage: show(P3+P4)
sage: (P3+P4).plot()
Graphics3d Object

.. end of output
Expand All @@ -241,14 +241,14 @@ syntaxes!

::

sage: int12 = P1.intersection(P2*.5); show(int12)
sage: int12 = P1.intersection(P2*.5); int12.plot()
Graphics object consisting of 7 graphics primitives

.. end of output
::

sage: int34 = P3 & P4; show(int34)
sage: int34 = P3 & P4; int34.plot()
Graphics3d Object

.. end of output
Expand All @@ -259,7 +259,7 @@ Should one wish to translate, one can.
::

sage: transP2 = P2.translation([2,1])
sage: show(P2)+show(transP2)
sage: P2.plot() + transP2.plot()
Graphics object consisting of 14 graphics primitives

.. end of output
Expand All @@ -269,21 +269,21 @@ Then of course we can take prisms, pyramids, and bipyramids of polytopes...

::

sage: show(P2.prism())
sage: P2.prism().plot()
Graphics3d Object

.. end of output
::

sage: show(P1.pyramid())
sage: P1.pyramid().plot()
Graphics3d Object

.. end of output
::

sage: show(P2dual.bipyramid())
sage: P2dual.bipyramid().plot()
Graphics3d Object

.. end of output
Expand All @@ -308,7 +308,7 @@ Let's look at a 4\-dimensional polytope.
::

sage: P8 = polytopes.n_cube(4)
sage: P8.show()
sage: P8.plot()
Graphics3d Object

.. end of output
Expand Down
1 change: 1 addition & 0 deletions src/ext/doctest/rich_output/example.canvas3d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{vertices:[{x:1,y:1,z:1},{x:-1,y:1,z:1},{x:-1,y:-1,z:1},{x:1,y:-1,z:1}],faces:[[0,1,2,3]],color:'008000'},{vertices:[{x:1,y:1,z:1},{x:-1,y:1,z:1},{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],faces:[[0,1,2,3]],color:'008000'},{vertices:[{x:1,y:1,z:1},{x:1,y:-1,z:1},{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],faces:[[0,1,2,3]],color:'008000'},{vertices:[{x:-1,y:1,z:1},{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],faces:[[0,1,2,3]],color:'008000'},{vertices:[{x:1,y:1,z:-1},{x:-1,y:1,z:-1},{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],faces:[[0,1,2,3]],color:'008000'},{vertices:[{x:1,y:-1,z:1},{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],faces:[[0,1,2,3]],color:'008000'}]
Binary file added src/ext/doctest/rich_output/example.dvi
Binary file not shown.
Binary file added src/ext/doctest/rich_output/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ext/doctest/rich_output/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ext/doctest/rich_output/example.pdf
Binary file not shown.
Binary file added src/ext/doctest/rich_output/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions src/ext/doctest/rich_output/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ext/doctest/rich_output/example_jmol.spt.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions src/ext/doctest/rich_output/example_lightwave/scene.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
newmtl texture177
Ka 0.2 0.2 0.5
Kd 0.4 0.4 1.0
Ks 0.0 0.0 0.0
illum 1
Ns 1
d 1
17 changes: 17 additions & 0 deletions src/ext/doctest/rich_output/example_lightwave/scene.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mtllib scene.mtl
g obj_1
usemtl texture177
v 0.5 0.5 0.5
v -0.5 0.5 0.5
v -0.5 -0.5 0.5
v 0.5 -0.5 0.5
v 0.5 0.5 -0.5
v -0.5 0.5 -0.5
v 0.5 -0.5 -0.5
v -0.5 -0.5 -0.5
f 1 2 3 4
f 1 5 6 2
f 1 4 7 5
f 6 5 7 8
f 7 4 3 8
f 3 2 6 8
8 changes: 6 additions & 2 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ def init_sage():
sage.doctest.DOCTEST_MODE=True
import sage.all_cmdline
sage.interfaces.quit.invalidate_all()
import sage.repl.display.python_hook
sys.displayhook = sage.repl.display.python_hook.DoctestDisplayHook()

# Use the rich output backend for doctest
from sage.repl.rich_output import get_display_manager
dm = get_display_manager()
from sage.repl.rich_output.backend_doctest import BackendDoctest
dm.switch_backend(BackendDoctest())

# Switch on extra debugging
from sage.structure.debug_options import debug
Expand Down
22 changes: 21 additions & 1 deletion src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,27 @@ def project(polyhedron):
.format(self.ambient_dim()))
return plot_method(*opts)

show = plot
def show(self, **kwds):
"""
Display graphics immediately
This method attempts to display the graphics immediately,
without waiting for the currently running code (if any) to
return to the command line. Be careful, calling it from within
a loop will potentially launch a large number of external
viewer programs.
INPUT:
- ``kwds`` -- optional keyword arguments. See :meth:`plot` for
the description of available options.
EXAMPLES::
sage: square = polytopes.n_cube(2)
sage: square.show(point='red')
"""
self.plot(**kwds).show()

def _repr_(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def permutahedron(self, n, project = True):
sage: perm4 = polytopes.permutahedron(4)
sage: perm4
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices
sage: polytopes.permutahedron(5).show() # long time
sage: polytopes.permutahedron(5).plot() # long time
Graphics3d Object
"""
verts = range(1,n+1)
Expand Down
15 changes: 0 additions & 15 deletions src/sage/geometry/polyhedron/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,20 +726,6 @@ def show(self, *args, **kwds):
deprecation(16625, 'use Projection.plot instead')
return self.plot(*args, **kwds)

def _graphics_(self, **kwds):
"""
Display projection graphically on the Sage command line.
See :meth:`~sage.plot.graphics.Graphics._graphics_`.
EXAMPLES::
sage: polytopes.n_cube(3).projection()._graphics_(
....: mime_types={'image/png'})
Graphics file image/png
"""
return self.plot()._graphics_(**kwds)

def _init_from_2d(self, polyhedron):
"""
Internal function: Initialize from polyhedron in
Expand All @@ -762,7 +748,6 @@ def _init_from_2d(self, polyhedron):
self._init_lines_arrows(polyhedron)
self._init_area_2d(polyhedron)


def _init_from_3d(self, polyhedron):
"""
Internal function: Initialize from polyhedron in
Expand Down
Loading

0 comments on commit 7747261

Please sign in to comment.