Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Exception not handled in widgetlock() #23324

Closed
@delsuc

Description

@delsuc

Bug summary

( This bug was originally issued in ipympl: matplotlib/ipympl#471 )

I want to use a selector matplotlib.widgets.RectangleSelector , it is incompatible with zoom and pan
So I try to call widgetlock to prevent user from using zoom when the selector is active, hoping that the zoom or pan tools will not be blocked.
This does not work, but crashes rather.

Code for reproduction

import matplotlib.pyplot as plt
fig,ax = plt.subplots()
ax.plot([0,1],[0,1])
fig.canvas.widgetlock(ax)   # get the widget lock
plt.show()

Actual outcome

if you then hit the zoom or pan matplotlib button, which also try to get the lock, you get

Traceback (most recent call last):
  File "/home/mad/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_qt5.py", line 762, in zoom
    super().zoom(*args)
  File "/home/mad/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3110, in zoom
    self.canvas.widgetlock(self)
  File "/home/mad/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 41, in __call__
    raise ValueError('already locked')
ValueError: already locked
Aborted (core dumped)

Expected outcome

The lock is grabbed by the Selector, when zoom it tries to grab the lock, an exception is raised which is the normal behaviour of the lock, however the zoom tool should handle the exception and give-up.

Additional information

100% reproducible in my set-up

Operating system

Ubuntu 20.04

Matplotlib Version

3.3.2

Matplotlib Backend

Qt5Agg

Python version

3.8.5

Jupyter version

N/A

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!status: confirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions