|
3 | 3 | import json
|
4 | 4 | import io
|
5 | 5 | import os
|
| 6 | +import six |
6 | 7 | from uuid import uuid4 as uuid
|
7 | 8 |
|
8 | 9 | from IPython.display import display, Javascript, HTML
|
@@ -64,24 +65,26 @@ def connection_info():
|
64 | 65 | return '\n'.join(result)
|
65 | 66 |
|
66 | 67 |
|
| 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 | + |
67 | 80 | 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 |
| - } |
78 | 81 |
|
79 | 82 | # Use the standard toolbar items + download button
|
80 | 83 | toolitems = [(text, tooltip_text,
|
81 |
| - _font_awesome_classes[image_file], name_of_method) |
| 84 | + _FONT_AWESOME_CLASSES[image_file], name_of_method) |
82 | 85 | for text, tooltip_text, image_file, name_of_method
|
83 | 86 | in NavigationToolbar2.toolitems
|
84 |
| - if image_file in _font_awesome_classes] |
| 87 | + if image_file in _FONT_AWESOME_CLASSES] |
85 | 88 |
|
86 | 89 |
|
87 | 90 | class FigureManagerNbAgg(FigureManagerWebAgg):
|
@@ -191,7 +194,10 @@ def send_json(self, content):
|
191 | 194 | def send_binary(self, blob):
|
192 | 195 | # The comm is ascii, so we always send the image in base64
|
193 | 196 | # 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) |
195 | 201 | self.comm.send({'data': data_uri})
|
196 | 202 |
|
197 | 203 | def on_message(self, message):
|
|
0 commit comments