Closed
Labels
Milestone
Description
Bug summary
Somehow on CentOS Linux 7 keyboard-buttons are not forwarded with pick_events... on Windows 10 everything works as expected.
Code for reproduction
import matplotlib.pyplot as plt
f, ax = plt.subplots()
s = ax.scatter([1,2,3,4], [1,2,3,4], s=1000)
s.set_picker(True)
def doit(event):
if event.name == "button_press_event":
print(event.name, event.key)
if event.name == "pick_event":
print(event.name, event.mouseevent.key)
f.canvas.mpl_connect("button_press_event", doit)
f.canvas.mpl_connect("pick_event", doit)Actual outcome
When clicking on one of the datapoints while pressing the buttons 1 2 and 3 the following happens:
on Windows I get:
pick_event 1
button_press_event 1
pick_event 2
button_press_event 2
pick_event 3
button_press_event 3on CentOS Linux I get:
pick_event None
button_press_event 1
pick_event None
button_press_event 2
pick_event None
button_press_event 3Expected outcome
The same output for both OS
Operating system
Windows / Linux CentOS7
Matplotlib Version
3.6.1
Matplotlib Backend
Qt5Agg
Python version
3.9.13
Installation
conda
Activity
oscargus commentedon Oct 18, 2022
(As I have some issues with my Qt install, I tried it with tk and wx and get None for both types of events... Also on CentOS 7.)
raphaelquast commentedon Oct 18, 2022
@oscargus
Thanks for the response! That's even worse 😅 Do you have any idea what's going on here?
(as far as I know this is the correct way of determining if a key is pressed while a mouse-button is clicked...)
oscargus commentedon Oct 18, 2022
Oh, I wouldn't trust my statement so much...
Ler me fet back tomorrow (left the office now) with the proper outcome.
No, I do not really know what is going on, but I seem to recall that there is something with Wayland not reporting keys correctly. Will try to dig up that issue.
tacaswell commentedon Oct 20, 2022
@oscargus It took me a while to sort out, you have to hold down '1" (or really any key) as this is looking at the key board key not the mouse button). I was also thrown using 1, 2, 3 as those are the names of the mouse buttons. If I hold 'a' down I get
which matches the OP.
This a regression from 3.5, likely due to the refactoring of the event tracking done in #16931 but have not bisected to be sure.
attn @anntzer
anntzer commentedon Oct 20, 2022
Indeed, this occurs because both (1) attaching the key attribute to the mouseevent and (2) emitting the pick_event are now done by callbacks, and we just need to ensure that callback (1) comes before callback (2), i.e.
fixes the issue AFAICT.
Feel free to pick up the patch, or I'll make a PR if no one else does.
Fix key reporting in pick events
raphaelquast commentedon Oct 23, 2022
awesome! thanks for fixing this!!
Fix key reporting in pick events
Fix key reporting in pick events