@@ -117,9 +117,10 @@ def draw_image(self, x, y, im, origin, bbox):
117117 X = fromstring (s , UInt8 )
118118 X .shape = rows , cols , 4
119119
120- pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
121- has_alpha = 1 , bits_per_sample = 8 ,
122- width = cols , height = rows )
120+ pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
121+ #has_alpha=1, bits_per_sample=8,
122+ has_alpha = True , bits_per_sample = 8 ,
123+ width = cols , height = rows )
123124 try :
124125 pa = pb .get_pixels_array ()
125126 except AttributeError :
@@ -134,9 +135,16 @@ def draw_image(self, x, y, im, origin, bbox):
134135
135136 if flipud : y = self .height - y - rows
136137
137- pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
138- int (x ), int (y ), cols , rows ,
139- gdk .RGB_DITHER_NONE , 0 , 0 )
138+ try : # requires GTK+ 2.2
139+ # can use None instead of gc.gdkGC, if don't need clipping
140+ self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
141+ int (x ), int (y ), cols , rows ,
142+ gdk .RGB_DITHER_NONE , 0 , 0 )
143+ except AttributeError :
144+ # is deprecated
145+ pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
146+ int (x ), int (y ), cols , rows ,
147+ gdk .RGB_DITHER_NONE , 0 , 0 )
140148
141149
142150 def draw_line (self , gc , x1 , y1 , x2 , y2 ):
@@ -146,7 +154,6 @@ def draw_line(self, gc, x1, y1, x2, y2):
146154
147155 def draw_lines (self , gc , x , y ):
148156 x = x .astype (nx .Int16 )
149- #y = self.height*ones(y.shape, nx.Int16) - y.astype(nx.Int16)
150157 y = self .height - y .astype (nx .Int16 )
151158 self .gdkDrawable .draw_lines (gc .gdkGC , zip (x ,y ))
152159
@@ -225,7 +232,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
225232 Xs .shape = imh , imw
226233
227234 pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
228- has_alpha = 1 , bits_per_sample = 8 , width = imw , height = imh )
235+ #has_alpha=1, bits_per_sample=8, width=imw, height=imh)
236+ has_alpha = True , bits_per_sample = 8 , width = imw , height = imh )
229237
230238 try :
231239 pa = pb .get_pixels_array ()
@@ -241,9 +249,15 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
241249 pa [:,:,2 ]= int (rgb [2 ]* 255 )
242250 pa [:,:,3 ]= Xs
243251
244- pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
245- int (x ), int (y ), imw , imh ,
246- gdk .RGB_DITHER_NONE , 0 , 0 )
252+ try : # requires GTK+ 2.2
253+ # can use None instead of gc.gdkGC, if don't need clipping
254+ self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
255+ int (x ), int (y ), cols , rows ,
256+ gdk .RGB_DITHER_NONE , 0 , 0 )
257+ except AttributeError :
258+ pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
259+ int (x ), int (y ), imw , imh ,
260+ gdk .RGB_DITHER_NONE , 0 , 0 )
247261
248262
249263 def _draw_rotated_text (self , gc , x , y , s , prop , angle ):
@@ -306,9 +320,7 @@ def _get_pango_layout(self, s, prop):
306320 key = self .dpi .get (), s , hash (prop )
307321 value = self .layoutd .get (key )
308322 if value != None :
309- #print 'layoutd cached value'
310323 return value
311- #print 'len(self.layoutd), s', len(self.layoutd), s
312324
313325 size = prop .get_size_in_points () * self .dpi .get () / PIXELS_PER_INCH
314326 size = round (size )
0 commit comments