From e56fbea53d7025c4ed1348c40e515985d77a354e Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Tue, 14 Apr 2015 16:45:13 +0200 Subject: [PATCH 1/3] Trac #18176: Pass keywords from show through save to gif resp. ffmpeg --- src/sage/plot/animate.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index d502221cefd..a146d7fb981 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -555,6 +555,8 @@ def gif(self, delay=20, savefile=None, iterations=0, show_path=False, sage: td = tmp_dir() sage: a.gif() # not tested sage: a.gif(savefile=td + 'my_animation.gif', delay=35, iterations=3) # optional -- ImageMagick + sage: with open(td + 'my_animation.gif', 'rb') as f: print '\x21\xf9\x04\x08\x23\x00' in f.read() # optional -- ImageMagick + True sage: a.gif(savefile=td + 'my_animation.gif', show_path=True) # optional -- ImageMagick Animation saved to .../my_animation.gif. sage: a.gif(savefile=td + 'my_animation_2.gif', show_path=True, use_ffmpeg=True) # optional -- ffmpeg @@ -795,6 +797,8 @@ def ffmpeg(self, savefile=None, show_path=False, output_format=None, TESTS:: sage: a.ffmpeg(output_format='gif',delay=30,iterations=5) # optional -- ffmpeg + doctest:...: DeprecationWarning: use tmp_filename instead + See http://trac.sagemath.org/17234 for details. """ if not self._have_ffmpeg(): msg = """Error: ffmpeg does not appear to be installed. Saving an animation to @@ -924,7 +928,7 @@ def apng(self, savefile=None, show_path=False, delay=20, iterations=0): if show_path: print "Animation saved to file %s." % savefile - def save(self, filename=None, show_path=False, use_ffmpeg=False): + def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): """ Save this animation. @@ -964,6 +968,27 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False): sage: a.save(td + 'wave0.sobj') sage: a.save(td + 'wave1.sobj', show_path=True) Animation saved to file .../wave1.sobj. + + TESTS: + + Ensure that we can pass delay and iteration count to the saved + GIF image (see :trac:`18176`):: + + sage: a.save(td + 'wave.gif') # optional -- ImageMagick + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xf9\x04\x08\x14\x00' in f.read() # optional -- ImageMagick + True + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xff\x0bNETSCAPE2.0\x03\x01\x00\x00\x00' in f.read() # optional -- ImageMagick + True + sage: a.save(td + 'wave.gif', delay=35) # optional -- ImageMagick + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xf9\x04\x08\x14\x00' in f.read() # optional -- ImageMagick + False + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xf9\x04\x08\x23\x00' in f.read() # optional -- ImageMagick + True + sage: a.save(td + 'wave.gif', iterations=3) # optional -- ImageMagick + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xff\x0bNETSCAPE2.0\x03\x01\x00\x00\x00' in f.read() # optional -- ImageMagick + False + sage: with open(td + 'wave.gif', 'rb') as f: print '!\xff\x0bNETSCAPE2.0\x03\x01\x03\x00\x00' in f.read() # optional -- ImageMagick + True """ if filename is None: suffix = '.gif' @@ -974,16 +999,13 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False): if filename is None or suffix == '.gif': self.gif(savefile=filename, show_path=show_path, - use_ffmpeg=use_ffmpeg) - return + use_ffmpeg=use_ffmpeg, **kwds) elif suffix == '.sobj': SageObject.save(self, filename) if show_path: print "Animation saved to file %s." % filename - return else: - self.ffmpeg(savefile=filename, show_path=show_path) - return + self.ffmpeg(savefile=filename, show_path=show_path, **kwds) class APngAssembler(object): From 14dd2818961df94bafdc2e2d1f2b640d3a68d5ae Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Tue, 14 Apr 2015 16:50:50 +0200 Subject: [PATCH 2/3] Don't use file name argument to show method Since 7747261d04e4ff0105fb514a2109b2d014396e2a removed the file name argument to the show method of GraphicsArray (without deprecatuion procedure), we should not document it being called in this way. Instead we can save it to a file (which won't get displayed automatically) to demonstrate the core idea of specifying a custom file name here. --- src/sage/plot/animate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index a146d7fb981..8e3ca84706d 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -491,12 +491,12 @@ def graphics_array(self, ncols=3): Graphics Array of size 2 x 3 sage: g.show(figsize=[6,3]) # optional - Specify different arrangement of array and save with different file name:: + Specify different arrangement of array and save it with a given file name:: sage: g = a.graphics_array(ncols=2); print g Graphics Array of size 2 x 2 sage: f = tmp_filename(ext='.png') - sage: g.show(f) # optional + sage: g.save(f) # optional Frames can be specified as a generator too; it is internally converted to a list:: From 9a48ae00a4cf86aa5c3cbf2c092e641b9f0c6e59 Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Tue, 14 Apr 2015 18:00:30 +0200 Subject: [PATCH 3/3] Use raw mode for docstring This avoids troubles due to the escape characters contained in this docstring. --- src/sage/plot/animate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index 8e3ca84706d..1ed5ccd6069 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -929,7 +929,7 @@ def apng(self, savefile=None, show_path=False, delay=20, iterations=0): print "Animation saved to file %s." % savefile def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): - """ + r""" Save this animation. INPUT: