@@ -247,10 +247,11 @@ def isAvailable(cls):
247247 running the commandline tool.
248248 '''
249249 try :
250- subprocess .Popen (cls .bin_path (),
250+ p = subprocess .Popen (cls .bin_path (),
251251 shell = False ,
252252 stdout = subprocess .PIPE ,
253253 stderr = subprocess .PIPE )
254+ p .communicate ()
254255 return True
255256 except OSError :
256257 return False
@@ -326,6 +327,30 @@ def _frame_sink(self):
326327 # because it will no longer be referenced and will be gc-ed.
327328 return open (fname , 'wb' )
328329
330+ def grab_frame (self , ** savefig_kwargs ):
331+ '''
332+ Grab the image information from the figure and save as a movie frame.
333+ All keyword arguments in savefig_kwargs are passed on to the 'savefig'
334+ command that saves the figure.
335+ '''
336+ #Overloaded to explicitly close temp file.
337+ verbose .report ('MovieWriter.grab_frame: Grabbing frame.' ,
338+ level = 'debug' )
339+ try :
340+ # Tell the figure to save its data to the sink, using the
341+ # frame format and dpi.
342+ myframesink = self ._frame_sink ()
343+ self .fig .savefig (myframesink , format = self .frame_format ,
344+ dpi = self .dpi , ** savefig_kwargs )
345+ myframesink .close ()
346+
347+ except RuntimeError :
348+ out , err = self ._proc .communicate ()
349+ verbose .report ('MovieWriter -- Error '
350+ 'running proc:\n %s\n %s' % (out ,
351+ err ), level = 'helpful' )
352+ raise
353+
329354 def finish (self ):
330355 # Call run here now that all frame grabbing is done. All temp files
331356 # are available to be assembled.
0 commit comments