Skip to content

webAgg backend incorrectly reports middle clicks as right clicks #18171

Closed
@ianhi

Description

@ianhi

Bug report

Bug summary
The webAgg backend reports middle click events as right click events. This is caused by these lines:

# The right mouse button pops up a context menu, which
# doesn't work very well, so use the middle mouse button
# instead. It doesn't seem that it's possible to disable
# the context menu in recent versions of Chrome. If this
# is resolved, please also adjust the docstring in MouseEvent.
if button == 2:
button = 3

I don't think I entirely understand the issue described by that comment but I'd argue that it is better to allow users to make the choice to listen for middle clicks rather than to report middle click as right click. Also there does not seem be anything in MouseEvent docstring about this: https://matplotlib.org/3.3.0/api/backend_bases_api.html#matplotlib.backend_bases.MouseEvent

I ran into this when using the ipympl backend (xref matplotlib/ipympl#254)
Code for reproduction

In the notebook:

import ipywidgets as widget
import matplotlib.pyplot as plt
%matplotlib widget

out = widgets.Output()
@out.capture()
def callback(event):
    print(event.button)
    
plt.ioff(); fig,ax = plt.subplots(); plt.ion()
fig.canvas.mpl_connect('button_press_event', callback)
fs = 15
ax.text(0.1,0.1,'left click here', fontsize=fs)
ax.text(0.5,0.5,'middle click here', fontsize=fs)
ax.text(0.7,0.8,'right click here', fontsize=fs)
widgets.HBox([out,fig.canvas])

Actual outcome

jupyter

Expected outcome
in ipython it gives this
ipython

Matplotlib version

  • Operating system: Ubuntu 20.04
  • Matplotlib version: 3.30
  • Matplotlib backend (print(matplotlib.get_backend())): 'module://ipympl.backend_nbagg'
  • Python version: 3.8.5
  • Jupyter version (if applicable): jupyterlab 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions