Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit03589b1
committed
Stop relying on dead-reckoning mouse buttons for motion_notify_event.
Previously, for motion_notify_event, `event.attribute` was set bychecking the last button_press_event/button_release event. This isbrittle for the same reason as to why we introduced `event.modifiers`to improve over `event.key`, so introduce the more robust`event.buttons` (see detailed discussion in the attribute docstring).For a concrete example, consider e.g. from matplotlib import pyplot as plt from matplotlib.backends.qt_compat import QtWidgets def on_button_press(event): if event.button != 3: # Right-click. return menu = QtWidgets.QMenu() menu.addAction("Some menu action", lambda: None) menu.exec(event.guiEvent.globalPosition().toPoint()) fig = plt.figure() fig.canvas.mpl_connect("button_press_event", on_button_press) fig.add_subplot() plt.show()(connecting a contextual menu on right button click) where a right clickwhile having selected zoom mode on the toolbar starts a zoom mode thatstays on even after the mouse release (because the mouse release eventis received by the menu widget, not by the main canvas). This PR doesnot fix the issue, but will allow a followup fix (where themotion_notify_event associated with zoom mode will be able to firstcheck whether the button is indeed still pressed when the motionoccurs).Limitations, on macOS only (everything works on Linux and WindowsAFAICT):- tk only reports a single pressed button even if multiple buttons are pressed.- gtk4 spams the terminal with Gtk-WARNINGs: "Broken accounting of active state for widget ..." on right-clicks only; similar issues appear to have been reported a while ago to Gtk (https://gitlab.gnome.org/GNOME/gtk/-/issues/3356 and linked issues) but it's unclear whether any action was taken on their side.(Alternatively, some GUI toolkits have a "permissive" notion ofdrag events defined as mouse moves with a button pressed, which we coulduse as well to define event.button{,s} for motion_notify_event, bute.g. Qt attaches quite heavy semantics to drags which we probably don'twant to bother with.)1 parentc010a36 commit03589b1
File tree
9 files changed
+178
-44
lines changed- lib/matplotlib
- backends
- web_backend/js
- src
9 files changed
+178
-44
lines changedLines changed: 34 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1342 | 1342 |
| |
1343 | 1343 |
| |
1344 | 1344 |
| |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
1345 | 1367 |
| |
1346 | 1368 |
| |
1347 | 1369 |
| |
| |||
1374 | 1396 |
| |
1375 | 1397 |
| |
1376 | 1398 |
| |
1377 |
| - | |
| 1399 | + | |
| 1400 | + | |
1378 | 1401 |
| |
1379 | 1402 |
| |
1380 | 1403 |
| |
| |||
1385 | 1408 |
| |
1386 | 1409 |
| |
1387 | 1410 |
| |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
1388 | 1421 |
| |
1389 | 1422 |
| |
1390 | 1423 |
| |
|
Lines changed: 19 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 |
| - | |
| 22 | + | |
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| |||
293 | 293 |
| |
294 | 294 |
| |
295 | 295 |
| |
| 296 | + | |
296 | 297 |
| |
297 | 298 |
| |
298 | 299 |
| |
| |||
354 | 355 |
| |
355 | 356 |
| |
356 | 357 |
| |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
357 | 372 |
| |
358 | 373 |
| |
359 |
| - | |
360 |
| - | |
361 |
| - | |
362 |
| - | |
363 |
| - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
364 | 377 |
| |
365 | 378 |
| |
366 | 379 |
| |
|
Lines changed: 15 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 |
| - | |
10 |
| - | |
| 9 | + | |
| 10 | + | |
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| |||
156 | 156 |
| |
157 | 157 |
| |
158 | 158 |
| |
| 159 | + | |
159 | 160 |
| |
160 | 161 |
| |
161 | 162 |
| |
| |||
182 | 183 |
| |
183 | 184 |
| |
184 | 185 |
| |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
185 | 198 |
| |
186 | 199 |
| |
187 | 200 |
| |
|
Lines changed: 23 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
8 |
| - | |
9 |
| - | |
| 8 | + | |
| 9 | + | |
10 | 10 |
| |
11 | 11 |
| |
12 | 12 |
| |
| |||
151 | 151 |
| |
152 | 152 |
| |
153 | 153 |
| |
| 154 | + | |
154 | 155 |
| |
155 | 156 |
| |
156 | 157 |
| |
| |||
175 | 176 |
| |
176 | 177 |
| |
177 | 178 |
| |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
178 | 199 |
| |
179 | 200 |
| |
180 | 201 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
329 | 329 |
| |
330 | 330 |
| |
331 | 331 |
| |
| 332 | + | |
332 | 333 |
| |
333 | 334 |
| |
334 | 335 |
| |
| |||
396 | 397 |
| |
397 | 398 |
| |
398 | 399 |
| |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
399 | 407 |
| |
400 | 408 |
| |
401 | 409 |
| |
|
Lines changed: 14 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
25 |
| - | |
| 25 | + | |
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
| |||
283 | 283 |
| |
284 | 284 |
| |
285 | 285 |
| |
286 |
| - | |
287 |
| - | |
288 |
| - | |
289 | 286 |
| |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
290 | 297 |
| |
291 | 298 |
| |
292 | 299 |
| |
| |||
300 | 307 |
| |
301 | 308 |
| |
302 | 309 |
| |
303 |
| - | |
| 310 | + | |
| 311 | + | |
304 | 312 |
| |
305 | 313 |
| |
306 | 314 |
| |
| 315 | + | |
307 | 316 |
| |
308 | 317 |
| |
309 | 318 |
| |
|
Lines changed: 19 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
685 | 685 |
| |
686 | 686 |
| |
687 | 687 |
| |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
688 | 704 |
| |
689 | 705 |
| |
690 | 706 |
| |
| |||
794 | 810 |
| |
795 | 811 |
| |
796 | 812 |
| |
797 |
| - | |
798 |
| - | |
799 |
| - | |
| 813 | + | |
| 814 | + | |
800 | 815 |
| |
801 | 816 |
| |
802 | 817 |
| |
| |||
826 | 841 |
| |
827 | 842 |
| |
828 | 843 |
| |
| 844 | + | |
829 | 845 |
| |
830 | 846 |
| |
831 | 847 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
644 | 644 |
| |
645 | 645 |
| |
646 | 646 |
| |
| 647 | + | |
647 | 648 |
| |
648 | 649 |
| |
649 | 650 |
| |
|
0 commit comments
Comments
(0)