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

Already on GitHub? Sign in to your account

ValueError exception in drag_zoom (tk backend) #1944

Merged
merged 2 commits into from Jun 11, 2013

Conversation

Projects
None yet
5 participants

mdboom commented Jun 5, 2013

I have an application that uses Tkinter and matplotlib 1.1.1rc to visualize some plots and axvspans. From time to time, when I drag the plot in pan mode I've got this Exception and I should kill the application:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 271, in motion_notify_event
    FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event)
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1681, in motion_notify_event
    self.callbacks.process(s, event)
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 262, in process
    proxy(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 192, in __call__
    return mtd(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2660, in drag_zoom
    lastx, lasty, a, ind, lim, trans = self._xypress[0]
ValueError: need more than 2 values to unpack

It does not happen always, only from time to time so it makes difficult to reproduce it.

Member

pelson commented Apr 25, 2013

It does not happen always, only from time to time so it makes difficult to reproduce it.

Hmmm. I use the tk backend all the time and haven't seen this issue. Are you using specific Artist type or projection? Anything that might make it easier to reproduce will be valuable, otherwise I fear we might struggle to fix this one.

After some days testing version 1.2, I'm not able to reproduce this bug anymore. Maybe we can just close this issue.

@mdboom mdboom closed this May 6, 2013

Member

pelson commented May 8, 2013

After some days testing version 1.2, I'm not able to reproduce this bug anymore.

Ok thanks @marblestation. If you ever come across it again (or anybody else does) we can re-open and (hopefully) reproduce.

Cheers,

lyvic commented Jun 5, 2013

I encountered the same problem and could reproduce it (by chance):
mplve
The environment where this happend was the following:
A GUI created with Tkinter:

import matplotlib
import ttk
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter as tki

If I plot something and start with the zoom-Tool, left-click and start drawing that rectangle to select the area where it should zoom into, but then cancel it by clicking right at the same time and releasing both buttons (nothing happens). Then changing to the pan_tool and trying to move the picture...brings up this error repeatedly.
I'm using 1.2.1 now, it happened with 0.98.0 as well.
It's avoidable by not left-right-clicking while zooming, but it seems to be a common issue that people start draging and realising this is not what they want to do, so they try to escape their action by right clicking but then end up with the above problem

Owner

mdboom commented Jun 5, 2013

@lyvic: Thanks so much for this investigation and the clear explanation. I can reproduce it now and will look into a fix.

@mdboom mdboom reopened this Jun 5, 2013

@mdboom mdboom was assigned Jun 5, 2013

@mdboom mdboom Treat pushing a second mouse button during a rectangle zoom as "cance…
…l" rather than putting us in an unresolved state.
4b4093d
Owner

mdboom commented Jun 5, 2013

@marblestation , @lyvic: Can you confirm that the attached patch resolves your problem?

Owner

mdboom commented Jun 5, 2013

Note to self: backport this to 1.2.x

lyvic commented Jun 5, 2013

@mdboom I would love to, but I'm a little overwhelmed here. First contact with OOP and Python was about two months ago.
I inserted the lines you added into the backend_bases.py of 1.2.1 and it workes somewhat.
Switching back and forth between zooming and panning works. Once I right-blick-cancel the rectangle selection is killed, not canceled. I can't zoom rect anymore.
Panning works fine. I'm using the buttons on the toolbar
self.toolbar = NavigationToolbar2TkAgg(self.Paper, self.toolbarframe)
So interrupting the rectangle now works, switching to pan-tool works. Switching back to zoom is not possible. Only restarting my program helps.

@GBillotey GBillotey commented on an outdated diff Jun 8, 2013

lib/matplotlib/backend_bases.py
@@ -2863,6 +2863,19 @@ def press_pan(self, event):
def press_zoom(self, event):
"""the press mouse button in zoom to rect mode callback"""
+ # If we're already in the middle of a zoom, pressing another
+ # button works to "cancel"
+ if self._ids_zoom != []:
+ for zoom_id in self._ids_zoom:
+ self.canvas.mpl_disconnect(zoom_id)
+ self.zoom()
@GBillotey

GBillotey Jun 8, 2013

Contributor

I think there should be here a self._ids_zoom = [] line, to allow switching back to zoom again (addressing @lyvic comment).

Owner

mdboom commented Jun 10, 2013

Thanks. I think I have it working so that the zoom rectangle continues to work, even after a cancel.

@mdboom mdboom added a commit that referenced this pull request Jun 11, 2013

@mdboom mdboom Merge pull request #1944 from mdboom/cancel-zoom
ValueError exception in drag_zoom (tk backend)
ddf2c57

@mdboom mdboom merged commit ddf2c57 into matplotlib:v1.3.x Jun 11, 2013

1 check failed

default The Travis CI build failed
Details

@mdboom mdboom added a commit that referenced this pull request Jun 11, 2013

@mdboom mdboom Merge pull request #1944 from mdboom/cancel-zoom
ValueError exception in drag_zoom (tk backend)
eb58bf6

lyvic commented Jun 12, 2013

Great! Thanks for solving this.

@mdboom mdboom deleted the mdboom:cancel-zoom branch Aug 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment