_cli.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. rescriptoon
  3. Copyright (C) 2018-2019 Fabian Peter Hammerle <fabian@hammerle.me>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. """
  15. import argparse
  16. import logging
  17. from Xlib import X, XK
  18. import rescriptoon
  19. _DEFAULT_TOGGLE_KEYSYM_NAME = "grave"
  20. _VERBOSITY_LEVELS = [logging.WARNING, logging.INFO, logging.DEBUG]
  21. def main() -> None:
  22. argparser = argparse.ArgumentParser(
  23. description="Attach rescriptoon to running Toontown Rewritten engines.",
  24. )
  25. argparser.add_argument(
  26. "--toggle",
  27. "-t",
  28. metavar="KEYSYM_NAME",
  29. dest="toggle_keysym_name",
  30. default=_DEFAULT_TOGGLE_KEYSYM_NAME,
  31. help="key to turn extended keyboard controls on / off."
  32. + " any keysym name may be used"
  33. + " (see XStringToKeysym & X11/keysymdef.h, "
  34. + " default: %(default)s)",
  35. )
  36. argparser.add_argument(
  37. "--verbose",
  38. "-v",
  39. action="count",
  40. dest="verbosity",
  41. default=0,
  42. help="repeat to further increase verbosity",
  43. )
  44. args = argparser.parse_args()
  45. logging.basicConfig(
  46. format="%(asctime)s %(levelname)s: %(message)s",
  47. datefmt="%H:%I:%S",
  48. level=_VERBOSITY_LEVELS[min(args.verbosity, len(_VERBOSITY_LEVELS) - 1)],
  49. )
  50. toggle_keysym = XK.string_to_keysym(args.toggle_keysym_name)
  51. if toggle_keysym == X.NoSymbol:
  52. raise ValueError(
  53. "controls toggle: unknown keysym name '{}'".format(args.toggle_keysym_name)
  54. )
  55. rescriptoon.Overlay(toggle_keysym=toggle_keysym).run()