Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e2180d7

Browse filesBrowse files
authored
Merge pull request #9505 from tacaswell/doc_draw_event_details
Doc draw event details
2 parents 473409e + 9a99efb commit e2180d7
Copy full SHA for e2180d7

File tree

Expand file treeCollapse file tree

3 files changed

+21
-7
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-7
lines changed

‎doc/users/event_handling.rst

Copy file name to clipboardExpand all lines: doc/users/event_handling.rst
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ Here are the events that you can connect to, the class instances that
5757
are sent back to you when the event occurs, and the event descriptions
5858

5959

60-
======================= ======================================================================================
60+
======================= =============================================================================================
6161
Event name Class and description
62-
======================= ======================================================================================
62+
======================= =============================================================================================
6363
'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed
6464
'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released
65-
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw
65+
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw (but before screen update)
6666
'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed
6767
'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released
6868
'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion
@@ -73,7 +73,7 @@ Event name Class and description
7373
'figure_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves a figure
7474
'axes_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new axes
7575
'axes_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves an axes
76-
======================= ======================================================================================
76+
======================= =============================================================================================
7777

7878
.. _event-attributes:
7979

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,16 @@ class DrawEvent(Event):
14251425
"""
14261426
An event triggered by a draw operation on the canvas
14271427
1428+
In most backends callbacks subscribed to this callback will be
1429+
fired after the rendering is complete but before the screen is
1430+
updated. Any extra artists drawn to the canvas's renderer will
1431+
be reflected without an explicit call to ``blit``.
1432+
1433+
.. warning ::
1434+
1435+
Calling ``canvas.draw`` and ``canvas.blit`` in these callbacks may
1436+
not be safe with all backends and may cause infinite recursion.
1437+
14281438
In addition to the :class:`Event` attributes, the following event
14291439
attributes are defined:
14301440

‎lib/matplotlib/backends/backend_qt5agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5agg.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ def draw_idle(self):
140140
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)
141141

142142
def __draw_idle_agg(self, *args):
143+
# if nothing to do, bail
143144
if not self._agg_draw_pending:
144145
return
146+
# we have now tried this function at least once, do not run
147+
# again until re-armed. Doing this here rather than after
148+
# protects against recursive calls triggered through self.draw
149+
self._agg_draw_pending = False
150+
# if negative size, bail
145151
if self.height() < 0 or self.width() < 0:
146-
self._agg_draw_pending = False
147152
return
148153
try:
154+
# actually do the drawing
149155
self.draw()
150156
except Exception:
151157
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
152158
traceback.print_exc()
153-
finally:
154-
self._agg_draw_pending = False
155159

156160
def blit(self, bbox=None):
157161
"""Blit the region in bbox.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.