Commit 44b6055
committed
Make it easier to improve UI event metadata.
Currently, UI events (MouseEvent, KeyEvent, etc.) are generated by
letting the GUI-specific backends massage the native event objects into
a list of args/kwargs and then call
`FigureCanvasBase.motion_notify_event`/`.key_press_event`/etc. This
makes it a bit tricky to improve the metadata on the events, because one
needs to change the signature on both the `FigureCanvasBase` method and
the event class. Moreover, the `motion_notify_event`/etc. methods are
directly bound as event handlers in the gtk3 and tk backends, and thus
have incompatible signatures there.
Instead, the native GUI handlers can directly construct the relevant
event objects and trigger the events themselves; a new `Event.process`
helper method makes this even shorter (and allows to keep factoring some
common functionality e.g. for tracking the last pressed button or key).
As an example, this PR also updates figure_leave_event to always
correctly set the event location based on the *current* cursor position,
instead of the last triggered location event (which may be outdated);
this can now easily be done on a backend-by-backend basis, instead of
coordinating the change with FigureCanvasBase.figure_leave_event.
This also exposed another (minor) issue, in that resize events often
trigger *two* calls to draw_idle -- one in the GUI-specific handler, and
one in FigureCanvasBase.draw_idle (now moved to ResizeEvent.process, but
should perhaps instead be a callback autoconnected to "resize_event") --
could probably be fixed later.1 parent e050f6e commit 44b6055
11 files changed
Lines changed: 243 additions & 252 deletions
File tree
- doc/api/next_api_changes
- lib/matplotlib
- backends
- tests
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
| 491 | + | |
491 | 492 | | |
492 | 493 | | |
493 | 494 | | |
| |||
496 | 497 | | |
497 | 498 | | |
498 | 499 | | |
499 | | - | |
| 500 | + | |
| 501 | + | |
500 | 502 | | |
501 | 503 | | |
502 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1191 | 1191 | | |
1192 | 1192 | | |
1193 | 1193 | | |
| 1194 | + | |
1194 | 1195 | | |
1195 | 1196 | | |
1196 | 1197 | | |
1197 | 1198 | | |
1198 | 1199 | | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
1199 | 1204 | | |
1200 | 1205 | | |
1201 | 1206 | | |
| |||
1238 | 1243 | | |
1239 | 1244 | | |
1240 | 1245 | | |
| 1246 | + | |
1241 | 1247 | | |
1242 | 1248 | | |
1243 | 1249 | | |
1244 | 1250 | | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
1245 | 1255 | | |
1246 | 1256 | | |
1247 | 1257 | | |
1248 | 1258 | | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
1249 | 1268 | | |
1250 | 1269 | | |
1251 | 1270 | | |
| |||
1360 | 1379 | | |
1361 | 1380 | | |
1362 | 1381 | | |
| 1382 | + | |
1363 | 1383 | | |
1364 | 1384 | | |
1365 | 1385 | | |
1366 | 1386 | | |
1367 | 1387 | | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
1368 | 1392 | | |
1369 | 1393 | | |
1370 | 1394 | | |
| |||
1403 | 1427 | | |
1404 | 1428 | | |
1405 | 1429 | | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
1406 | 1435 | | |
1407 | 1436 | | |
1408 | 1437 | | |
1409 | 1438 | | |
1410 | 1439 | | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
1411 | 1451 | | |
1412 | 1452 | | |
1413 | 1453 | | |
| |||
1448 | 1488 | | |
1449 | 1489 | | |
1450 | 1490 | | |
| 1491 | + | |
1451 | 1492 | | |
1452 | 1493 | | |
| 1494 | + | |
| 1495 | + | |
1453 | 1496 | | |
1454 | 1497 | | |
1455 | 1498 | | |
| |||
1490 | 1533 | | |
1491 | 1534 | | |
1492 | 1535 | | |
| 1536 | + | |
1493 | 1537 | | |
1494 | 1538 | | |
1495 | 1539 | | |
1496 | 1540 | | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
1497 | 1548 | | |
1498 | 1549 | | |
1499 | 1550 | | |
| |||
1651 | 1702 | | |
1652 | 1703 | | |
1653 | 1704 | | |
| 1705 | + | |
1654 | 1706 | | |
1655 | 1707 | | |
1656 | 1708 | | |
1657 | 1709 | | |
1658 | 1710 | | |
1659 | 1711 | | |
| 1712 | + | |
1660 | 1713 | | |
1661 | 1714 | | |
1662 | 1715 | | |
| |||
1666 | 1719 | | |
1667 | 1720 | | |
1668 | 1721 | | |
| 1722 | + | |
1669 | 1723 | | |
1670 | 1724 | | |
1671 | 1725 | | |
| |||
1682 | 1736 | | |
1683 | 1737 | | |
1684 | 1738 | | |
| 1739 | + | |
1685 | 1740 | | |
1686 | 1741 | | |
1687 | 1742 | | |
| |||
1692 | 1747 | | |
1693 | 1748 | | |
1694 | 1749 | | |
| 1750 | + | |
1695 | 1751 | | |
1696 | 1752 | | |
1697 | 1753 | | |
| |||
1702 | 1758 | | |
1703 | 1759 | | |
1704 | 1760 | | |
| 1761 | + | |
1705 | 1762 | | |
1706 | 1763 | | |
1707 | 1764 | | |
| |||
1715 | 1772 | | |
1716 | 1773 | | |
1717 | 1774 | | |
| 1775 | + | |
1718 | 1776 | | |
1719 | 1777 | | |
1720 | 1778 | | |
| |||
1735 | 1793 | | |
1736 | 1794 | | |
1737 | 1795 | | |
| 1796 | + | |
1738 | 1797 | | |
1739 | 1798 | | |
1740 | 1799 | | |
| |||
1752 | 1811 | | |
1753 | 1812 | | |
1754 | 1813 | | |
| 1814 | + | |
1755 | 1815 | | |
1756 | 1816 | | |
1757 | 1817 | | |
| |||
1776 | 1836 | | |
1777 | 1837 | | |
1778 | 1838 | | |
| 1839 | + | |
1779 | 1840 | | |
1780 | 1841 | | |
1781 | 1842 | | |
| |||
1801 | 1862 | | |
1802 | 1863 | | |
1803 | 1864 | | |
| 1865 | + | |
1804 | 1866 | | |
1805 | 1867 | | |
1806 | 1868 | | |
| |||
1817 | 1879 | | |
1818 | 1880 | | |
1819 | 1881 | | |
| 1882 | + | |
1820 | 1883 | | |
1821 | 1884 | | |
1822 | 1885 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
219 | 220 | | |
220 | 221 | | |
221 | 222 | | |
222 | | - | |
| 223 | + | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
244 | | - | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | | - | |
| 274 | + | |
274 | 275 | | |
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
278 | 279 | | |
279 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
280 | 289 | | |
281 | 290 | | |
282 | 291 | | |
| |||
291 | 300 | | |
292 | 301 | | |
293 | 302 | | |
294 | | - | |
295 | | - | |
| 303 | + | |
| 304 | + | |
296 | 305 | | |
297 | 306 | | |
298 | 307 | | |
| |||
311 | 320 | | |
312 | 321 | | |
313 | 322 | | |
314 | | - | |
| 323 | + | |
| 324 | + | |
315 | 325 | | |
316 | 326 | | |
317 | 327 | | |
318 | 328 | | |
319 | 329 | | |
320 | 330 | | |
321 | | - | |
| 331 | + | |
| 332 | + | |
322 | 333 | | |
323 | 334 | | |
324 | 335 | | |
325 | 336 | | |
326 | 337 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
333 | 346 | | |
334 | 347 | | |
335 | 348 | | |
| |||
376 | 389 | | |
377 | 390 | | |
378 | 391 | | |
379 | | - | |
| 392 | + | |
380 | 393 | | |
381 | 394 | | |
382 | 395 | | |
383 | | - | |
| 396 | + | |
384 | 397 | | |
385 | 398 | | |
386 | 399 | | |
| |||
0 commit comments