Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6938b00

Browse files
committed
backend_qt4agg: eliminate duplicate call to FigureCanvasAgg.draw()
The basic problem is that the most efficient way to eliminate the duplication appears to be to do the Agg drawing in the paintEvent, not in draw(); but then a draw() followed by copy_from_bbox may result in a copy being made before the Agg draw has occurred. The solution here is to do that drawing inside copy_from_bbox when necessary. Side note: it seems that by using the update() method, the qt4agg draw() is acting more like draw_idle() than like the draw() methods in the other interactive backends. svn path=/trunk/matplotlib/; revision=8922
1 parent a9b94ac commit 6938b00

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def paintEvent( self, e ):
110110
w = int(r) - int(l)
111111
h = int(t) - int(b)
112112
t = int(b) + h
113-
reg = self.copy_from_bbox(bbox)
113+
reg = FigureCanvasAgg.copy_from_bbox(self, bbox)
114114
stringBuffer = reg.to_string_argb()
115115
qImage = QtGui.QImage(stringBuffer, w, h, QtGui.QImage.Format_ARGB32)
116116
pixmap = QtGui.QPixmap.fromImage(qImage)
@@ -127,7 +127,6 @@ def draw( self ):
127127

128128
if DEBUG: print "FigureCanvasQtAgg.draw", self
129129
self.replot = True
130-
FigureCanvasAgg.draw(self)
131130
self.update()
132131

133132
def blit(self, bbox=None):
@@ -140,6 +139,16 @@ def blit(self, bbox=None):
140139
t = b + h
141140
self.repaint(l, self.renderer.height-t, w, h)
142141

142+
def copy_from_bbox(self, *args):
143+
"""
144+
If a draw() has been called but the update() has not
145+
occurred, draw into the agg canvas before copying.
146+
"""
147+
if self.replot:
148+
FigureCanvasAgg.draw(self)
149+
self.replot = False
150+
return FigureCanvasAgg.copy_from_bbox(self, *args)
151+
143152
def print_figure(self, *args, **kwargs):
144153
FigureCanvasAgg.print_figure(self, *args, **kwargs)
145154
self.draw()

0 commit comments

Comments
 (0)