Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in WebAgg When "S" Key is Pressed #3966

Closed
blink1073 opened this issue Jan 4, 2015 · 6 comments · Fixed by #3967
Closed

Error in WebAgg When "S" Key is Pressed #3966

blink1073 opened this issue Jan 4, 2015 · 6 comments · Fixed by #3967

Comments

@blink1073
Copy link
Member

I am using IPython 2.3.1 and ab549ac. To reproduce, run IPython and %paste the code below. Click on the figure and then press the 'S' key. The traceback below is printed and the figure becomes unresponsive.

import matplotlib
import itertools
import numpy as np
matplotlib.use('webagg')
import matplotlib.pyplot as plt
plt.close('all')
fig, ax = plt.subplots()
x = np.linspace(0,10,10000)
y = np.sin(x)
ln, = ax.plot(x,y)
evt = []
colors = iter(itertools.cycle(['r', 'g', 'b', 'k', 'c']))
def on_event(event):
    evt.append(event)
    ln.set_color(next(colors))
    fig.canvas.draw()
    fig.canvas.draw_idle()
fig.canvas.mpl_connect('button_press_event', on_event)
plt.show()
ERROR:tornado.application:Uncaught exception in /1/ws
Traceback (most recent call last):
  File "/home/silvester/anaconda/lib/python3.4/site-packages/tornado/websocket.py", line 369, in _run_callback
    callback(*args, **kwargs)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backends/backend_webagg.py", line 230, in on_message
    manager.handle_json(message)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backends/backend_webagg_core.py", line 361, in handle_json
    self.canvas.handle_event(content)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backends/backend_webagg_core.py", line 219, in handle_event
    self.key_press_event(key)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 1837, in key_press_event
    self.callbacks.process(s, event)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/cbook.py", line 534, in process
    proxy(*args, **kwargs)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/cbook.py", line 415, in __call__
    return mtd(*args, **kwargs)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 2597, in key_press
    key_press_handler(event, self.canvas, self.canvas.toolbar)
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 2490, in key_press_handler
    toolbar.save_figure()
  File "/home/silvester/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 3155, in save_figure
    raise NotImplementedError
NotImplementedError
@blink1073
Copy link
Member Author

I'd vote in favor of raising a warning here instead of crashing the app.

@blink1073
Copy link
Member Author

Specifically:

diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py
index ceb43ba..da3b994 100644
--- a/lib/matplotlib/backends/backend_webagg_core.py
+++ b/lib/matplotlib/backends/backend_webagg_core.py
@@ -19,6 +19,7 @@ import io
 import json
 import os
 import time
+import warnings

 import numpy as np

@@ -318,6 +319,10 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
         self.canvas.send_event(
             "rubberband", x0=-1, y0=-1, x1=-1, y1=-1)

+    def save_figure(self, *args):
+        """Save the current figure"""
+        warnings.warn('Save figure not implemented in Web Backend')
+

 class FigureManagerWebAgg(backend_bases.FigureManagerBase):
     ToolbarCls = NavigationToolbar2WebAgg

@pelson
Copy link
Member

pelson commented Jan 4, 2015

👍

On the super wish list - I'd love to have a little console on the webagg/nbagg interface which allowed us to propagate warnings to the user directly in the browser.

@blink1073
Copy link
Member Author

FYI I got a gittip for this. Ugh....

@blink1073
Copy link
Member Author

Well prime4commit to be precise.

@tacaswell
Copy link
Member

I think the projects position is to just ignore them. I also dug into it a while ago and I think it is worth some comically small amount in $ terms and no one hand actually claimed any mpl related coins yet.

I think I marked the one I got as spam to try and train google to suppress it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants