Skip to content

Only use asynchronous redraw methods when handling GUI events in Qt5Agg (fix #4604) #4612

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 2 commits into from
Jul 22, 2015
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
16 changes: 0 additions & 16 deletions lib/matplotlib/backends/backend_qt4agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,6 @@ def __init__(self, figure):
self._drawRect = None
self.blitbox = None
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
# it has been reported that Qt is semi-broken in a windows
# environment. If `self.draw()` uses `update` to trigger a
# system-level window repaint (as is explicitly advised in the
# Qt documentation) the figure responds very slowly to mouse
# input. The work around is to directly use `repaint`
# (against the advice of the Qt documentation). The
# difference between `update` and repaint is that `update`
# schedules a `repaint` for the next time the system is idle,
# where as `repaint` repaints the window immediately. The
# risk is if `self.draw` gets called with in another `repaint`
# method there will be an infinite recursion. Thus, we only
# expose windows users to this risk.
if sys.platform.startswith('win'):
self._priv_update = self.repaint
else:
self._priv_update = self.update


FigureCanvas = FigureCanvasQTAgg
Expand Down
17 changes: 3 additions & 14 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ def resizeEvent(self, event):
hinch = h / dpival
self.figure.set_size_inches(winch, hinch)
FigureCanvasBase.resize_event(self)
self.draw()
self.update()
self.draw_idle()
QtWidgets.QWidget.resizeEvent(self, event)

def sizeHint(self):
Expand Down Expand Up @@ -417,17 +416,7 @@ def stop_event_loop(self):
stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__

def draw_idle(self):
'update drawing area only if idle'
d = self._idle
self._idle = False

def idle_draw(*args):
try:
self.draw()
finally:
self._idle = True
if d:
QtCore.QTimer.singleShot(0, idle_draw)
self.update()


class MainWindow(QtWidgets.QMainWindow):
Expand Down Expand Up @@ -666,7 +655,7 @@ def zoom(self, *args):
self._update_buttons_checked()

def dynamic_update(self):
self.canvas.draw()
self.canvas.draw_idle()

def set_message(self, s):
self.message.emit(s)
Expand Down
21 changes: 3 additions & 18 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ class FigureCanvasQTAggBase(object):

def drawRectangle(self, rect):
self._drawRect = rect
self.repaint()
self.draw_idle()

def paintEvent(self, e):
"""
Copy the image from the Agg canvas to the qt.drawable.
In Qt, all drawing should be done inside of here when a widget is
shown onscreen.
"""
FigureCanvasAgg.draw(self)

# FigureCanvasQT.paintEvent(self, e)
if DEBUG:
Expand Down Expand Up @@ -146,7 +147,7 @@ def draw(self):
# causes problems with code that uses the result of the
# draw() to update plot elements.
FigureCanvasAgg.draw(self)
self._priv_update()
self.update()

def blit(self, bbox=None):
"""
Expand Down Expand Up @@ -183,22 +184,6 @@ def __init__(self, figure):
self._drawRect = None
self.blitbox = None
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
# it has been reported that Qt is semi-broken in a windows
# environment. If `self.draw()` uses `update` to trigger a
# system-level window repaint (as is explicitly advised in the
# Qt documentation) the figure responds very slowly to mouse
# input. The work around is to directly use `repaint`
# (against the advice of the Qt documentation). The
# difference between `update` and repaint is that `update`
# schedules a `repaint` for the next time the system is idle,
# where as `repaint` repaints the window immediately. The
# risk is if `self.draw` gets called with in another `repaint`
# method there will be an infinite recursion. Thus, we only
# expose windows users to this risk.
if sys.platform.startswith('win'):
self._priv_update = self.repaint
else:
self._priv_update = self.update


FigureCanvas = FigureCanvasQTAgg
Expand Down