Cairo And IPython

Lawrence D'Oliveiro <[email protected]>
Newsgroups gmane.comp.lib.cairo
Organization Geek Central
Message-ID <[email protected]>
Just a note, for those wanting to have a simple testbed for trying out
Cairo snippets (or any other kind of snippets): IPython
<http://ipython.org/> can be very useful for this kind of thing. It
offers a notebook-style interface, where you can insert any number of
lines of code into a single cell, and execute that cell with
shift-enter. The notebook preserves its context as long as the kernel
instance is running, so you can incrementally execute additional code
that uses definitions set up by previous code.

With Python, you can display graphics, using the ImageWidget class:

    from IPython.html.widgets import ImageWidget

This takes a PNG stream, and inserts the resulting graphic into the
notebook display. For example, reading from a PNG file:

    ImageWidget(value = open("/path/to/example.png", "rb").read())

Or, having rendered an image to a Qahirah ImageSurface called, say
“pix”, you can display it as easily as

    ImageWidget(value = pix.to_png_bytes())
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.