##// END OF EJS Templates
Make PNG images in the Qt console work in Python 3.
Grahame Bowland -
Show More
@@ -83,7 +83,7 b' class RichIPythonWidget(IPythonWidget):'
83 self._append_html(self._make_out_prompt(prompt_number), True)
83 self._append_html(self._make_out_prompt(prompt_number), True)
84 # This helps the output to look nice.
84 # This helps the output to look nice.
85 self._append_plain_text('\n', True)
85 self._append_plain_text('\n', True)
86 self._append_png(decodestring(data['image/png']), True)
86 self._append_png(decodestring(data['image/png'].encode('ascii')), True)
87 self._append_html(self.output_sep2, True)
87 self._append_html(self.output_sep2, True)
88 else:
88 else:
89 # Default back to the plain text representation.
89 # Default back to the plain text representation.
@@ -104,7 +104,7 b' class RichIPythonWidget(IPythonWidget):'
104 elif data.has_key('image/png'):
104 elif data.has_key('image/png'):
105 # PNG data is base64 encoded as it passes over the network
105 # PNG data is base64 encoded as it passes over the network
106 # in a JSON structure so we decode it.
106 # in a JSON structure so we decode it.
107 png = decodestring(data['image/png'])
107 png = decodestring(data['image/png'].encode('ascii'))
108 self._append_png(png, True)
108 self._append_png(png, True)
109 else:
109 else:
110 # Default back to the plain text representation.
110 # Default back to the plain text representation.
@@ -19,7 +19,7 b' Authors'
19 # Imports
19 # Imports
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 from cStringIO import StringIO
22 from io import BytesIO
23
23
24 from IPython.utils.decorators import flag_calls
24 from IPython.utils.decorators import flag_calls
25
25
@@ -99,11 +99,11 b" def print_figure(fig, fmt='png'):"
99 fig.set_facecolor('white')
99 fig.set_facecolor('white')
100 fig.set_edgecolor('white')
100 fig.set_edgecolor('white')
101 try:
101 try:
102 string_io = StringIO()
102 bytes_io = BytesIO()
103 # use 72 dpi to match QTConsole's dpi
103 # use 72 dpi to match QTConsole's dpi
104 fig.canvas.print_figure(string_io, format=fmt, dpi=72,
104 fig.canvas.print_figure(bytes_io, format=fmt, dpi=72,
105 bbox_inches='tight')
105 bbox_inches='tight')
106 data = string_io.getvalue()
106 data = bytes_io.getvalue()
107 finally:
107 finally:
108 fig.set_facecolor(fc)
108 fig.set_facecolor(fc)
109 fig.set_edgecolor(ec)
109 fig.set_edgecolor(ec)
@@ -30,10 +30,10 b' class ZMQDisplayHook(object):'
30 def _encode_binary(format_dict):
30 def _encode_binary(format_dict):
31 pngdata = format_dict.get('image/png')
31 pngdata = format_dict.get('image/png')
32 if pngdata is not None:
32 if pngdata is not None:
33 format_dict['image/png'] = encodestring(pngdata)
33 format_dict['image/png'] = encodestring(pngdata).decode('ascii')
34 jpegdata = format_dict.get('image/jpeg')
34 jpegdata = format_dict.get('image/jpeg')
35 if jpegdata is not None:
35 if jpegdata is not None:
36 format_dict['image/jpeg'] = encodestring(jpegdata)
36 format_dict['image/jpeg'] = encodestring(jpegdata).decode('ascii')
37
37
38
38
39 class ZMQShellDisplayHook(DisplayHook):
39 class ZMQShellDisplayHook(DisplayHook):
General Comments 0
You need to be logged in to leave comments. Login now