Skip to content

Commit cfc92e2

Browse files
committed
Merge pull request matplotlib#3464 from tacaswell/nbagg_py3k
BUG : nbagg py3k compatibility
2 parents 53b6797 + 3a9757c commit cfc92e2

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import io
55
import os
6+
import six
67
from uuid import uuid4 as uuid
78

89
from IPython.display import display, Javascript, HTML
@@ -64,24 +65,26 @@ def connection_info():
6465
return '\n'.join(result)
6566

6667

68+
# Note: Version 3.2 icons, not the later 4.0 ones.
69+
# http://fontawesome.io/3.2.1/icons/
70+
_FONT_AWESOME_CLASSES = {
71+
'home': 'icon-home',
72+
'back': 'icon-arrow-left',
73+
'forward': 'icon-arrow-right',
74+
'zoom_to_rect': 'icon-check-empty',
75+
'move': 'icon-move',
76+
None: None
77+
}
78+
79+
6780
class NavigationIPy(NavigationToolbar2WebAgg):
68-
# Note: Version 3.2 icons, not the later 4.0 ones.
69-
# http://fontawesome.io/3.2.1/icons/
70-
_font_awesome_classes = {
71-
'home': 'icon-home',
72-
'back': 'icon-arrow-left',
73-
'forward': 'icon-arrow-right',
74-
'zoom_to_rect': 'icon-check-empty',
75-
'move': 'icon-move',
76-
None: None
77-
}
7881

7982
# Use the standard toolbar items + download button
8083
toolitems = [(text, tooltip_text,
81-
_font_awesome_classes[image_file], name_of_method)
84+
_FONT_AWESOME_CLASSES[image_file], name_of_method)
8285
for text, tooltip_text, image_file, name_of_method
8386
in NavigationToolbar2.toolitems
84-
if image_file in _font_awesome_classes]
87+
if image_file in _FONT_AWESOME_CLASSES]
8588

8689

8790
class FigureManagerNbAgg(FigureManagerWebAgg):
@@ -191,7 +194,10 @@ def send_json(self, content):
191194
def send_binary(self, blob):
192195
# The comm is ascii, so we always send the image in base64
193196
# encoded data URL form.
194-
data_uri = "data:image/png;base64,{0}".format(b64encode(blob))
197+
data = b64encode(blob)
198+
if six.PY3:
199+
data = data.decode('ascii')
200+
data_uri = "data:image/png;base64,{0}".format(data)
195201
self.comm.send({'data': data_uri})
196202

197203
def on_message(self, message):

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,26 @@ def stop_event_loop(self):
238238
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__
239239

240240

241+
_JQUERY_ICON_CLASSES = {
242+
'home': 'ui-icon ui-icon-home',
243+
'back': 'ui-icon ui-icon-circle-arrow-w',
244+
'forward': 'ui-icon ui-icon-circle-arrow-e',
245+
'zoom_to_rect': 'ui-icon ui-icon-search',
246+
'move': 'ui-icon ui-icon-arrow-4',
247+
'download': 'ui-icon ui-icon-disk',
248+
None: None,
249+
}
250+
251+
241252
class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
242-
_jquery_icon_classes = {
243-
'home': 'ui-icon ui-icon-home',
244-
'back': 'ui-icon ui-icon-circle-arrow-w',
245-
'forward': 'ui-icon ui-icon-circle-arrow-e',
246-
'zoom_to_rect': 'ui-icon ui-icon-search',
247-
'move': 'ui-icon ui-icon-arrow-4',
248-
'download': 'ui-icon ui-icon-disk',
249-
None: None,
250-
}
251253

252254
# Use the standard toolbar items + download button
253-
toolitems = [(text, tooltip_text, _jquery_icon_classes[image_file],
255+
toolitems = [(text, tooltip_text, _JQUERY_ICON_CLASSES[image_file],
254256
name_of_method)
255257
for text, tooltip_text, image_file, name_of_method
256258
in (backend_bases.NavigationToolbar2.toolitems +
257259
(('Download', 'Download plot', 'download', 'download'),))
258-
if image_file in _jquery_icon_classes]
260+
if image_file in _JQUERY_ICON_CLASSES]
259261

260262
def _init_toolbar(self):
261263
self.message = ''

0 commit comments

Comments
 (0)