port-rename-callback.py 989 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import jack
  5. import time
  6. import argparse
  7. def port_renamed(client, port, old_name, new_name, arg):
  8. assert(arg == 1234)
  9. print("renamed port %s\n\tfrom '%s'\n\tto '%s'\n" % (repr(port), old_name, new_name))
  10. def run():
  11. client = jack.Client('port rename callback example');
  12. client.set_port_renamed_callback(port_renamed, 1234)
  13. client.activate();
  14. print('client name: ' + client.get_name())
  15. while True:
  16. try:
  17. time.sleep(1);
  18. except KeyboardInterrupt:
  19. break
  20. def _init_argparser():
  21. argparser = argparse.ArgumentParser(description = None)
  22. return argparser
  23. def main(argv):
  24. argparser = _init_argparser()
  25. try:
  26. import argcomplete
  27. argcomplete.autocomplete(argparser)
  28. except ImportError:
  29. pass
  30. args = argparser.parse_args(argv)
  31. run(**vars(args))
  32. return 0
  33. if __name__ == '__main__':
  34. sys.exit(main(sys.argv[1:]))