Skip to content

Doc draw event details #9505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/users/event_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ Here are the events that you can connect to, the class instances that
are sent back to you when the event occurs, and the event descriptions


======================= ======================================================================================
======================= =============================================================================================
Event name Class and description
======================= ======================================================================================
======================= =============================================================================================
'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed
'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw (but before screen update)
'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed
'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released
'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion
Expand All @@ -73,7 +73,7 @@ Event name Class and description
'figure_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves a figure
'axes_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new axes
'axes_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves an axes
======================= ======================================================================================
======================= =============================================================================================

.. _event-attributes:

Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,16 @@ class DrawEvent(Event):
"""
An event triggered by a draw operation on the canvas

In most backends callbacks subscribed to this callback will be
fired after the rendering is complete but before the screen is
updated. Any extra artists drawn to the canvas's renderer will
be reflected without an explicit call to ``blit``.

.. warning ::

Calling ``canvas.draw`` and ``canvas.blit`` in these callbacks may
not be safe with all backends and may cause infinite recursion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is nice to at least warn the user they have acquired a foot-cannon.....


In addition to the :class:`Event` attributes, the following event
attributes are defined:

Expand Down
10 changes: 7 additions & 3 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,22 @@ def draw_idle(self):
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)

def __draw_idle_agg(self, *args):
# if nothing to do, bail
if not self._agg_draw_pending:
return
# we have now tried this function at least once, do not run
# again until re-armed. Doing this here rather than after
# protects against recursive calls triggered through self.draw
self._agg_draw_pending = False
# if negative size, bail
if self.height() < 0 or self.width() < 0:
self._agg_draw_pending = False
return
try:
# actually do the drawing
self.draw()
except Exception:
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
traceback.print_exc()
finally:
self._agg_draw_pending = False

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