11from __future__ import division
22
3- import os , math
3+ import math , os , warnings
44import sys
55def fn_name (): return sys ._getframe (1 ).f_code .co_name
66
77import matplotlib
8- from matplotlib import verbose
9- from matplotlib .numerix import asarray , fromstring , UInt8 , zeros , \
10- where , transpose , nonzero , indices , ones , nx
118
129import matplotlib .numerix as numerix
13- from matplotlib .cbook import is_string_like , enumerate
14- from matplotlib . font_manager import fontManager
10+ from matplotlib .numerix import asarray , fromstring , UInt8 , zeros , \
11+ where , transpose , nonzero , indices , ones , nx
1512
13+ from matplotlib ._pylab_helpers import Gcf
1614from matplotlib .backend_bases import RendererBase , GraphicsContextBase , \
1715 FigureManagerBase , FigureCanvasBase
18- from matplotlib ._pylab_helpers import Gcf
16+ from matplotlib .cbook import is_string_like , enumerate
1917from matplotlib .figure import Figure
18+ from matplotlib .font_manager import fontManager
2019from matplotlib .mathtext import math_parse_s_ft2font
2120
2221pygtk_version_required = (1 ,99 ,16 )
@@ -29,7 +28,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name
2928 raise SystemExit ('PyGTK version %d.%d.%d or greater is required to run the GTK Matplotlib backends'
3029 % pygtk_version_required )
3130
32- import gtk , gobject , pango
31+ #import gobject
32+ import gtk , pango
3333from gtk import gdk
3434if gtk .pygtk_version < pygtk_version_required :
3535 raise SystemExit ("PyGTK %d.%d.%d is installed\n "
@@ -78,7 +78,7 @@ class RendererGDK(RendererBase):
7878 rotated = {} # a map from text prop tups to rotated text pixbufs
7979
8080 def __init__ (self , gtkDA , dpi ):
81- # gtkDA is used in '<widget>.create_pango_layout(s)' only
81+ # gtkDA is used in '<widget>.create_pango_layout(s)' (and cmap line below) only
8282 self .gtkDA = gtkDA
8383 self .dpi = dpi
8484 self ._cmap = gtkDA .get_colormap ()
@@ -118,20 +118,22 @@ def draw_image(self, x, y, im, origin, bbox):
118118 X .shape = rows , cols , 4
119119
120120 pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
121- #has_alpha=1, bits_per_sample=8,
122121 has_alpha = True , bits_per_sample = 8 ,
123122 width = cols , height = rows )
124123 try :
125124 pa = pb .get_pixels_array ()
126125 except AttributeError :
127126 pa = pb .pixel_array
128- except RuntimeError , exc : # pygtk was not compiled with Numeric Python support
129- raise
127+ except RuntimeError : # pygtk was not compiled with Numeric Python support
128+ warnings .warn ('draw_image not supported: %s' % exc )
129+ return
130+
130131 pa [:,:,:] = X
131132
132133 gc = self .new_gc ()
133134
134- if flipud : y = self .height - y - rows
135+ if flipud :
136+ y = self .height - y - rows
135137
136138 try : # requires GTK+ 2.2
137139 # can use None instead of gc.gdkGC, if don't need clipping
@@ -252,7 +254,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
252254 try : # requires GTK+ 2.2
253255 # can use None instead of gc.gdkGC, if don't need clipping
254256 self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
255- int (x ), int (y ), cols , rows ,
257+ int (x ), int (y ), imw , imh ,
256258 gdk .RGB_DITHER_NONE , 0 , 0 )
257259 except AttributeError :
258260 pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
@@ -346,7 +348,6 @@ def flipy(self):
346348 return True
347349
348350 def get_canvas_width_height (self ):
349- #return self.gtkDA.allocation.width, self.gtkDA.allocation.height
350351 return self .width , self .height
351352
352353 def get_text_width_height (self , s , prop , ismath ):
@@ -474,15 +475,13 @@ def __init__(self, figure):
474475 self ._renderer_init ()
475476
476477 def _renderer_init (self ):
477- #self._renderer = RendererGDK (self, self.figure.dpi) # self is no longer a widget subclass
478478 self ._renderer = RendererGDK (gtk .DrawingArea (), self .figure .dpi )
479479
480480
481- def _render_to_pixmap (self , width , height ):
481+ def _render_figure (self , width , height ):
482482 """Render the figure to a gdk.Pixmap, is used for
483483 - rendering the pixmap to display (pylab.draw)
484484 - rendering the pixmap to save to a file (pylab.savefig)
485- Should not be overridden
486485 """
487486 if DEBUG : print 'FigureCanvasGDK.%s' % fn_name ()
488487 create_pixmap = False
@@ -497,7 +496,6 @@ def _render_to_pixmap(self, width, height):
497496
498497 if create_pixmap :
499498 if DEBUG : print 'FigureCanvasGTK.%s new pixmap' % fn_name ()
500- #self._pixmap = gtk.gdk.Pixmap (self.window, self._pixmap_width,
501499 self ._pixmap = gtk .gdk .Pixmap (None , self ._pixmap_width ,
502500 self ._pixmap_height , depth = 24 )
503501 # gtk backend must use self.window
@@ -523,7 +521,7 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
523521 if ext in ('jpg' , 'png' ): # native printing
524522 width , height = self .figure .get_width_height ()
525523 width , height = int (width ), int (height )
526- self ._render_to_pixmap (width , height )
524+ self ._render_figure (width , height )
527525
528526 # jpg colors don't match the display very well, png colors match better
529527 pixbuf = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB , 0 , 8 ,
0 commit comments