gtk4.py 557 B

123456789101112131415161718192021222324252627
  1. """
  2. prompt_toolkit input hook for GTK 4.
  3. """
  4. from gi.repository import GLib
  5. class _InputHook:
  6. def __init__(self, context):
  7. self._quit = False
  8. GLib.io_add_watch(
  9. context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit
  10. )
  11. def quit(self, *args, **kwargs):
  12. self._quit = True
  13. return False
  14. def run(self):
  15. context = GLib.MainContext.default()
  16. while not self._quit:
  17. context.iteration(True)
  18. def inputhook(context):
  19. hook = _InputHook(context)
  20. hook.run()