#! /usr/bin/env python3 import sys import getopt import blup.animation import blup.output def printUsage(errMsg=None): if errMsg is not None: print('error: %s\n' % (errMsg)) print('usage: %s [OPTIONS] FILENAME' % (sys.argv[0])) print('supported options:') print(' -o OUTPUT where to output the frames (default: shell)') print(' --no-loop play animation only once') print(' --output OUTPUT\n') print(' -h print this text') print(' --help') def main(): try: (opts, args) = getopt.gnu_getopt(sys.argv, 'ho:', ['help', 'output=', 'no-loop']) opts = dict(opts) except getopt.GetoptError as e: printUsage(e.msg) sys.exit(1) if '--help' in opts: printUsage() sys.exit(0) if '-o' in opts: output = opts['-o'] elif '--output' in opts: output = opts['--output'] else: output = 'shell' loop = '--no-loop' not in opts try: out = blup.output.getOutput(output) except blup.output.IllegalOutputSpecificationError: print('illegal output specification') print('available outputs:') print(blup.output.getOutputDescriptions()) sys.exit(1) except Exception as e: print('could not initialize output: %s' % (str(e))) sys.exit(1) if len(args) != 2: printUsage() sys.exit(1) try: anim = blup.animation.load(args[1]) except blup.animation.AnimationFileError: print('could not load animation') sys.exit(1) player = blup.animation.AnimationPlayer() try: while True: player.play(anim, out) if not loop: break except KeyboardInterrupt: sys.exit(0) if __name__ == "__main__": main()