You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.8 KiB

6 years ago
#! /usr/bin/env python3
8 years ago
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')
8 years ago
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)
8 years ago
if '--help' in opts:
printUsage()
sys.exit(0)
8 years ago
if '-o' in opts:
output = opts['-o']
elif '--output' in opts:
output = opts['--output']
else:
output = 'shell'
8 years ago
loop = '--no-loop' not in opts
8 years ago
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)
8 years ago
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)
8 years ago
if __name__ == "__main__":
main()
8 years ago