Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make PNG images in the Qt console work in Python 3.

  • Loading branch information...
commit 307b083bb3101fd226dced2c366b8c4ab9a78d40 1 parent 786b191
@grahame grahame authored committed
View
4 IPython/frontend/qt/console/rich_ipython_widget.py
@@ -83,7 +83,7 @@ def _handle_pyout(self, msg):
self._append_html(self._make_out_prompt(prompt_number), True)
# This helps the output to look nice.
self._append_plain_text('\n', True)
- self._append_png(decodestring(data['image/png']), True)
+ self._append_png(decodestring(data['image/png'].encode('ascii')), True)
self._append_html(self.output_sep2, True)
else:
# Default back to the plain text representation.
@@ -104,7 +104,7 @@ def _handle_display_data(self, msg):
elif data.has_key('image/png'):
# PNG data is base64 encoded as it passes over the network
# in a JSON structure so we decode it.
- png = decodestring(data['image/png'])
+ png = decodestring(data['image/png'].encode('ascii'))
self._append_png(png, True)
else:
# Default back to the plain text representation.
View
8 IPython/lib/pylabtools.py
@@ -19,7 +19,7 @@
# Imports
#-----------------------------------------------------------------------------
-from cStringIO import StringIO
+from io import BytesIO
from IPython.utils.decorators import flag_calls
@@ -99,11 +99,11 @@ def print_figure(fig, fmt='png'):
fig.set_facecolor('white')
fig.set_edgecolor('white')
try:
- string_io = StringIO()
+ bytes_io = BytesIO()
# use 72 dpi to match QTConsole's dpi
- fig.canvas.print_figure(string_io, format=fmt, dpi=72,
+ fig.canvas.print_figure(bytes_io, format=fmt, dpi=72,
bbox_inches='tight')
- data = string_io.getvalue()
+ data = bytes_io.getvalue()
finally:
fig.set_facecolor(fc)
fig.set_edgecolor(ec)
View
4 IPython/zmq/displayhook.py
@@ -30,10 +30,10 @@ def set_parent(self, parent):
def _encode_binary(format_dict):
pngdata = format_dict.get('image/png')
if pngdata is not None:
- format_dict['image/png'] = encodestring(pngdata)
+ format_dict['image/png'] = encodestring(pngdata).decode('ascii')
jpegdata = format_dict.get('image/jpeg')
if jpegdata is not None:
- format_dict['image/jpeg'] = encodestring(jpegdata)
+ format_dict['image/jpeg'] = encodestring(jpegdata).decode('ascii')
class ZMQShellDisplayHook(DisplayHook):
Please sign in to comment.
Something went wrong with that request. Please try again.