Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51f94c3

Browse files
author
Steve Chaplin
committed
SC 04/11/2004
svn path=/trunk/matplotlib/; revision=657
1 parent 53055e2 commit 51f94c3

5 files changed

Lines changed: 33 additions & 23 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
New entries should be added at the top
22

33
==============================================================
4+
2004-11-04 backend_agg.py: added IMAGE_FORMAT to list the formats that the
5+
backend can save to.
6+
backend_gtkagg.py: added support for saving JPG files by using the
7+
GTK backend - SC
8+
49
2004-10-31 backend_cairo.py: now produces png and ps files (although the figure
510
sizing needs some work). pycairo did not wrap all the necessary
611
functions, so I wrapped them myself, they are included in the

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
backend_version = 'v2.2'
9090
_fontd = {} # a map from fname to font instances
9191

92+
IMAGE_FORMAT = ['eps', 'bmp', 'png', 'ps', 'raw', 'rgb', 'svg']
93+
IMAGE_FORMAT_DEFAULT = 'png'
94+
9295
class RendererAgg(RendererBase):
9396
"""
9497
The renderer handles all the drawing primitives using a graphics

lib/matplotlib/backends/backend_cairo.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,9 @@ def set_clip_rectangle(self, rectangle):
380380
"""
381381
Set the clip rectangle with sequence (left, bottom, width, height)
382382
"""
383-
# Cairo clipping is currently extremely slow, so I disabled it
383+
# Cairo clipping is currently extremely slow
384384
# cairo/BUGS lists it as a known bug
385385
self._cliprect = rectangle
386-
return
387386

388387
x,y,w,h = rectangle
389388
ctx = self.ctx
@@ -508,7 +507,6 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
508507
figure.set_edgecolor(edgecolor)
509508

510509
ext = ext.lower()
511-
print 'filename:', filename
512510
if ext in ('png', 'ps'):
513511
try:
514512
fileObject = file(filename,'wb')
@@ -577,7 +575,7 @@ def _save_ps (figure, fileObject, orientation):
577575
renderer = RendererCairo (ctx.target_surface, ctx.matrix, width, height, figure.dpi)
578576
figure.draw(renderer)
579577

580-
show_fig_border = True # for testing figure orientation and scaling
578+
show_fig_border = False # for testing figure orientation and scaling
581579
if show_fig_border:
582580
ctx.new_path()
583581
ctx.rectangle(0, 0, width, height)

lib/matplotlib/backends/backend_gtk.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,6 @@ def set_joinstyle(self, js):
548548
self.gdkGC.join_style = self._joind[self._joinstyle]
549549

550550

551-
def raise_msg_to_str(msg):
552-
"""msg is a return arg from a raise. Join with new lines"""
553-
if not is_string_like(msg):
554-
msg = '\n'.join(map(str, msg))
555-
return msg
556-
557-
558551
def error_msg_gtk(msg, parent=None):
559552
dialog = gtk.MessageDialog(
560553
parent = parent,
@@ -847,11 +840,16 @@ def gdk_pixmap_save (pixmap, filename, ext, width, height):
847840
# pixbuf.save() recognises 'jpeg' not 'jpg'
848841
if ext == 'jpg': ext = 'jpeg'
849842
try: pixbuf.save(filename, ext)
850-
except gobject.GError, msg:
851-
msg = raise_msg_to_str(msg)
843+
except gobject.GError, exc:
852844
error_msg('Could not save figure to %s\n\n%s' % (
853-
filename, msg))
845+
filename, exc))
854846

847+
#def raise_msg_to_str(msg):
848+
# """msg is a return arg from a raise. Join with new lines"""
849+
# if not is_string_like(msg):
850+
# msg = '\n'.join(map(str, msg))
851+
# return msg
852+
855853

856854
class FigureManagerGTK(FigureManagerBase):
857855
"""
@@ -879,9 +877,8 @@ def __init__(self, canvas, num):
879877
# must be inited after the window, drawingArea and figure
880878
# attrs are set
881879
if matplotlib.rcParams['toolbar']=='classic':
882-
self.toolbar = NavigationToolbar( canvas, self.window )
880+
self.toolbar = NavigationToolbar (canvas, self.window)
883881
elif matplotlib.rcParams['toolbar']=='toolbar2':
884-
#self.toolbar = NavigationToolbar2GTK( canvas )
885882
self.toolbar = NavigationToolbar2GTK (canvas, self.window)
886883
else:
887884
self.toolbar = None
@@ -1139,7 +1136,7 @@ class NavigationToolbar(gtk.Toolbar):
11391136
gtk.STOCK_SAVE, 'save_figure', None, False),
11401137
)
11411138

1142-
def __init__(self, canvas, window=None):
1139+
def __init__(self, canvas, window):
11431140
"""
11441141
figManager is the FigureManagerGTK instance that contains the
11451142
toolbar, with attributes figure, window and drawingArea
@@ -1148,7 +1145,7 @@ def __init__(self, canvas, window=None):
11481145
gtk.Toolbar.__init__(self)
11491146

11501147
self.canvas = canvas
1151-
self.win = window
1148+
self.win = window # Note: gtk.Toolbar already has a 'window' attribute
11521149

11531150
self.set_style(gtk.TOOLBAR_ICONS)
11541151

@@ -1424,6 +1421,7 @@ def __init__ (self,
14241421

14251422
self.IMAGE_FORMAT = matplotlib.backends.backend_mod.IMAGE_FORMAT
14261423
self.IMAGE_FORMAT_DEFAULT = matplotlib.backends.backend_mod.IMAGE_FORMAT_DEFAULT
1424+
self.IMAGE_FORMAT.sort()
14271425

14281426
# create an extra widget to list supported image formats
14291427
self.set_current_folder (self.path)

lib/matplotlib/backends/backend_gtkagg.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from matplotlib.cbook import enumerate, True, False
99
from matplotlib.figure import Figure
1010

11-
from backend_agg import FigureCanvasAgg
11+
from backend_agg import FigureCanvasAgg, IMAGE_FORMAT, IMAGE_FORMAT_DEFAULT
1212
from backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
1313
show, draw_if_interactive,\
1414
error_msg, NavigationToolbar, PIXELS_PER_INCH, backend_version
@@ -19,8 +19,7 @@
1919
DEBUG = 0
2020

2121
# Image formats that this backend supports - for FileChooser and print_figure()
22-
IMAGE_FORMAT = ['eps', 'bmp', 'png', 'ps', 'raw', 'rgb', 'svg']
23-
IMAGE_FORMAT_DEFAULT = 'png'
22+
IMAGE_FORMAT += ['jpg']
2423

2524

2625
def new_figure_manager(num, *args, **kwargs):
@@ -59,8 +58,15 @@ def print_figure(self, filename, dpi=150,
5958
if DEBUG: print 'FigureCanvasGTKAgg.print_figure'
6059
# delete the renderer to prevent improper blitting after print
6160

62-
agg = self.switch_backends(FigureCanvasAgg)
63-
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
61+
root, ext = os.path.splitext(filename)
62+
ext = ext.lower()[1:]
63+
if ext == 'jpg':
64+
FigureCanvasGTK.print_figure(self, filename, dpi, facecolor,
65+
edgecolor, orientation)
66+
67+
else:
68+
agg = self.switch_backends(FigureCanvasAgg)
69+
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
6470

6571

6672

0 commit comments

Comments
 (0)