@@ -80,15 +80,15 @@ def blit(self, bbox=None):
80
80
x = int (l )
81
81
y = int (self .bitmap .GetHeight () - t )
82
82
83
- srcBmp = _convert_agg_to_wx_bitmap (self .get_renderer (), bbox )
83
+ srcBmp = _convert_agg_to_wx_bitmap (self .get_renderer (), None )
84
84
srcDC = wx .MemoryDC ()
85
85
srcDC .SelectObject (srcBmp )
86
86
87
87
destDC = wx .MemoryDC ()
88
88
destDC .SelectObject (self .bitmap )
89
89
90
90
destDC .BeginDrawing ()
91
- destDC .Blit (x , y , int (w ), int (h ), srcDC , 0 , 0 )
91
+ destDC .Blit (x , y , int (w ), int (h ), srcDC , x , y )
92
92
destDC .EndDrawing ()
93
93
94
94
destDC .SelectObject (wx .NullBitmap )
@@ -145,7 +145,7 @@ def new_figure_manager(num, *args, **kwargs):
145
145
146
146
147
147
#
148
- # agg/wxPython image conversion functions
148
+ # agg/wxPython image conversion functions (wxPython <= 2.6)
149
149
#
150
150
151
151
def _py_convert_agg_to_wx_image (agg , bbox ):
@@ -185,7 +185,7 @@ def _py_convert_agg_to_wx_bitmap(agg, bbox):
185
185
186
186
def _clipped_image_as_bitmap (image , bbox ):
187
187
"""
188
- Convert the region of a wx.Image described by bbox to a wx.Bitmap.
188
+ Convert the region of a wx.Image bounded by bbox to a wx.Bitmap.
189
189
"""
190
190
l , b , width , height = bbox .get_bounds ()
191
191
r = l + width
@@ -211,19 +211,94 @@ def _clipped_image_as_bitmap(image, bbox):
211
211
return destBmp
212
212
213
213
214
+ #
215
+ # agg/wxPython image conversion functions (wxPython >= 2.8)
216
+ #
217
+
218
+ def _py_WX28_convert_agg_to_wx_image (agg , bbox ):
219
+ """
220
+ Convert the region of the agg buffer bounded by bbox to a wx.Image. If
221
+ bbox is None, the entire buffer is converted.
222
+
223
+ Note: agg must be a backend_agg.RendererAgg instance.
224
+ """
225
+ if bbox is None :
226
+ # agg => rgb -> image
227
+ image = wx .EmptyImage (int (agg .width ), int (agg .height ))
228
+ image .SetData (agg .tostring_rgb ())
229
+ return image
230
+ else :
231
+ # agg => rgba buffer -> bitmap => clipped bitmap => image
232
+ return wx .ImageFromBitmap (_WX28_clipped_agg_as_bitmap (agg , bbox ))
233
+
234
+
235
+ def _py_WX28_convert_agg_to_wx_bitmap (agg , bbox ):
236
+ """
237
+ Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If
238
+ bbox is None, the entire buffer is converted.
239
+
240
+ Note: agg must be a backend_agg.RendererAgg instance.
241
+ """
242
+ if bbox is None :
243
+ # agg => rgba buffer -> bitmap
244
+ return wx .BitmapFromBufferRGBA (int (agg .width ), int (agg .height ),
245
+ agg .buffer_rgba (0 , 0 ))
246
+ else :
247
+ # agg => rgba buffer -> bitmap => clipped bitmap
248
+ return _WX28_clipped_agg_as_bitmap (agg , bbox )
249
+
250
+
251
+ def _WX28_clipped_agg_as_bitmap (agg , bbox ):
252
+ """
253
+ Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.
254
+
255
+ Note: agg must be a backend_agg.RendererAgg instance.
256
+ """
257
+ l , b , width , height = bbox .get_bounds ()
258
+ r = l + width
259
+ t = b + height
260
+
261
+ srcBmp = wx .BitmapFromBufferRGBA (int (agg .width ), int (agg .height ),
262
+ agg .buffer_rgba (0 , 0 ))
263
+ srcDC = wx .MemoryDC ()
264
+ srcDC .SelectObject (srcBmp )
265
+
266
+ destBmp = wx .EmptyBitmap (int (width ), int (height ))
267
+ destDC = wx .MemoryDC ()
268
+ destDC .SelectObject (destBmp )
269
+
270
+ destDC .BeginDrawing ()
271
+ x = int (l )
272
+ y = int (int (agg .height ) - t )
273
+ destDC .Blit (0 , 0 , int (width ), int (height ), srcDC , x , y )
274
+ destDC .EndDrawing ()
275
+
276
+ srcDC .SelectObject (wx .NullBitmap )
277
+ destDC .SelectObject (wx .NullBitmap )
278
+
279
+ return destBmp
280
+
281
+
214
282
def _use_accelerator (state ):
215
283
"""
216
- Enable or disable the WXAgg accelerator, if it is present.
284
+ Enable or disable the WXAgg accelerator, if it is present and is also
285
+ compatible with whatever version of wxPython is in use.
217
286
"""
218
287
global _convert_agg_to_wx_image
219
288
global _convert_agg_to_wx_bitmap
220
289
221
- if state and _wxagg is not None :
222
- _convert_agg_to_wx_image = _wxagg .convert_agg_to_wx_image
223
- _convert_agg_to_wx_bitmap = _wxagg .convert_agg_to_wx_bitmap
290
+ if getattr (wx , '__version__' , '0.0' )[0 :3 ] < '2.8' :
291
+ # wxPython < 2.8, so use the C++ accelerator or the Python routines
292
+ if state and _wxagg is not None :
293
+ _convert_agg_to_wx_image = _wxagg .convert_agg_to_wx_image
294
+ _convert_agg_to_wx_bitmap = _wxagg .convert_agg_to_wx_bitmap
295
+ else :
296
+ _convert_agg_to_wx_image = _py_convert_agg_to_wx_image
297
+ _convert_agg_to_wx_bitmap = _py_convert_agg_to_wx_bitmap
224
298
else :
225
- _convert_agg_to_wx_image = _py_convert_agg_to_wx_image
226
- _convert_agg_to_wx_bitmap = _py_convert_agg_to_wx_bitmap
299
+ # wxPython >= 2.8, so use the accelerated Python routines
300
+ _convert_agg_to_wx_image = _py_WX28_convert_agg_to_wx_image
301
+ _convert_agg_to_wx_bitmap = _py_WX28_convert_agg_to_wx_bitmap
227
302
228
303
229
304
# try to load the WXAgg accelerator
@@ -234,4 +309,3 @@ def _use_accelerator(state):
234
309
235
310
# if it's present, use it
236
311
_use_accelerator (True )
237
-
0 commit comments