8000 SC · matplotlib/matplotlib@73d791d · GitHub
[go: up one dir, main page]

Skip to content

Commit 73d791d

Browse files
author
Steve Chaplin
committed
SC
svn path=/trunk/matplotlib/; revision=1351
1 parent f20cff5 commit 73d791d

File tree

3 files changed

+74
-42
lines changed

3 files changed

+74
-42
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff 10000 line numberDiff line change
@@ -106,18 +106,20 @@ def _set_width_height(self, width, height):
106106
self.height = height
107107
self.matrix_flipy = cairo.Matrix (d=-1, ty=self.height)
108108
# use matrix_flipy for ALL rendering?
109-
# - problem with text? - will need to switch matrix_flipy off, or do a font transform?
109+
# - problem with text? - will need to switch matrix_flipy off, or do a
110+
# font transform?
110111

111112
def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
112113
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
113114
# draws circular arcs where width=height
114115
# FIXME
115-
# to get a proper arc of width/height you can use translate() and scale()
116-
# see draw_arc() manual page
116+
# to get a proper arc of width/height you can use translate() and
117+
# scale(), see draw_arc() manual page
117118
radius = (height + width) / 4
118119
ctx = gc.ctx
119120
ctx.new_path()
120-
ctx.arc (x, self.height - y, radius, angle1 * pi/180.0, angle2 * pi/180.0)
121+
ctx.arc (x, self.height - y, radius,
122+
angle1 * pi/180.0, angle2 * pi/180.0)
121123

122124
if rgbFace:
123125
ctx.save()
@@ -131,7 +133,8 @@ def draw_image(self, x, y, im, origin, bbox):
131133
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
132134

133135
if numerix.which[0] == "numarray":
134-
warnings.warn("draw_image() currently works for numpy, but not numarray")
136+
warnings.warn("draw_image() currently works for numpy, but not "
137+
"numarray")
135138
return
136139

137140
if not HAVE_CAIRO_NUMPY:
@@ -163,7 +166,8 @@ def draw_image(self, x, y, im, origin, bbox):
163166
surface = cairo.numpy.surface_create_for_array (X)
164167

165168
# Alternative
166-
#surface = cairo.surface_create_for_image(buf, cairo.FORMAT_ARGB32, cols, rows) #, stride)
169+
# surface = cairo.ImageSurface(buf, cairo.FORMAT_ARGB32, cols, rows)
170+
# stride)
167171
# error: TypeError: Cannot use string as modifiable buffer
168172

169173
ctx.translate (x,y)
@@ -297,7 +301,8 @@ def draw_rectangle(self, gc, rgbFace, x, y, width, height):
297301

298302

299303
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
300-
# Note: x,y are device/display coords, not user-coords, unlike other draw_* methods
304+
# Note: x,y are device/display coords, not user-coords, unlike other
305+
# draw_* methods
301306
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
302307

303308
if ismath:
@@ -327,7 +332,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
327332
# mathtext using the gtk/gdk method
328333

329334
if numerix.which[0] == "numarray":
330-
warnings.warn("_draw_mathtext() currently works for numpy, but not numarray")
335+
warnings.warn(" A92E _draw_mathtext() currently works for numpy, but "
336+
"not numarray")
331337
return
332338

333339
if not HAVE_CAIRO_NUMPY:
@@ -378,7 +384,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
378384
def flipy(self):
379385
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
380386
return True
381-
#return False # tried - all draw objects ok except text (and images?) which comes out mirrored!
387+
#return False # tried - all draw objects ok except text (and images?)
388+
# which comes out mirrored!
382389

383390

384391
def get_canvas_width_height(self):
@@ -559,7 +566,8 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
559566
warnings.warn("%s: %s" % (exc.filename, exc.strerror))
560567
else:
561568
if ext == 'png': _save_png (figure, fileObject)
562-
else: _save_ps_pdf (figure, fileObject, ext, orientation)
569+
else: _save_ps_pdf (figure, fileObject, ext,
570+
orientation)
563571
fileObject.close()
564572

565573
elif ext in ('eps', 'svg'): # backend_svg/ps

lib/matplotlib/backends/backend_gdk.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name
3737
backend_version = "%d.%d.%d" % gtk.pygtk_version
3838
del pygtk_version_required
3939

40-
# do after gtk else get "pygtk.require() must be called before importing gtk" errors
40+
# do after gtk else get "pygtk.require() must be called before importing gtk"
41+
# errors
4142
if numerix.which[0] == "numarray":
4243
from matplotlib._na_backend_gdk import pixbuf_get_pixels_array
4344
else:
@@ -47,7 +48,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
4748
DEBUG = False
4849

4950
# Image formats that this backend supports - for FileChooser and print_figure()
50-
IMAGE_FORMAT = ['eps', 'jpg', 'png', 'ps', 'svg'] + ['bmp'] # , 'raw', 'rgb']
51+
IMAGE_FORMAT = ['eps', 'jpg', 'png', 'ps', 'svg'] + ['bmp'] # , 'raw', 'rgb']
5152
IMAGE_FORMAT.sort()
5253
IMAGE_FORMAT_DEFAULT = 'png'
5354

@@ -79,7 +80,8 @@ class RendererGDK(RendererBase):
7980
rotated = {} # a map from text prop tups to rotated text pixbufs
8081

8182
def __init__(self, gtkDA, dpi):
82-
# gtkDA is used in '<widget>.create_pango_layout(s)' (and cmap line below) only
83+
# gtkDA is used in '<widget>.create_pango_layout(s)' (and cmap line
84+
# below) only
8385
self.gtkDA = gtkDA
8486
self.dpi = dpi
8587
self._cmap = gtkDA.get_colormap()
@@ -257,7 +259,8 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle):
257259
Draw the text rotated 90 degrees, other angles are not supported
258260
"""
259261
# this function (and its called functions) is a bottleneck
260-
# Pango 1.6 supports rotated text, but pygtk 2.4.0 does not yet have wrapper functions
262+
# Pango 1.6 supports rotated text, but pygtk 2.4.0 does not yet have
263+
# wrapper functions
261264
# GTK+ 2.6 pixbufs support rotation
262265

263266
gdrawable = self.gdkDrawable
@@ -279,7 +282,6 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle):
279282

280283
imageBack = gdrawable.get_image(x, y, w, h)
281284
imageVert = gdrawable.get_image(x, y, h, w)
282-
#imageFlip = gtk.gdk.Image(type=gdk.IMAGE_NORMAL,
283285
imageFlip = gtk.gdk.Image(type=gdk.IMAGE_FASTEST,
284286
visual=gdrawable.get_visual(),
285287
width=w, height=h)
@@ -313,7 +315,8 @@ def _get_pango_layout(self, s, prop):
313315
Ref: pango/fonts.c/pango_font_description_set_size() manual page
314316
"""
315317
# problem? - cache gets bigger and bigger, is never cleared out
316-
# two (not one) layouts are created for every text item s (then they are cached) - why?
318+
# two (not one) layouts are created for every text item s (then they
319+
# are cached) - why?
317320

318321
key = self.dpi.get(), s, hash(prop)
319322
value = self.layoutd.get(key)
@@ -458,7 +461,8 @@ def new_figure_manager(num, *args, **kwargs):
458461
canvas = FigureCanvasGDK(thisFig)
459462
manager = FigureManagerBase(canvas, num)
460463
# equals:
461-
#manager = FigureManagerBase (FigureCanvasGDK (Figure(*args, **kwargs), num)
464+
#manager = FigureManagerBase (FigureCanvasGDK (Figure(*args, **kwargs),
465+
# num)
462466
return manager
463467

464468

@@ -519,10 +523,10 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
519523
width, height = int(width), int(height)
520524
self._render_figure(width, height)
521525

522-
# jpg colors don't match the display very well, png colors match better
526+
# jpg colors don't match the display very well, png colors match
527+
# better
523528
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8,
524529
width, height)
525-
#pixbuf.get_from_drawable(self._pixmap, self._pixmap.get_colormap(),
526530
pixbuf.get_from_drawable(self._pixmap, self._renderer._cmap,
527531
0, 0, 0, 0, width, height)
528532

lib/matplotlib/backends/backend_gtk.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def fn_name(): return sys._getframe(1).f_code.co_name
4747
PIXELS_PER_INCH = 96
4848

4949
# Image formats that this backend supports - for FileChooser and print_figure()
50-
IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'ps', 'svg']
51-
#IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'pdf', 'ps', 'svg'] # pdf not ready yet
50+
IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'ps', 'svg']
51+
# pdf not ready yet
52+
#IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'pdf', 'ps', 'svg']
5253
IMAGE_FORMAT.sort()
5354
IMAGE_FORMAT_DEFAULT = 'png'
5455

@@ -64,7 +65,9 @@ def fn_name(): return sys._getframe(1).f_code.co_name
6465
}
6566

6667
# ref gtk+/gtk/gtkwidget.h
67-
def GTK_WIDGET_DRAWABLE(w): flags = w.flags(); return flags & gtk.VISIBLE !=0 and flags & gtk.MAPPED != 0
68+
def GTK_WIDGET_DRAWABLE(w):
69+
flags = w.flags();
70+
return flags & gtk.VISIBLE !=0 and flags & gtk.MAPPED != 0
6871

6972

7073
def draw_if_interactive():
@@ -118,7 +121,7 @@ def __init__(self, figure):
118121
FigureCanvasBase.__init__(self, figure)
119122
gtk.DrawingArea.__init__(self)
120123

121-
self._idleID = 0 # used in gtkAgg
124+
self._idleID = 0
122125
self._draw_pixmap = True
123126
self._pixmap_width = -1
124127
self._pixmap_height = -1
@@ -242,11 +245,13 @@ def _render_figure(self, width, height):
242245
create_pixmap = False
243246
if width > self._pixmap_width:
244247
# increase the pixmap in 10%+ (rather than 1 pixel) steps
245-
self._pixmap_width = max (int (self._pixmap_width * 1.1), width)
248+
self._pixmap_width = max (int (self._pixmap_width * 1.1),
249+
width)
246250
create_pixmap = True
247251

248252
if height > self._pixmap_height:
249-
self._pixmap_height = max (int (self._pixmap_height * 1.1), height)
253+
self._pixmap_height = max (int (self._pixmap_height * 1.1),
254+
height)
250255
create_pixmap = True
251256

252257
if create_pixmap:
@@ -298,7 +303,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
298303
origWIn, origHIn = self.figure.get_size_inches()
299304

300305
if self.flags() & gtk.REALIZED == 0:
301-
# for self.window(for pixmap) and has a side effect of altering figure width,height (via configure-event?)
306+
# for self.window(for pixmap) and has a side effect of altering
307+
# figure width,height (via configure-event?)
302308
gtk.DrawingArea.realize(self)
303309

304310
self.figure.dpi.set(dpi)
@@ -317,7 +323,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
317323

318324
DBL_BUFFER = dbl_buffer_save
319325

320-
# jpg colors don't match the display very well, png colors match better
326+
# jpg colors don't match the display very well, png colors match
327+
# better
321328
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8,
322329
width, height)
323330
pixbuf.get_from_drawable(self._pixmap, self._pixmap.get_colormap(),
@@ -338,7 +345,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
338345

339346
try:
340347
fc = self.switch_backends(FigureCanvas)
341-
fc.print_figure(filename, dpi, facecolor, edgecolor, orientation)
348+
fc.print_figure(filename, dpi, facecolor, edgecolor,
349+
orientation)
342350
except IOError, exc:
343351
error_msg_gtk("Save figure failure:\n%s: %s" %
344352
(exc.filename, exc.strerror), parent=self)
@@ -354,7 +362,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
354362
parent=self)
355363
else:
356364
fc = self.switch_backends(FigureCanvas)
357-
fc.print_figure(filename, dpi, facecolor, edgecolor, orientation)
365+
fc.print_figure(filename, dpi, facecolor, edgecolor,
366+
orientation)
358367

359368
elif ext in ('pdf',):
360369
try:
@@ -365,7 +374,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
365374
parent=self)
366375
else:
367376
fc = self.switch_backends(FigureCanvas)
368-
fc.print_figure(filename, dpi, facecolor, edgecolor, orientation)
377+
fc.print_figure(filename, dpi, facecolor, edgecolor,
378+
orientation)
369379

370380
else:
371381
error_msg_gtk('Format "%s" is not supported.\nSupported formats are %s.' %
@@ -501,7 +511,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
501511

502512
ax = event.inaxes
503513
l,b,w,h = [int(val) for val in ax.bbox.get_bounds()]
504-
b = int(height)-(b+h) # b = y = int(height)-(b+h) # y not used
514+
b = int(height)-(b+h)
505515
axrect = l,b,w,h
506516
self._imageBack = axrect, drawable.get_image(*axrect)
507517
drawable.draw_rectangle(gc, False, *rect)
@@ -573,7 +583,9 @@ def _init_toolbar2_4(self):
573583

574584
toolitem = gtk.SeparatorToolItem()
575585
self.insert(toolitem, -1)
576-
toolitem.set_draw(False) # set_draw() not making separator invisible, bug #143692 fixed Jun 06 2004, will be in GTK+ 2.6
586+
# set_draw() not making separator invisible,
587+
# bug #143692 fixed Jun 06 2004, will be in GTK+ 2.6
588+
toolitem.set_draw(False)
577589
toolitem.set_expand(True)
578590

579591
toolitem = gtk.ToolItem()
@@ -608,21 +620,25 @@ class NavigationToolbar(gtk.Toolbar):
608620
gtk.STOCK_GO_BACK, 'panx', -1, True),
609621
('Right', 'Pan right with click or wheel mouse (bidirectional)',
610622
gtk.STOCK_GO_FORWARD, 'panx', 1, True),
611-
('Zoom In X', 'Zoom In X (shrink the x axis limits) with click or wheel'
623+
('Zoom In X',
624+
'Zoom In X (shrink the x axis limits) with click or wheel'
612625
' mouse (bidirectional)',
613626
gtk.STOCK_ZOOM_IN, 'zoomx', 1, True),
614-
('Zoom Out X', 'Zoom Out X (expand the x axis limits) with click or wheel'
627+
('Zoom Out X',
628+
'Zoom Out X (expand the x axis limits) with click or wheel'
615629
' mouse (bidirectional)',
616630
gtk.STOCK_ZOOM_OUT, 'zoomx', -1, True),
617631
(None, None, None, None, None, None,),
618632
('Up', 'Pan up with click or wheel mouse (bidirectional)',
619633
gtk.STOCK_GO_UP, 'pany', 1, True),
620634
('Down', 'Pan down with click or wheel mouse (bidirectional)',
621635
gtk.STOCK_GO_DOWN, 'pany', -1, True),
622-
('Zoom In Y', 'Zoom in Y (shrink the y axis limits) with click or wheel'
636+
('Zoom In Y',
637+
'Zoom in Y (shrink the y axis limits) with click or wheel'
623638
' mouse (bidirectional)',
624639
gtk.STOCK_ZOOM_IN, 'zoomy', 1, True),
625-
('Zoom Out Y', 'Zoom Out Y (expand the y axis limits) with click or wheel'
640+
('Zoom Out Y',
641+
'Zoom Out Y (expand the y axis limits) with click or wheel'
626642
' mouse (bidirectional)',
627643
gtk.STOCK_ZOOM_OUT, 'zoomy', -1, True),
628644
(None, None, None, None, None, None,),
@@ -639,7 +655,8 @@ def __init__(self, canvas, window):
639655
gtk.Toolbar.__init__(self)
640656

641657
self.canvas = canvas
642-
self.win = window # Note: gtk.Toolbar already has a 'window' attribute
658+
# Note: gtk.Toolbar already has a 'window' attribute
659+
self.win = window
643660

644661
self.set_style(gtk.TOOLBAR_ICONS)
645662

@@ -671,7 +688,8 @@ def _create_toolitems_2_4(self):
671688
text)
672689
self.insert(tbutton, -1)
673690
if callback_arg:
674-
tbutton.connect('clicked', getattr(self, callback), callback_arg)
691+
tbutton.connect('clicked', getattr(self, callback),
692+
callback_arg)
675693
else:
676694
tbutton.connect('clicked', getattr(self, callback))
677695
if scroll:
@@ -681,9 +699,10 @@ def _create_toolitems_2_4(self):
681699
# Axes toolitem, is empty at start, update() adds a menu if >=2 axes
682700
self.axes_toolitem = gtk.ToolItem()
683701
self.insert(self.axes_toolitem, 0)
684-
self.axes_toolitem.set_tooltip(self.tooltips,
685-
tip_text='Select axes that controls affect',
686-
tip_private = 'Private')
702+
self.axes_toolitem.set_tooltip (
703+
self.tooltips,
704+
tip_text='Select axes that controls affect',
705+
tip_private = 'Private')
687706

688707
align = gtk.Alignment (xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0)
689708
self.axes_toolitem.add(align)
@@ -709,7 +728,8 @@ def position_menu (menu):
709728
return x, y, True
710729

711730
def button_clicked (button, data=None):
712-
self.axismenu.popup (None, None, position_menu, 0, gtk.get_current_event_time())
731+
self.axismenu.popup (None, None, position_menu, 0,
732+
gtk.get_current_event_time())
713733

714734
self.menubutton.connect ("clicked", button_clicked)
715735

0 commit comments

Comments
 (0)
0