This class is used to express display preferences that are not simply a choice of a particular output format. For example, whether to prefer vector over raster graphics. By convention, the value None is always a valid value for a preference and means no particular preference.
EXAMPLES:
sage: from sage.repl.rich_output.preferences import DisplayPreferences
sage: prefs = DisplayPreferences()
sage: prefs.available_options()
(graphics, text)
sage: prefs.text is None
True
sage: prefs.text = 'ascii_art'
sage: prefs.text
'ascii_art'
sage: prefs
Display preferences:
* graphics is not specified
* text = ascii_art
Properties can be unset by deleting them or by assinging None:
sage: prefs.text = 'ascii_art'
sage: del prefs.text
sage: prefs.text is None
True
sage: prefs.text = 'ascii_art'
sage: prefs.text = None
sage: prefs.text is None
True
Properties have documentation attached:
sage: import pydoc
sage: doc = pydoc.render_doc(prefs)
sage: assert ' graphics' in doc
sage: assert ' Preferred graphics format' in doc
sage: assert ' text' in doc
sage: assert ' Which textual representation is preferred' in doc
Values can also be specified as keyword arguments to the constructor:
sage: DisplayPreferences(text='latex')
Display preferences:
* graphics is not specified
* text = latex
Todo
A value-checking preference system should be used elsewhere in Sage, too. The class here is just a simple implementation, a proper implementation would use a metaclass to construct the preference items.
Bases: sage.repl.rich_output.preferences.PreferencesABC
Preferences for displaying graphics
These can be preferences expressed by the user or by the display backend. They are specified as keyword arguments.
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.preferences import DisplayPreferences
sage: p1 = DisplayPreferences(graphics='vector')
sage: p2 = DisplayPreferences(graphics='raster')
sage: DisplayPreferences(p1, p2)
Display preferences:
* graphics = raster
* text is not specified
If specified in the opposite order, the setting from p1 is inherited:
sage: DisplayPreferences(p2, p1)
Display preferences:
* graphics = vector
* text is not specified
Further keywords override:
sage: DisplayPreferences(p2, p1, graphics='disable')
Display preferences:
* graphics = disable
* text is not specified
Preferred graphics format
Allowed values:
Which textual representation is preferred
Allowed values:
Bases: sage.structure.sage_object.SageObject
Preferences for displaying graphics
These can be preferences expressed by the user or by the display backend. They are specified as keyword arguments.
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.preferences import DisplayPreferences
sage: p1 = DisplayPreferences(graphics='vector')
sage: p2 = DisplayPreferences(graphics='raster')
sage: DisplayPreferences(p1, p2)
Display preferences:
* graphics = raster
* text is not specified
If specified in the opposite order, the setting from p1 is inherited:
sage: DisplayPreferences(p2, p1)
Display preferences:
* graphics = vector
* text is not specified
Further keywords override:
sage: DisplayPreferences(p2, p1, graphics='disable')
Display preferences:
* graphics = disable
* text is not specified
Bases: property
Preference item
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.preferences import Property
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
sage: prop.__doc__
'The Foo Property\n\nAllowed values:\n\n* ``None`` (default): no preference\n\n* 0\n\n* 1\n\n* 2'
sage: prop.allowed_values
(0, 1, 2)
Delete the current value of the property
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
sage: prefs = PreferencesABC()
sage: prop.getter(prefs) is None
True
sage: prop.setter(prefs, 1)
sage: prop.deleter(prefs)
sage: prop.getter(prefs) is None
True
Get the current value of the property
INPUT:
OUTPUT:
One of the allowed values or None if not set.
EXAMPLES:
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
sage: prefs = PreferencesABC()
sage: prop.getter(prefs) is None
True
sage: prop.setter(prefs, 1)
sage: prop.getter(prefs)
1
Get the current value of the property
INPUT:
OUTPUT:
This method does not return anything. A ValueError is raised if the given value is not one of the allowed values.
EXAMPLES:
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
sage: prefs = PreferencesABC()
sage: prop.getter(prefs) is None
True
sage: prop.setter(prefs, 1)
sage: prop.getter(prefs)
1
sage: prop.setter(prefs, None)
sage: prop.getter(prefs) is None
True