Make IPython.core.display.Image less notebook-centric #1616

Merged
merged 9 commits into from May 2, 2012
View
@@ -422,7 +422,7 @@ class Image(DisplayObject):
_read_flags = 'rb'
- def __init__(self, data=None, url=None, filename=None, format=u'png', embed=False):
+ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=None):
"""Create a display an PNG/JPEG image given raw data.
When this object is returned by an expression or passed to the
@@ -441,10 +441,24 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=Fals
The format of the image data (png/jpeg/jpg). If a filename or URL is given
for format will be inferred from the filename extension.
embed : bool
- Should the image data be embedded in the notebook using a data URI (True)
- or be loaded using an <img> tag. Set this to True if you want the image
- to be viewable later with no internet connection. If a filename is given
- embed is always set to True.
+ Should the image data be embedded using a data URI (True) or be
+ loaded using an <img> tag. Set this to True if you want the image
+ to be viewable later with no internet connection in the notebook.
+
+ Default is `True`, unless the keyword argument `url` is set, then
+ default value is `False`.
+
+ Note that QtConsole is not able to display images if `embed` is set to `False`
+
+ Examples
+ --------
+ # embed implicitly True, works in qtconsole and notebook
+ Image('http://www.google.fr/images/srpr/logo3w.png')
+
+ # embed implicitly False, does not works in qtconsole but works in notebook if
+ # internet connection available
+ Image(url='http://www.google.fr/images/srpr/logo3w.png')
+
"""
if filename is not None:
ext = self._find_ext(filename)
@@ -460,7 +474,7 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=Fals
if ext == u'png':
format = u'png'
self.format = unicode(format).lower()
- self.embed = True if filename is not None else embed
+ self.embed = embed if embed is not None else (url is None)
super(Image, self).__init__(data=data, url=url, filename=filename)
def reload(self):
Oops, something went wrong.