def enable(ipython):
    global formatter_instance
    FormatterABC.register(IPyCollectionsFormatter)
    formatter_instance = IPyCollectionsFormatter(
        parent=get_ipython().display_formatter)
    ipython.display_formatter.formatters[
        formatter_instance.format_type] = formatter_instance
Пример #2
0
def add_display_formatter(new_formatter):
    from IPython.core.formatters import FormatterABC
    FormatterABC.register(new_formatter)
    from IPython.core.interactiveshell import InteractiveShell
    inst = InteractiveShell.instance()
    f = new_formatter(config=inst.display_formatter.config)
    inst.display_formatter.formatters[f.format_type] = f
Пример #3
0
#!/usr/bin/env python

from IPython.core.formatters import BaseFormatter, FormatterABC, Unicode, ObjectName


class VegaFormatter(BaseFormatter):
    """A Vega formatter.

    To define the callables that compute the Javascript representation of
    your objects, define a :meth:`_repr_vega_` method or use the
    :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
    that handle this.

    The return value of this formatter should be valid Vega JSON.
    """
    format_type = Unicode('json/vega')
    _return_type = (dict,)

    print_method = ObjectName('_repr_vega_')

FormatterABC.register(VegaFormatter)

from IPython import get_ipython
ip = get_ipython()
display = ip.display_formatter
formatter = VegaFormatter(parent=display)
display.formatters['json/vega'] = formatter

# vim: et sw=4 sts=4
Пример #4
0
            'rows': [map(format, row) for row in self.rows]
        }

from IPython.core.formatters import (
        BaseFormatter, FormatterABC, Unicode, ObjectName)

class TableFormatter(BaseFormatter):
    """A Table formatter.

    To define the callables that compute the Javascript representation of
    your objects, define a :meth:`_repr_table_` method or use the
    :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
    that handle this.

    The return value of this formatter should be a {header: [], rows: []}.
    Everything will be fed through `ipython display`.
    """
    format_type = Unicode('json/table')
    _return_type = (dict,)

    print_method = ObjectName('_repr_table_')

FormatterABC.register(TableFormatter)

display = ip.display_formatter
formatter = TableFormatter(parent=display)
display.formatters['json/table'] = formatter


# vim: et sw=4 sts=4
Пример #5
0
                'value': value}



from IPython.core.formatters import BaseFormatter, FormatterABC, Unicode, ObjectName

class LiveFormatter(BaseFormatter):
    """A LiveElement formatter.

    To define the callables that compute the Javascript representation of
    your objects, define a :meth:`_repr_live_` method or use the
    :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
    that handle this.

    The return value of this formatter should be a formatted JSON object
    """
    format_type = Unicode('json/live')
    _return_type = (dict,)

    print_method = ObjectName('_repr_live_')

FormatterABC.register(LiveFormatter)

from IPython import get_ipython
ip = get_ipython()
display = ip.display_formatter
formatter = LiveFormatter(parent=display)
display.formatters['json/live'] = formatter

# vim: et sw=4 sts=4