Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multimedia display of Python objects #43

Closed
stevengj opened this issue Sep 26, 2013 · 3 comments
Closed

multimedia display of Python objects #43

stevengj opened this issue Sep 26, 2013 · 3 comments

Comments

@stevengj
Copy link
Member

If a Python object supports one or more of the IPython display methods, it would be good to automatically implement the corresponding writemime method so that the object displays graphically in IJulia (etc.).

Will also need to overload mimewritable for PyObject, since in this case checking method_exists(writemime, ...) won't be the correct thing to do.

See also this julia-dev discussion.

cc: @fperez, @JeffBezanson

@stevengj
Copy link
Member Author

@fperez, how am I supposed to call the _repr_foo_ methods to get the corresponding data? I did:

using PyCall
@pyimport IPython.display as d
image = d.Image(url="http://127.0.0.1:8998/static/base/images/ipynblogo.png")

and then image[:_repr_png_](), but it returns nothing (i.e. Python None). The same thing happens in ipython with

import IPython.display as d
image = d.Image(url="http://127.0.0.1:8998/static/base/images/ipynblogo.png")
image._repr_png_()

What am I doing wrong?

@fperez
Copy link

fperez commented Sep 26, 2013

Sorry, since that particular image comes from a remote URL, it is being rendered via html:

image._repr_html_()

produces

u'<img src="http://127.0.0.1:8888/static/base/images/ipynblogo.png"/>'

If you had an image coming from a file, it would then call _repr_png_:

In [1]: from IPython.display import Image

In [2]: a=Image('logo/logo.png')

In [3]: a._repr_png_()[:20]  # just show the first 20 characters
Out[3]: '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x02\x08'

@stevengj
Copy link
Member Author

Ah, great. display("text/html", image[:_repr_html_]()) works in IJulia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants