@@ -84,7 +84,7 @@ def paintEvent(self, e):
8484 print ('FigureCanvasQtAgg.paintEvent: ' , self ,
8585 self .get_width_height ())
8686
87- if self .blitbox is None :
87+ if len ( self .blitbox ) == 0 :
8888 # matplotlib is in rgba byte order. QImage wants to put the bytes
8989 # into argb format and is in a 4 byte unsigned int. Little endian
9090 # system is LSB first and expects the bytes in reverse order
@@ -123,31 +123,34 @@ def paintEvent(self, e):
123123 if refcnt != sys .getrefcount (stringBuffer ):
124124 _decref (stringBuffer )
125125 else :
126- bbox = self .blitbox
127- l , b , r , t = bbox .extents
128- w = int (r ) - int (l )
129- h = int (t ) - int (b )
130- t = int (b ) + h
131- reg = self .copy_from_bbox (bbox )
132- stringBuffer = reg .to_string_argb ()
133- qImage = QtGui .QImage (stringBuffer , w , h ,
134- QtGui .QImage .Format_ARGB32 )
135- # Adjust the stringBuffer reference count to work around a memory
136- # leak bug in QImage() under PySide on Python 3.x
137- if QT_API == 'PySide' and six .PY3 :
138- ctypes .c_long .from_address (id (stringBuffer )).value = 1
139-
140- pixmap = QtGui .QPixmap .fromImage (qImage )
141126 p = QtGui .QPainter (self )
142- p .drawPixmap (QtCore .QPoint (l , self .renderer .height - t ), pixmap )
127+
128+ while len (self .blitbox ):
129+ bbox = self .blitbox .pop ()
130+ l , b , r , t = bbox .extents
131+ w = int (r ) - int (l )
132+ h = int (t ) - int (b )
133+ t = int (b ) + h
134+ reg = self .copy_from_bbox (bbox )
135+ stringBuffer = reg .to_string_argb ()
136+ qImage = QtGui .QImage (stringBuffer , w , h ,
137+ QtGui .QImage .Format_ARGB32 )
138+ # Adjust the stringBuffer reference count to work
139+ # around a memory leak bug in QImage() under PySide on
140+ # Python 3.x
141+ if QT_API == 'PySide' and six .PY3 :
142+ ctypes .c_long .from_address (id (stringBuffer )).value = 1
143+
144+ pixmap = QtGui .QPixmap .fromImage (qImage )
145+ p .drawPixmap (QtCore .QPoint (l , self .renderer .height - t ), pixmap )
143146
144147 # draw the zoom rectangle to the QPainter
145148 if self ._drawRect is not None :
146149 p .setPen (QtGui .QPen (QtCore .Qt .black , 1 , QtCore .Qt .DotLine ))
147150 x , y , w , h = self ._drawRect
148151 p .drawRect (x , y , w , h )
152+
149153 p .end ()
150- self .blitbox = None
151154
152155 def draw (self ):
153156 """
@@ -190,7 +193,7 @@ def blit(self, bbox=None):
190193 if bbox is None and self .figure :
191194 bbox = self .figure .bbox
192195
193- self .blitbox = bbox
196+ self .blitbox . append ( bbox )
194197 l , b , w , h = bbox .bounds
195198 t = b + h
196199 self .repaint (l , self .renderer .height - t , w , h )
@@ -218,7 +221,7 @@ def __init__(self, figure):
218221 print ('FigureCanvasQtAgg: ' , figure )
219222 super (FigureCanvasQTAgg , self ).__init__ (figure = figure )
220223 self ._drawRect = None
221- self .blitbox = None
224+ self .blitbox = []
222225 self .setAttribute (QtCore .Qt .WA_OpaquePaintEvent )
223226
224227
0 commit comments