Skip to content

handle jpg/jpeg in the qtconsole #1643

Merged
merged 5 commits into from Apr 25, 2012

2 participants

@Carreau
IPython member
Carreau commented Apr 22, 2012

This add jpg/jpeg display in QtConsole, after png has been tried, of course.

@minrk minrk commented on an outdated diff Apr 22, 2012
IPython/frontend/qt/console/rich_ipython_widget.py
@@ -69,24 +83,38 @@ def _context_menu_make(self, pos):
def _handle_pyout(self, msg):
""" Overridden to handle rich data types, like SVG.
"""
+ def pre_image_append():
@minrk
IPython member
minrk added a note Apr 22, 2012

This function shouldn't be defined anew every time this is called. Just make it a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@minrk minrk and 1 other commented on an outdated diff Apr 22, 2012
IPython/frontend/qt/console/rich_ipython_widget.py
@@ -36,6 +44,12 @@ def __init__(self, *args, **kw):
# Dictionary for resolving document resource names to SVG data.
self._name_to_svg_map = {}
+ # Do we support jpg ?
+ # it seems that sometime jpg support is a plugin of QT, so try to assume
+ # it is not always supported.
+ self._supported_format = map(str, QtGui.QImageReader.supportedImageFormats())
+ self._jpg_supported = 'jpeg' in self._supported_format
@minrk
IPython member
minrk added a note Apr 22, 2012

There should be no attributes that are not always defined. Make sure this is defined in the class at the top level (_jpg_supported = Bool(False))

@Carreau
IPython member
Carreau added a note Apr 23, 2012

Well, it's true that I can put it at class top level, but I don't see why 'jpeg' in _supported_format can be not defined. and Bool traits would be overkill no ?

@minrk
IPython member
minrk added a note Apr 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@minrk
IPython member
minrk commented Apr 22, 2012

What happens to jpegs during export?

@Carreau
IPython member
Carreau commented Apr 23, 2012

jpeg are converted to png at export time. I thought it was overkill to try to keep the original file format, as well as proposing a full jpeg export. ( who likes jpeg for graphs anyway ? )
Moreover rich_text.py and HtmlExporter are, I think, written to work only with only one function to convert from the <image> tag of the qtconsole to file.

@minrk minrk commented on an outdated diff Apr 25, 2012
IPython/frontend/qt/console/rich_ipython_widget.py
@@ -65,6 +81,15 @@ def _context_menu_make(self, pos):
#---------------------------------------------------------------------------
# 'BaseFrontendMixin' abstract interface
#---------------------------------------------------------------------------
+ def _pre_image_append(self, msg, prompt_number):
+ """ Append the Out[] prompt and mke the output nicer
@minrk
IPython member
minrk added a note Apr 25, 2012

mke/make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@minrk
IPython member
minrk commented Apr 25, 2012

one last spelling error, and I think it's ready for merge.

Carreau added some commits Apr 22, 2012
@Carreau Carreau handle jpg/jpeg in the qtconsole.
This try to handle both image/jpeg image/jpg mimetype that arrives in
the qtconsole, when QImage support It,
note that image/jpg should never append, but is still supported.

It does not allows the export as html/jpeg. The jpeg will be converted
to png at save time.
c722f75
@Carreau Carreau pylinting 51ddac4
@Carreau Carreau more robust code
_pre_image_append as method
_jpg_supported as Bool Trait
193559c
@Carreau Carreau strip copyright 9e8cfdd
@Carreau Carreau do not handle image/jpg 9d7b5df
@Carreau
IPython member
Carreau commented Apr 25, 2012

Thanks, as I rebased on master to avoid recursive merge, I squashed the fix in the commit that introduced the docstring :-)
Should I merge ?

@minrk
IPython member
minrk commented Apr 25, 2012

Sure, go for it.

@Carreau Carreau merged commit f387e4a into ipython:master Apr 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.