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

Skip to content

Commit e315e90

Browse files
committed
qt4agg: fix blit bug; closes #506
A simple Cursor test script was causing infinite recursion. The solution here involves using separate attributes for the replot flag (meaning an Agg draw is needed) and the blitbox. This clarifies the logic and removes the need to override the inherited copy_from_bbox method.
1 parent 7dda386 commit e315e90

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__( self, figure ):
5858
FigureCanvasAgg.__init__( self, figure )
5959
self.drawRect = False
6060
self.rect = []
61+
self.blitbox = None
6162
self.replot = True
6263
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
6364

@@ -77,11 +78,11 @@ def paintEvent( self, e ):
7778
if DEBUG: print 'FigureCanvasQtAgg.paintEvent: ', self, \
7879
self.get_width_height()
7980

80-
# only replot data when needed
81-
if type(self.replot) is bool: # might be a bbox for blitting
82-
if self.replot:
83-
FigureCanvasAgg.draw(self)
81+
if self.replot:
82+
FigureCanvasAgg.draw(self)
83+
self.replot = False
8484

85+
if self.blitbox is None:
8586
# matplotlib is in rgba byte order. QImage wants to put the bytes
8687
# into argb format and is in a 4 byte unsigned int. Little endian
8788
# system is LSB first and expects the bytes in reverse order
@@ -91,7 +92,7 @@ def paintEvent( self, e ):
9192
else:
9293
stringBuffer = self.renderer._renderer.tostring_argb()
9394

94-
qImage = QtGui.QImage(stringBuffer, self.renderer.width,
95+
qImage = QtGui.QImage(stringBuffer, self.renderer.width,
9596
self.renderer.height,
9697
QtGui.QImage.Format_ARGB32)
9798
p = QtGui.QPainter(self)
@@ -101,23 +102,21 @@ def paintEvent( self, e ):
101102
if self.drawRect:
102103
p.setPen( QtGui.QPen( QtCore.Qt.black, 1, QtCore.Qt.DotLine ) )
103104
p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
104-
105105
p.end()
106-
# we are blitting here
107106
else:
108-
bbox = self.replot
107+
bbox = self.blitbox
109108
l, b, r, t = bbox.extents
110109
w = int(r) - int(l)
111110
h = int(t) - int(b)
112111
t = int(b) + h
113-
reg = FigureCanvasAgg.copy_from_bbox(self, bbox)
112+
reg = self.copy_from_bbox(bbox)
114113
stringBuffer = reg.to_string_argb()
115114
qImage = QtGui.QImage(stringBuffer, w, h, QtGui.QImage.Format_ARGB32)
116115
pixmap = QtGui.QPixmap.fromImage(qImage)
117116
p = QtGui.QPainter( self )
118117
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap)
119118
p.end()
120-
self.replot = False
119+
self.blitbox = None
121120
self.drawRect = False
122121

123122
def draw( self ):
@@ -133,22 +132,11 @@ def blit(self, bbox=None):
133132
"""
134133
Blit the region in bbox
135134
"""
136-
137-
self.replot = bbox
135+
self.blitbox = bbox
138136
l, b, w, h = bbox.bounds
139137
t = b + h
140138
self.repaint(l, self.renderer.height-t, w, h)
141139

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-
152140
def print_figure(self, *args, **kwargs):
153141
FigureCanvasAgg.print_figure(self, *args, **kwargs)
154142
self.draw()

0 commit comments

Comments
 (0)