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

Commit

Permalink
Merge branch 'public/3drenderers' of git://trac.sagemath.org/sage int…
Browse files Browse the repository at this point in the history
…o public/3drenderers
  • Loading branch information
nilesjohnson committed May 26, 2015
2 parents b6e0cc1 + 5cc7f56 commit c496e19
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/sage/plot/plot3d/renderers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

def register(renderer):
global registered_renderers
registered_renderers[renderer.__name__] = renderer
registered_renderers[renderer.name] = renderer()

def unregister(renderer):
del registered_renderers[renderer.__name__]
del registered_renderers[renderer.name]



Expand Down
50 changes: 37 additions & 13 deletions src/sage/repl/rich_output/backend_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def install(self, **kwds):
from sage.repl.display.formatter import SageDisplayFormatter
shell.display_formatter = SageDisplayFormatter(parent=shell)
shell.configurables.append(shell.display_formatter)

def set_underscore_variable(self, obj):
"""
Set the ``_`` builtin variable.
Since IPython handles the history itself, this does nothing.
INPUT:
Expand Down Expand Up @@ -108,7 +108,7 @@ def display_immediately(self, plain_text, rich_output):
if not formatted:
return
publish_display_data(data=formatted, metadata=metadata)


class BackendIPythonCommandline(BackendIPython):
"""
Expand Down Expand Up @@ -141,6 +141,7 @@ def default_preferences(self):
sage: backend.default_preferences()
Display preferences:
* graphics is not specified
* graphics3d is not specified
* supplemental_plot = never
* text is not specified
"""
Expand All @@ -163,7 +164,7 @@ def _repr_(self):
'IPython command line'
"""
return 'IPython command line'

def supported_output(self):
"""
Return the outputs that are supported by the IPython commandline backend.
Expand All @@ -179,7 +180,7 @@ def supported_output(self):
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'>,
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
Expand All @@ -196,7 +197,7 @@ def supported_output(self):
def displayhook(self, plain_text, rich_output):
"""
Backend implementation of the displayhook
INPUT:
- ``plain_text`` -- instance of
Expand Down Expand Up @@ -264,7 +265,7 @@ def display_immediately(self, plain_text, rich_output):
This method is similar to the rich output :meth:`displayhook`,
except that it can be invoked at any time. On the Sage command
line it launches viewers just like :meth:`displayhook`.
INPUT:
Same as :meth:`displayhook`.
Expand Down Expand Up @@ -390,7 +391,7 @@ def launch_sage3d(self, output_wavefront, plain_text):
.format(sage3d, obj))
return 'Launched Java 3D viewer for {0}'.format(plain_text)


class BackendIPythonNotebook(BackendIPython):
"""
Backend for the IPython Notebook
Expand All @@ -402,6 +403,29 @@ class BackendIPythonNotebook(BackendIPython):
IPython notebook
"""

def default_preferences(self):
"""
Return the backend's display preferences
OUTPUT:
Instance of
:class:`~sage.repl.rich_output.preferences.DisplayPreferences`.
EXAMPLES::
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: backend.default_preferences()
Display preferences:
* graphics is not specified
* graphics3d = ('Jmol', 'Tachyon')
* supplemental_plot is not specified
* text is not specified
"""
from sage.repl.rich_output.preferences import DisplayPreferences
return DisplayPreferences(graphics3d=('Jmol', 'Tachyon'))

def _repr_(self):
"""
Return string representation of the backend
Expand All @@ -418,7 +442,7 @@ def _repr_(self):
'IPython notebook'
"""
return 'IPython notebook'

def supported_output(self):
"""
Return the outputs that are supported by the IPython notebook backend.
Expand All @@ -434,7 +458,7 @@ def supported_output(self):
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'>,
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
Expand All @@ -458,7 +482,7 @@ def supported_output(self):
def displayhook(self, plain_text, rich_output):
"""
Backend implementation of the displayhook
INPUT:
- ``plain_text`` -- instance of
Expand Down Expand Up @@ -518,8 +542,8 @@ def displayhook(self, plain_text, rich_output):
jsmol = JSMolHtml(rich_output, height=500)
return ({u'text/html': jsmol.iframe(),
u'text/plain': plain_text.text.get(),
}, {})
}, {})
else:
raise TypeError('rich_output type not supported')


44 changes: 29 additions & 15 deletions src/sage/repl/rich_output/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@


class Property(property):

def __init__(self, name, allowed_values, doc=None):
r"""
Preference item
Expand All @@ -87,10 +87,11 @@ def __init__(self, name, allowed_values, doc=None):
- ``name`` -- string. The name of the property.
- ``allowed_values`` -- list/tuple/iterable of allowed values.
- ``allowed_values`` -- list/tuple/iterable of allowed values,
or ``None`` if all values are allowed
- ``doc`` -- string (optional). The docstring of the property.
EXAMPLES::
sage: from sage.repl.rich_output.preferences import Property
Expand All @@ -102,7 +103,10 @@ def __init__(self, name, allowed_values, doc=None):
"""
self.name = name
self.underscore_name = '_{0}'.format(name)
self.allowed_values = tuple(allowed_values)
if allowed_values is None:
self.allowed_values = None
else:
self.allowed_values = tuple(allowed_values)
self.__doc__ = doc = self._make_doc(doc)
super(Property, self).__init__(
fget=self.getter, fset=self.setter, fdel=self.deleter, doc=doc)
Expand Down Expand Up @@ -138,6 +142,8 @@ def _make_doc(self, doc):
* 2
"""
doc = dedent(doc)
if self.allowed_values is None:
return doc
doc += '\n\n'
doc += 'Allowed values:\n\n'
values_doc = []
Expand All @@ -162,11 +168,11 @@ def __repr__(self):
'foo'
"""
return self.name

def getter(self, prefs):
"""
Get the current value of the property
INPUT:
- ``prefs`` -- the :class:`PreferencesABC` instance that the
Expand All @@ -191,11 +197,11 @@ def getter(self, prefs):
return getattr(prefs, self.underscore_name)
except AttributeError:
return None

def setter(self, prefs, value):
"""
Get the current value of the property
INPUT:
- ``prefs`` -- the :class:`PreferencesABC` instance that the
Expand Down Expand Up @@ -229,15 +235,15 @@ def setter(self, prefs, value):
if value is None:
return self.deleter(prefs)
allowed = self.allowed_values
if value not in allowed:
if allowed is not None and value not in allowed:
raise ValueError('value must be unset (None) or one of {0}, got {1}'
.format(allowed, value))
setattr(prefs, self.underscore_name, value)

def deleter(self, prefs):
"""
Delete the current value of the property
INPUT:
- ``prefs`` -- the :class:`PreferencesABC` instance that the
Expand All @@ -263,7 +269,7 @@ def deleter(self, prefs):


class PreferencesABC(SageObject):

def __init__(self, *args, **kwds):
"""
Preferences for displaying graphics
Expand All @@ -277,7 +283,7 @@ def __init__(self, *args, **kwds):
instances. The property values will be inherited from left
to right, that is, later parents override values from
earlier parents.
- ``**kwds`` -- keyword arguments. Will be used to initialize
properties, and override inherited values if necessary.
Expand Down Expand Up @@ -347,7 +353,7 @@ def _add_option(cls, name, values, doc):
"""
prop = Property(name, values, doc)
setattr(cls, name, prop)

def available_options(self):
"""
Return the available options
Expand All @@ -368,7 +374,7 @@ def available_options(self):
if isinstance(value, Property):
options.append(value)
return tuple(sorted(options, key=str))

def _repr_(self):
r"""
Return a string representation
Expand Down Expand Up @@ -426,4 +432,12 @@ class DisplayPreferences(PreferencesABC):
)



DisplayPreferences._add_option(
'graphics3d',
None,
"""
List that gives the order of preference of renderers for
3d graphics. If ``None``, assumes that the backend doesn't
support 3d graphics.
"""
)

0 comments on commit c496e19

Please sign in to comment.