aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py')
-rw-r--r--contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py b/contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py
new file mode 100644
index 0000000000..a872cee36a
--- /dev/null
+++ b/contrib/python/ipython/py3/IPython/lib/inputhookgtk4.py
@@ -0,0 +1,43 @@
+"""
+Enable Gtk4 to be used interactively by IPython.
+"""
+# -----------------------------------------------------------------------------
+# Copyright (c) 2021, the IPython Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+# -----------------------------------------------------------------------------
+
+# -----------------------------------------------------------------------------
+# Imports
+# -----------------------------------------------------------------------------
+
+import sys
+
+from gi.repository import GLib
+
+# -----------------------------------------------------------------------------
+# Code
+# -----------------------------------------------------------------------------
+
+
+class _InputHook:
+ def __init__(self, context):
+ self._quit = False
+ GLib.io_add_watch(sys.stdin, GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit)
+
+ def quit(self, *args, **kwargs):
+ self._quit = True
+ return False
+
+ def run(self):
+ context = GLib.MainContext.default()
+ while not self._quit:
+ context.iteration(True)
+
+
+def inputhook_gtk4():
+ hook = _InputHook()
+ hook.run()
+ return 0