Skip to content

Commit

Permalink
Trac #17284: Fix command-line plotting keywords
Browse files Browse the repository at this point in the history
This should open a Tachyon-rendered plot (and this worked until very
recently):
{{{
sage: cube(viewer="tachyon")
}}}

The following patch fixes the problem (but probably not in the correct
way):
{{{
#!diff
diff --git a/src/sage/repl/display/formatter.py
b/src/sage/repl/display/formatter.py
index 670d208..a352a54 100644
--- a/src/sage/repl/display/formatter.py
+++ b/src/sage/repl/display/formatter.py
@@ -377,8 +377,6 @@ class
SageConsoleTextFormatter(SagePlainTextFormatter):
         """
         from sage.structure.sage_object import SageObject
         if isinstance(obj, SageObject) and hasattr(obj, '_graphics_'):
-            gfx = obj._graphics_()
-            if gfx:
-                gfx.launch_viewer()
-                return ''
+            obj.show()
+            return ''
         return super(SageConsoleTextFormatter, self).__call__(obj)
}}}

URL: http://trac.sagemath.org/17284
Reported by: jdemeyer
Ticket author(s): Volker Braun
Reviewer(s): Steven Trogdon, Karl-Dieter Crisman, Jeroen Demeyer, Martin
von Gagern
  • Loading branch information
Release Manager authored and vbraun committed Nov 11, 2014
2 parents 408233d + c84805c commit f02afd1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/sage/plot/plot3d/base.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cdef class Graphics3d(SageObject):
cdef public object texture
cdef object _aspect_ratio
cdef object _frame_aspect_ratio
cdef public object _extra_kwds
cdef public dict _extra_kwds

cdef class PrimitiveObject(Graphics3d):
pass
48 changes: 39 additions & 9 deletions src/sage/plot/plot3d/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ cdef class Graphics3d(SageObject):
.. automethod:: _graphics_
.. automethod:: __add__
"""
def __cinit__(self):
"""
The Cython constructor
EXAMPLES::
sage: gfx = sage.plot.plot3d.base.Graphics3d()
sage: gfx._extra_kwds
{}
"""
self._extra_kwds = dict()

def _repr_(self):
"""
Return a string representation.
Expand Down Expand Up @@ -107,17 +119,36 @@ cdef class Graphics3d(SageObject):
"""
from sage.structure.graphics_file import (
Mime, graphics_from_save, GraphicsFile)
if (mime_types is None) or (Mime.JMOL in mime_types):
# default to jmol
### First, figure out the best graphics format
can_view_jmol = (mime_types is None) or (Mime.JMOL in mime_types)
viewer = self._extra_kwds.get('viewer', None)
# make sure viewer is one of the supported options
if viewer not in [None, 'jmol', 'tachyon']:
import warnings
warnings.warn('viewer={0} is not supported'.format(viewer))
viewer = None
# select suitable default
if viewer is None:
viewer = 'jmol'
# fall back to 2d image if necessary
if viewer == 'jmol' and not can_view_jmol:
viewer = 'tachyon'
### Second, return the corresponding graphics file
if viewer == 'jmol':
from sage.misc.temporary_file import tmp_filename
filename = tmp_filename(
ext=os.path.extsep + Mime.extension(Mime.JMOL))
self.save(filename)
return GraphicsFile(filename, Mime.JMOL)
preference = [Mime.PNG, Mime.JPG]
return graphics_from_save(self.save, preference,
allowed_mime_types=mime_types,
figsize=figsize, dpi=dpi)
elif viewer == 'tachyon':
preference = [Mime.PNG, Mime.JPG]
figsize = self._extra_kwds.get('figsize', figsize)
dpi = self._extra_kwds.get('dpi', dpi)
return graphics_from_save(self.save, preference,
allowed_mime_types=mime_types,
figsize=figsize, dpi=dpi)
else:
assert False # unreachable

def __str__(self):
"""
Expand Down Expand Up @@ -1011,8 +1042,7 @@ end_scene""" % (render_params.antialiasing,
"""
opts = {}
opts.update(SHOW_DEFAULTS)
if self._extra_kwds is not None:
opts.update(self._extra_kwds)
opts.update(self._extra_kwds)
opts.update(kwds)

# Remove all of the keys that are viewing options, since the remaining
Expand Down Expand Up @@ -1399,7 +1429,7 @@ class Graphics3dGroup(Graphics3d):
self.all = list(all)
self.frame_aspect_ratio(optimal_aspect_ratios([a.frame_aspect_ratio() for a in all]))
self.aspect_ratio(optimal_aspect_ratios([a.aspect_ratio() for a in all]))
self._set_extra_kwds(optimal_extra_kwds([a._extra_kwds for a in all if a._extra_kwds is not None]))
self._set_extra_kwds(optimal_extra_kwds([a._extra_kwds for a in all]))

def __add__(self, other):
"""
Expand Down

0 comments on commit f02afd1

Please sign in to comment.