##// END OF EJS Templates
Add input hooks for GTK4.
Elliott Sales de Andrade -
Show More
@@ -0,0 +1,42 b''
1 """
2 Enable Gtk4 to be used interactively by IPython.
3 """
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2021, the IPython Development Team.
6 #
7 # Distributed under the terms of the Modified BSD License.
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
11
12 #-----------------------------------------------------------------------------
13 # Imports
14 #-----------------------------------------------------------------------------
15
16 import sys
17
18 from gi.repository import GLib
19
20 #-----------------------------------------------------------------------------
21 # Code
22 #-----------------------------------------------------------------------------
23
24 class _InputHook:
25 def __init__(self, context):
26 self._quit = False
27 GLib.io_add_watch(sys.stdin, GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit)
28
29 def quit(self, *args, **kwargs):
30 self._quit = True
31 return False
32
33 def run(self):
34 context = GLib.MainContext.default()
35 while not self._quit:
36 context.iteration(True)
37
38
39 def inputhook_gtk4():
40 hook = _InputHook()
41 hook.run()
42 return 0
@@ -0,0 +1,25 b''
1 """
2 prompt_toolkit input hook for GTK 4.
3 """
4
5 from gi.repository import GLib
6
7
8 class _InputHook:
9 def __init__(self, context):
10 self._quit = False
11 GLib.io_add_watch(context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit)
12
13 def quit(self, *args, **kwargs):
14 self._quit = True
15 return False
16
17 def run(self):
18 context = GLib.MainContext.default()
19 while not self._quit:
20 context.iteration(True)
21
22
23 def inputhook(context):
24 hook = _InputHook(context)
25 hook.run()
@@ -0,0 +1,36 b''
1 #!/usr/bin/env python
2 """Simple Gtk example to manually test event loop integration.
3
4 This is meant to run tests manually in ipython as:
5
6 In [1]: %gui gtk4
7
8 In [2]: %run gui-gtk4.py
9 """
10
11 import gi
12 gi.require_version('Gtk', '4.0')
13 from gi.repository import Gtk, GLib # noqa
14
15
16 def hello_world(wigdet, data=None):
17 print("Hello World")
18
19
20 def close_request_cb(widget, data=None):
21 global running
22 running = False
23
24
25 running = True
26 window = Gtk.Window()
27 window.connect("close-request", close_request_cb)
28 button = Gtk.Button(label="Hello World")
29 button.connect("clicked", hello_world, None)
30
31 window.set_child(button)
32 window.show()
33
34 context = GLib.MainContext.default()
35 while running:
36 context.iteration(True)
@@ -493,6 +493,7 b' Currently the magic system has the following functions:""",'
493 493 %gui qt5 # enable PyQt5 event loop integration
494 494 %gui gtk # enable PyGTK event loop integration
495 495 %gui gtk3 # enable Gtk3 event loop integration
496 %gui gtk4 # enable Gtk4 event loop integration
496 497 %gui tk # enable Tk event loop integration
497 498 %gui osx # enable Cocoa event loop integration
498 499 # (requires %matplotlib 1.1)
@@ -88,7 +88,7 b' class PylabMagics(Magics):'
88 88 You can list the available backends using the -l/--list option::
89 89
90 90 In [4]: %matplotlib --list
91 Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',
91 Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'gtk4', 'notebook', 'wx', 'qt', 'nbagg',
92 92 'gtk', 'tk', 'inline']
93 93 """
94 94 args = magic_arguments.parse_argstring(self.matplotlib, line)
@@ -16,6 +16,7 b' backends = {'
16 16 "tk": "TkAgg",
17 17 "gtk": "GTKAgg",
18 18 "gtk3": "GTK3Agg",
19 "gtk4": "GTK4Agg",
19 20 "wx": "WXAgg",
20 21 "qt4": "Qt4Agg",
21 22 "qt5": "Qt5Agg",
@@ -44,6 +45,7 b" backend2gui['Qt4Agg'] = 'qt'"
44 45 # map to the same GUI support
45 46 backend2gui['GTK'] = backend2gui['GTKCairo'] = 'gtk'
46 47 backend2gui['GTK3Cairo'] = 'gtk3'
48 backend2gui['GTK4Cairo'] = 'gtk4'
47 49 backend2gui['WX'] = 'wx'
48 50 backend2gui['CocoaAgg'] = 'osx'
49 51 # And some backends that don't need GUI integration
@@ -14,6 +14,7 b' backends = ['
14 14 "gtk",
15 15 "gtk2",
16 16 "gtk3",
17 "gtk4",
17 18 "tk",
18 19 "wx",
19 20 "pyglet",
@@ -7,9 +7,9 b' loop, so you can use both a GUI and an interactive prompt together. IPython'
7 7 supports a number of common GUI toolkits, but from IPython 3.0, it is possible
8 8 to integrate other event loops without modifying IPython itself.
9 9
10 Supported event loops include ``qt4``, ``qt5``, ``gtk2``, ``gtk3``, ``wx``,
11 ``osx`` and ``tk``. Make sure the event loop you specify matches the GUI
12 toolkit used by your own code.
10 Supported event loops include ``qt4``, ``qt5``, ``gtk2``, ``gtk3``, ``gtk4``,
11 ``wx``, ``osx`` and ``tk``. Make sure the event loop you specify matches the
12 GUI toolkit used by your own code.
13 13
14 14 To make IPython GUI event loop integration occur automatically at every
15 15 startup, set the ``c.InteractiveShellApp.gui`` configuration key in your
@@ -44,7 +44,7 b' the command-line by passing the full class name and a corresponding value; type'
44 44 <...snip...>
45 45 --matplotlib=<CaselessStrEnum> (InteractiveShellApp.matplotlib)
46 46 Default: None
47 Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
47 Choices: ['auto', 'gtk', 'gtk3', 'gtk4', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
48 48 Configure matplotlib for interactive use with the default matplotlib
49 49 backend.
50 50 <...snip...>
@@ -902,7 +902,8 b' For users, enabling GUI event loop integration is simple. You simple use the'
902 902 %gui [GUINAME]
903 903
904 904 With no arguments, ``%gui`` removes all GUI support. Valid ``GUINAME``
905 arguments include ``wx``, ``qt``, ``qt5``, ``gtk``, ``gtk3`` and ``tk``.
905 arguments include ``wx``, ``qt``, ``qt5``, ``gtk``, ``gtk3`` ``gtk4``, and
906 ``tk``.
906 907
907 908 Thus, to use wxPython interactively and create a running :class:`wx.App`
908 909 object, do::
@@ -150,6 +150,7 b''
150 150 "&nbsp;&nbsp;<a href='gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
151 151 "&nbsp;&nbsp;<a href='gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
152 152 "&nbsp;&nbsp;<a href='gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n",
153 "&nbsp;&nbsp;<a href='gui/gui-gtk4.py' target='_blank'>gui-gtk4.py</a><br>\n",
153 154 "&nbsp;&nbsp;<a href='gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
154 155 "&nbsp;&nbsp;<a href='gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
155 156 "&nbsp;&nbsp;<a href='gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
@@ -160,6 +161,7 b''
160 161 " gui-glut.py\n",
161 162 " gui-gtk.py\n",
162 163 " gui-gtk3.py\n",
164 " gui-gtk4.py\n",
163 165 " gui-pyglet.py\n",
164 166 " gui-qt.py\n",
165 167 " gui-tk.py\n",
@@ -3180,6 +3180,7 b''
3180 3180 "&nbsp;&nbsp;<a href='./gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
3181 3181 "&nbsp;&nbsp;<a href='./gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
3182 3182 "&nbsp;&nbsp;<a href='./gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n",
3183 "&nbsp;&nbsp;<a href='./gui/gui-gtk4.py' target='_blank'>gui-gtk4.py</a><br>\n",
3183 3184 "&nbsp;&nbsp;<a href='./gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
3184 3185 "&nbsp;&nbsp;<a href='./gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
3185 3186 "&nbsp;&nbsp;<a href='./gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
@@ -3230,6 +3231,7 b''
3230 3231 " gui-glut.py\n",
3231 3232 " gui-gtk.py\n",
3232 3233 " gui-gtk3.py\n",
3234 " gui-gtk4.py\n",
3233 3235 " gui-pyglet.py\n",
3234 3236 " gui-qt.py\n",
3235 3237 " gui-tk.py\n",
General Comments 0
You need to be logged in to leave comments. Login now