Browse Source

added --no-loop option

feature/balanceutils
Fr3deric 7 years ago
parent
commit
062c2efdb9
  1. 101
      utils/blmplay.py

101
utils/blmplay.py

@ -7,62 +7,67 @@ import blup.animation
import blup.output import blup.output
def printUsage(errMsg=None): def printUsage(errMsg=None):
if errMsg is not None: if errMsg is not None:
print('error: %s\n' % (errMsg)) print('error: %s\n' % (errMsg))
print('usage: %s [OPTIONS] FILENAME' % (sys.argv[0])) print('usage: %s [OPTIONS] FILENAME' % (sys.argv[0]))
print('supported options:') print('supported options:')
print(' -o OUTPUT where to output the frames (default: shell)') print(' -o OUTPUT where to output the frames (default: shell)')
print(' --output OUTPUT\n') print(' --no-loop play animation only once')
print(' -h print this text') print(' --output OUTPUT\n')
print(' --help') print(' -h print this text')
print(' --help')
def main(): def main():
try: try:
(opts, args) = getopt.gnu_getopt(sys.argv, 'ho:', ['help', 'output=']) (opts, args) = getopt.gnu_getopt(sys.argv, 'ho:', ['help', 'output=', 'no-loop'])
opts = dict(opts) opts = dict(opts)
except getopt.GetoptError as e: except getopt.GetoptError as e:
printUsage(e.msg) printUsage(e.msg)
sys.exit(1) sys.exit(1)
if '--help' in opts: if '--help' in opts:
printUsage() printUsage()
sys.exit(0) sys.exit(0)
if '-o' in opts: if '-o' in opts:
output = opts['-o'] output = opts['-o']
elif '--output' in opts: elif '--output' in opts:
output = opts['--output'] output = opts['--output']
else: else:
output = 'shell' output = 'shell'
try: loop = '--no-loop' not in opts
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: try:
printUsage() out = blup.output.getOutput(output)
sys.exit(1) 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)
try: if len(args) != 2:
anim = blup.animation.load(args[1]) printUsage()
except blup.animation.AnimationFileError: sys.exit(1)
print('could not load animation')
sys.exit(1)
player = blup.animation.AnimationPlayer() try:
try: anim = blup.animation.load(args[1])
while True: except blup.animation.AnimationFileError:
player.play(anim, out) print('could not load animation')
except KeyboardInterrupt: sys.exit(1)
sys.exit(0)
player = blup.animation.AnimationPlayer()
try:
while True:
player.play(anim, out)
if not loop:
break
except KeyboardInterrupt:
sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save