Skip to content

Commit

Permalink
browse_slp.py can now save frames
Browse files Browse the repository at this point in the history
  • Loading branch information
fredreichbier committed Mar 17, 2013
1 parent d8d1704 commit acf2ebc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions browse_slp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import argparse
import shlex
import traceback
import cmd
import os
Expand Down Expand Up @@ -326,6 +327,43 @@ def do_play(self, name):
except:
traceback.print_exc()

def do_save(self, params):
"""
Save a specific frame of a specific SLP file to a file.
save RESOURCE FRAME_ID FILENAME
"""
try:
resource_filename, frame_id, filename = shlex.split(params)
frame_id = int(frame_id)
resource_id = _get_resource_id(resource_filename)
image = self.loader.get_frames(resource_id)[frame_id]
image.save(filename)
print 'Saved %r.' % filename
except:
traceback.print_exc()

def do_saveall(self, params):
"""
Save all frames of the SLP file to a file.
saveall RESOURCE TEMPLATE
where TEMPLATE is a string containing `%d`, which will be replaced with the frame index.
This is the output filename.
"""
try:
resource_filename, filename_template = shlex.split(params)
resource_id = _get_resource_id(resource_filename)
for idx, image in enumerate(self.loader.get_frames(resource_id)):
filename = filename_template % idx
image.save(filename)
print 'Saved %r.' % filename
except:
traceback.print_exc()
return

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='View SLP files.')
parser.add_argument('path', metavar='PATH', type=str,
Expand Down

0 comments on commit acf2ebc

Please sign in to comment.