@@ -37,6 +37,12 @@ def fn_name(): return sys._getframe(1).f_code.co_name
3737backend_version = "%d.%d.%d" % gtk .pygtk_version
3838del pygtk_version_required
3939
40+ # do after gtk else get "pygtk.require() must be called before importing gtk" errors
41+ if numerix .which [0 ] == "numarray" :
42+ from matplotlib ._na_backend_gdk import pixbuf_get_pixels_array
43+ else :
44+ from matplotlib ._nc_backend_gdk import pixbuf_get_pixels_array
45+
4046
4147DEBUG = False
4248
@@ -107,23 +113,17 @@ def draw_image(self, x, y, im, origin, bbox):
107113 # set clip rect?
108114
109115 flipud = origin == 'lower'
110- rows , cols , s = im .as_str (flipud )
116+ rows , cols , image_str = im .as_str (flipud )
111117
112- X = fromstring (s , UInt8 )
113- X .shape = rows , cols , 4
118+ image_array = fromstring (image_str , UInt8 )
119+ image_array .shape = rows , cols , 4
114120
115- pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
116- has_alpha = True , bits_per_sample = 8 ,
117- width = cols , height = rows )
118- try :
119- pa = pb .get_pixels_array () # new in 2.2
120- except AttributeError :
121- pa = pb .pixel_array # deprecated in 2.2
122- except RuntimeError , exc : # pygtk was not compiled with Numeric Python support
123- warnings .warn ('draw_image not supported: %s' % exc )
124- return
121+ pixbuf = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
122+ has_alpha = True , bits_per_sample = 8 ,
123+ width = cols , height = rows )
125124
126- pa [:,:,:] = X
125+ array = pixbuf_get_pixels_array (pixbuf )
126+ array [:,:,:] = image_array
127127
128128 gc = self .new_gc ()
129129
@@ -132,12 +132,12 @@ def draw_image(self, x, y, im, origin, bbox):
132132
133133 try : # new in 2.2
134134 # can use None instead of gc.gdkGC, if don't need clipping
135- self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
135+ self .gdkDrawable .draw_pixbuf (gc .gdkGC , pixbuf , 0 , 0 ,
136136 int (x ), int (y ), cols , rows ,
137137 gdk .RGB_DITHER_NONE , 0 , 0 )
138138 except AttributeError :
139139 # deprecated in 2.2
140- pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
140+ pixbuf .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
141141 int (x ), int (y ), cols , rows ,
142142 gdk .RGB_DITHER_NONE , 0 , 0 )
143143
@@ -211,7 +211,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
211211 x -= width
212212 y -= height
213213
214- imw , imh , s = fonts [0 ].image_as_str ()
214+ imw , imh , image_str = fonts [0 ].image_as_str ()
215215 N = imw * imh
216216
217217 # a numpixels by num fonts array
@@ -220,40 +220,34 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
220220 for i , font in enumerate (fonts ):
221221 if angle == 90 :
222222 font .horiz_image_to_vert_image () # <-- Rotate
223- imw , imh , s = font .image_as_str ()
224- Xall [:,i ] = fromstring (s , UInt8 )
223+ imw , imh , image_str = font .image_as_str ()
224+ Xall [:,i ] = fromstring (image_str , UInt8 )
225225
226226 # get the max alpha at each pixel
227227 Xs = numerix .mlab .max (Xall ,1 )
228228
229229 # convert it to it's proper shape
230230 Xs .shape = imh , imw
231231
232- pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB , has_alpha = True ,
233- bits_per_sample = 8 , width = imw , height = imh )
232+ pixbuf = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB , has_alpha = True ,
233+ bits_per_sample = 8 , width = imw , height = imh )
234234
235- try :
236- pa = pb .get_pixels_array () # new in 2.2
237- except AttributeError :
238- pa = pb .pixel_array # deprecated in 2.2
239- except RuntimeError , exc : # 'pygtk was not compiled with Numeric Python support'
240- warnings .warn ('mathtext not supported: %s' % exc )
241- return
235+ array = pixbuf_get_pixels_array (pixbuf )
242236
243237 rgb = gc .get_rgb ()
244- pa [:,:,0 ]= int (rgb [0 ]* 255 )
245- pa [:,:,1 ]= int (rgb [1 ]* 255 )
246- pa [:,:,2 ]= int (rgb [2 ]* 255 )
247- pa [:,:,3 ]= Xs
238+ array [:,:,0 ]= int (rgb [0 ]* 255 )
239+ array [:,:,1 ]= int (rgb [1 ]* 255 )
240+ array [:,:,2 ]= int (rgb [2 ]* 255 )
241+ array [:,:,3 ]= Xs
248242
249243 try : # new in 2.2
250244 # can use None instead of gc.gdkGC, if don't need clipping
251- self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
245+ self .gdkDrawable .draw_pixbuf (gc .gdkGC , pixbuf , 0 , 0 ,
252246 int (x ), int (y ), imw , imh ,
253247 gdk .RGB_DITHER_NONE , 0 , 0 )
254248 except AttributeError :
255249 # deprecated in 2.2
256- pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
250+ pixbuf .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
257251 int (x ), int (y ), imw , imh ,
258252 gdk .RGB_DITHER_NONE , 0 , 0 )
259253
0 commit comments