Esempio n. 1
0
    def __enter__(self):
        """
        Enter the restricted output context

        EXAMPLES::

            sage: from sage.repl.rich_output.display_manager import (
            ....:     get_display_manager, restricted_output)
            sage: dm = get_display_manager()
            sage: len(dm.supported_output()) > 1
            True
            sage: with restricted_output(dm, [dm.types.OutputPlainText]):
            ....:    dm.supported_output()
            frozenset({<class 'sage.repl.rich_output.output_basic.OutputPlainText'>})

            sage: dm.preferences.supplemental_plot
            'never'
            sage: dm.preferences.supplemental_plot = 'always'
            sage: with restricted_output(dm, [dm.types.OutputPlainText]):
            ....:    dm.preferences
            Display preferences:
            * graphics = disable
            * supplemental_plot = never
            * text is not specified
            sage: dm.preferences.supplemental_plot = 'never'
        """
        dm = self._display_manager
        self._original = dm._supported_output
        dm._supported_output = self._output_classes
        self._original_prefs = DisplayPreferences(dm.preferences)
        dm.preferences.graphics = 'disable'
        dm.preferences.supplemental_plot = 'never'
Esempio n. 2
0
    def default_preferences(self):
        """
        Return the backend's display preferences

        The default for the commandline is to not plot graphs since
        the launching of an external viewer is considered too
        disruptive.

        OUTPUT:

        Instance of
        :class:`~sage.repl.rich_output.preferences.DisplayPreferences`.

        EXAMPLES::

            sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
            sage: backend = BackendIPythonCommandline()
            sage: backend.default_preferences()
            Display preferences:
            * graphics is not specified
            * supplemental_plot = never
            * text is not specified
        """
        from sage.repl.rich_output.preferences import DisplayPreferences
        return DisplayPreferences(supplemental_plot='never')
Esempio n. 3
0
    def switch_backend(self, backend, **kwds):
        """
        Switch to a new backend

        INPUT:

        - ``backend`` -- instance of
          :class:`~sage.repl.rich_output.backend_base.BackendBase`.

        - ``kwds`` -- optional keyword arguments that are passed on to
          the
          :meth:`~sage.repl.rich_output.backend_base.BackendBase.install`
          method.

        OUTPUT:

        The previous backend.

        EXAMPLES::

            sage: from sage.repl.rich_output.backend_base import BackendSimple
            sage: simple = BackendSimple()
            sage: from sage.repl.rich_output import get_display_manager
            sage: dm = get_display_manager();  dm
            The Sage display manager using the doctest backend

            sage: previous = dm.switch_backend(simple)
            sage: dm
            The Sage display manager using the simple backend

        Restore the doctest backend::

            sage: dm.switch_backend(previous) is simple
            True
        """
        from sage.repl.rich_output.backend_base import BackendBase
        if not isinstance(backend, BackendBase):
            raise ValueError('backend must be instance of BackendBase class')
        supported = backend.supported_output()
        if not any(issubclass(out, OutputPlainText) for out in supported):
            raise ValueError('every backend must support plain text')
        try:
            self._backend.uninstall()
        except AttributeError:
            pass  # first time we switch
        # clear caches
        self._output_promotions = dict()
        self._supported_output = frozenset(
            map(self._demote_output_class, backend.supported_output()))
        # install new backend
        try:
            old_backend = self._backend
        except AttributeError:
            old_backend = None
        self._backend = backend
        self._backend.install(**kwds)
        self._preferences = DisplayPreferences(
            self._backend.default_preferences())
        return old_backend
Esempio n. 4
0
    def default_preferences(self):
        """
        Return the backend's display preferences

        Matches the IPython command line display preferences to keep
        the differences between that and the doctests to a minimum.

        OUTPUT:

        Instance of
        :class:`~sage.repl.rich_output.preferences.DisplayPreferences`.

        EXAMPLES::

            sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
            sage: backend = BackendIPythonCommandline()
            sage: backend.default_preferences()
            Display preferences:
            * graphics is not specified
            * supplemental_plot = never
            * text is not specified
        """
        from sage.repl.rich_output.preferences import DisplayPreferences
        return DisplayPreferences(supplemental_plot='never')
Esempio n. 5
0
    def default_preferences(self):
        """
        Return the backend's display preferences

        Override this method to change the default preferences when
        using your backend.

        OUTPUT:

        Instance of
        :class:`~sage.repl.rich_output.preferences.DisplayPreferences`.

        EXAMPLES::

            sage: from sage.repl.rich_output.backend_base import BackendBase
            sage: backend = BackendBase()
            sage: backend.default_preferences()
            Display preferences:
            * graphics is not specified
            * supplemental_plot is not specified
            * text is not specified
        """
        from sage.repl.rich_output.preferences import DisplayPreferences
        return DisplayPreferences()
 def default_preferences(self):
     return DisplayPreferences(text=self.__text)
 def default_preferences(self):
     if self.state.latex:
         text = 'latex'
     else:
         text = None
     return DisplayPreferences(text=text)