1
1
from __future__ import division
2
2
3
- import os , math
3
+ import math , os , warnings
4
4
import sys
5
5
def fn_name (): return sys ._getframe (1 ).f_code .co_name
6
6
7
7
import matplotlib
8
- from matplotlib import verbose
9
- from matplotlib .numerix import asarray , fromstring , UInt8 , zeros , \
10
- where , transpose , nonzero , indices , ones , nx
11
8
12
9
import 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
15
12
13
+ from matplotlib ._pylab_helpers import Gcf
16
14
from matplotlib .backend_bases import RendererBase , GraphicsContextBase , \
17
15
FigureManagerBase , FigureCanvasBase
18
- from matplotlib ._pylab_helpers import Gcf
16
+ from matplotlib .cbook import is_string_like , enumerate
19
17
from matplotlib .figure import Figure
18
+ from matplotlib .font_manager import fontManager
20
19
from matplotlib .mathtext import math_parse_s_ft2font
21
20
22
21
pygtk_version_required = (1 ,99 ,16 )
@@ -29,7 +28,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name
29
28
raise SystemExit ('PyGTK version %d.%d.%d or greater is required to run the GTK Matplotlib backends'
30
29
% pygtk_version_required )
31
30
32
- import gtk , gobject , pango
31
+ #import gobject
32
+ import gtk , pango
33
33
from gtk import gdk
34
34
if gtk .pygtk_version < pygtk_version_required :
35
35
raise SystemExit ("PyGTK %d.%d.%d is installed\n "
@@ -78,7 +78,7 @@ class RendererGDK(RendererBase):
78
78
rotated = {} # a map from text prop tups to rotated text pixbufs
79
79
80
80
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
82
82
self .gtkDA = gtkDA
83
83
self .dpi = dpi
84
84
self ._cmap = gtkDA .get_colormap ()
@@ -118,20 +118,22 @@ def draw_image(self, x, y, im, origin, bbox):
118
118
X .shape = rows , cols , 4
119
119
120
120
pb = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB ,
121
- #has_alpha=1, bits_per_sample=8,
122
121
has_alpha = True , bits_per_sample = 8 ,
123
122
width = cols , height = rows )
124
123
try :
125
124
pa = pb .get_pixels_array ()
126
125
except AttributeError :
127
126
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
+
130
131
pa [:,:,:] = X
131
132
132
133
gc = self .new_gc ()
133
134
134
- if flipud : y = self .height - y - rows
135
+ if flipud :
136
+ y = self .height - y - rows
135
137
136
138
try : # requires GTK+ 2.2
137
139
# 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):
252
254
try : # requires GTK+ 2.2
253
255
# can use None instead of gc.gdkGC, if don't need clipping
254
256
self .gdkDrawable .draw_pixbuf (gc .gdkGC , pb , 0 , 0 ,
255
- int (x ), int (y ), cols , rows ,
257
+ int (x ), int (y ), imw , imh ,
256
258
gdk .RGB_DITHER_NONE , 0 , 0 )
257
259
except AttributeError :
258
260
pb .render_to_drawable (self .gdkDrawable , gc .gdkGC , 0 , 0 ,
@@ -346,7 +348,6 @@ def flipy(self):
346
348
return True
347
349
348
350
def get_canvas_width_height (self ):
349
- #return self.gtkDA.allocation.width, self.gtkDA.allocation.height
350
351
return self .width , self .height
351
352
352
353
def get_text_width_height (self , s , prop , ismath ):
@@ -474,15 +475,13 @@ def __init__(self, figure):
474
475
self ._renderer_init ()
475
476
476
477
def _renderer_init (self ):
477
- #self._renderer = RendererGDK (self, self.figure.dpi) # self is no longer a widget subclass
478
478
self ._renderer = RendererGDK (gtk .DrawingArea (), self .figure .dpi )
479
479
480
480
481
- def _render_to_pixmap (self , width , height ):
481
+ def _render_figure (self , width , height ):
482
482
"""Render the figure to a gdk.Pixmap, is used for
483
483
- rendering the pixmap to display (pylab.draw)
484
484
- rendering the pixmap to save to a file (pylab.savefig)
485
- Should not be overridden
486
485
"""
487
486
if DEBUG : print 'FigureCanvasGDK.%s' % fn_name ()
488
487
create_pixmap = False
@@ -497,7 +496,6 @@ def _render_to_pixmap(self, width, height):
497
496
498
497
if create_pixmap :
499
498
if DEBUG : print 'FigureCanvasGTK.%s new pixmap' % fn_name ()
500
- #self._pixmap = gtk.gdk.Pixmap (self.window, self._pixmap_width,
501
499
self ._pixmap = gtk .gdk .Pixmap (None , self ._pixmap_width ,
502
500
self ._pixmap_height , depth = 24 )
503
501
# gtk backend must use self.window
@@ -523,7 +521,7 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
523
521
if ext in ('jpg' , 'png' ): # native printing
524
522
width , height = self .figure .get_width_height ()
525
523
width , height = int (width ), int (height )
526
- self ._render_to_pixmap (width , height )
524
+ self ._render_figure (width , height )
527
525
528
526
# jpg colors don't match the display very well, png colors match better
529
527
pixbuf = gtk .gdk .Pixbuf (gtk .gdk .COLORSPACE_RGB , 0 , 8 ,
0 commit comments