Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 130 lines (99 sloc) 3.753 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
# -*- coding: utf-8 -*-
"""Top-level display functions for displaying object in different formats.

Authors:

* Brian Granger
"""

#-----------------------------------------------------------------------------
# Copyright (C) 2008-2010 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Main functions
#-----------------------------------------------------------------------------

def display(*objs, **kwargs):
    """Display a Python object in all frontends.

By default all representations will be computed and sent to the frontends.
Frontends can decide which representation is used and how.

Parameters
----------
objs : tuple of objects
The Python objects to display.
include : list or tuple, optional
A list of format type strings (MIME types) to include in the
format data dict. If this is set *only* the format types included
in this list will be computed.
exclude : list or tuple, optional
A list of format type string (MIME types) to exclue in the format
data dict. If this is set all format types will be computed,
except for those included in this argument.
"""
    include = kwargs.get('include')
    exclude = kwargs.get('exclude')
    
    from IPython.core.interactiveshell import InteractiveShell
    inst = InteractiveShell.instance()
    format = inst.display_formatter.format
    publish = inst.display_pub.publish

    for obj in objs:
        format_dict = format(obj, include=include, exclude=exclude)
        publish('IPython.core.display.display', format_dict)


def display_pretty(*objs):
    """Display the pretty (default) representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain'])


def display_html(*objs):
    """Display the HTML representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','text/html'])


def display_svg(*objs):
    """Display the SVG representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','image/svg+xml'])


def display_png(*objs):
    """Display the PNG representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','image/png'])


def display_latex(*objs):
    """Display the LaTeX representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','text/latex'])


def display_json(*objs):
    """Display the JSON representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','application/json'])


def display_javascript(*objs):
    """Display the Javascript representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
    display(*objs, include=['text/plain','application/javascript'])
Something went wrong with that request. Please try again.