Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Qt5: Add flag that informs paintEvent if the agg buffer needs to upda…
…ted, init FigureCanvasQTAggBase
  • Loading branch information
pwuertz committed Aug 20, 2015
commit 05ded3b69ee8b37e29b2c5b587f35ab011b8bd25
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_qt4agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def new_figure_manager_given_figure(num, figure):
return FigureManagerQT(canvas, num)


class FigureCanvasQTAgg(FigureCanvasQTAggBase,
FigureCanvasQT, FigureCanvasAgg):
class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase,
FigureCanvasAgg):
"""
The canvas the figure renders into. Calls the draw and print fig
methods, creates the renderers, etc...
Expand All @@ -69,6 +69,7 @@ def __init__(self, figure):
if DEBUG:
print('FigureCanvasQtAgg: ', figure)
FigureCanvasQT.__init__(self, figure)
FigureCanvasQTAggBase.__init__(self, figure)
FigureCanvasAgg.__init__(self, figure)
self._drawRect = None
self.blitbox = None
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ def stop_event_loop(self):

stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__

def draw_idle(self):
self.update()


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably stay, do we want to fallback to the base implementation of draw_idle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its not really clear to me what's the idea of the split between qt5 and qt5agg. Draw is defined in qt5agg, draw_idle is defined in qt5. It seems reasonable to have both at the same spot where the whole draw mechanism is implemented. Its not gone, it just moved from qt5 to qt5agg.

class MainWindow(QtWidgets.QMainWindow):
closing = QtCore.Signal()
Expand Down
25 changes: 18 additions & 7 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ class FigureCanvasQTAggBase(object):

Public attribute

figure - A Figure instance
"""
figure - A Figure instance
"""

def __init__(self, figure):
super(FigureCanvasQTAggBase, self).__init__(figure=figure)
self._agg_redraw_flag = True

def drawRectangle(self, rect):
self._drawRect = rect
Expand All @@ -71,7 +75,9 @@ def paintEvent(self, e):
In Qt, all drawing should be done inside of here when a widget is
shown onscreen.
"""
FigureCanvasAgg.draw(self)
if self._agg_redraw_flag:
self._agg_redraw_flag = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please flip the order on these lines so it is only cleared after the Agg draw has succeeded with out exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would have, but I'm still confused about these draw_idle callbacks from within the draw call. If there is a reason for those you cannot clear the flag after draw since it might have been re-set during draw on purpose.

FigureCanvasAgg.draw(self)

# FigureCanvasQT.paintEvent(self, e)
if DEBUG:
Expand Down Expand Up @@ -147,6 +153,11 @@ def draw(self):
# causes problems with code that uses the result of the
# draw() to update plot elements.
FigureCanvasAgg.draw(self)
self._agg_redraw_flag = False
self.update()

def draw_idle(self):
self._agg_redraw_flag = True
self.update()

def blit(self, bbox=None):
Expand All @@ -161,15 +172,16 @@ def blit(self, bbox=None):
self.blitbox = bbox
l, b, w, h = bbox.bounds
t = b + h
self._agg_redraw_flag = False # don't repaint the agg buffer in blit()
self.repaint(l, self.renderer.height-t, w, h)

def print_figure(self, *args, **kwargs):
FigureCanvasAgg.print_figure(self, *args, **kwargs)
self.draw()


class FigureCanvasQTAgg(FigureCanvasQTAggBase,
FigureCanvasQT, FigureCanvasAgg):
class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase,
FigureCanvasAgg):
"""
The canvas the figure renders into. Calls the draw and print fig
methods, creates the renderers, etc.
Expand All @@ -184,8 +196,7 @@ class FigureCanvasQTAgg(FigureCanvasQTAggBase,
def __init__(self, figure):
if DEBUG:
print('FigureCanvasQtAgg: ', figure)
FigureCanvasQT.__init__(self, figure)
FigureCanvasAgg.__init__(self, figure)
super(FigureCanvasQTAgg, self).__init__(figure=figure)
self._drawRect = None
self.blitbox = None
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
Expand Down