##// END OF EJS Templates
Merge pull request #13101 from QuLogic/gtk4...
Matthias Bussonnier -
r26737:d4d26467 merge
parent child Browse files
Show More
@@ -0,0 +1,43 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
25 class _InputHook:
26 def __init__(self, context):
27 self._quit = False
28 GLib.io_add_watch(sys.stdin, GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit)
29
30 def quit(self, *args, **kwargs):
31 self._quit = True
32 return False
33
34 def run(self):
35 context = GLib.MainContext.default()
36 while not self._quit:
37 context.iteration(True)
38
39
40 def inputhook_gtk4():
41 hook = _InputHook()
42 hook.run()
43 return 0
@@ -0,0 +1,27 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(
12 context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit
13 )
14
15 def quit(self, *args, **kwargs):
16 self._quit = True
17 return False
18
19 def run(self):
20 context = GLib.MainContext.default()
21 while not self._quit:
22 context.iteration(True)
23
24
25 def inputhook(context):
26 hook = _InputHook(context)
27 hook.run()
@@ -0,0 +1,37 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
13 gi.require_version("Gtk", "4.0")
14 from gi.repository import Gtk, GLib # noqa
15
16
17 def hello_world(wigdet, data=None):
18 print("Hello World")
19
20
21 def close_request_cb(widget, data=None):
22 global running
23 running = False
24
25
26 running = True
27 window = Gtk.Window()
28 window.connect("close-request", close_request_cb)
29 button = Gtk.Button(label="Hello World")
30 button.connect("clicked", hello_world, None)
31
32 window.set_child(button)
33 window.show()
34
35 context = GLib.MainContext.default()
36 while running:
37 context.iteration(True)
@@ -493,6 +493,7 b' Currently the magic system has the following functions:""",'
493 %gui qt5 # enable PyQt5 event loop integration
493 %gui qt5 # enable PyQt5 event loop integration
494 %gui gtk # enable PyGTK event loop integration
494 %gui gtk # enable PyGTK event loop integration
495 %gui gtk3 # enable Gtk3 event loop integration
495 %gui gtk3 # enable Gtk3 event loop integration
496 %gui gtk4 # enable Gtk4 event loop integration
496 %gui tk # enable Tk event loop integration
497 %gui tk # enable Tk event loop integration
497 %gui osx # enable Cocoa event loop integration
498 %gui osx # enable Cocoa event loop integration
498 # (requires %matplotlib 1.1)
499 # (requires %matplotlib 1.1)
@@ -88,7 +88,7 b' class PylabMagics(Magics):'
88 You can list the available backends using the -l/--list option::
88 You can list the available backends using the -l/--list option::
89
89
90 In [4]: %matplotlib --list
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 'gtk', 'tk', 'inline']
92 'gtk', 'tk', 'inline']
93 """
93 """
94 args = magic_arguments.parse_argstring(self.matplotlib, line)
94 args = magic_arguments.parse_argstring(self.matplotlib, line)
@@ -16,6 +16,7 b' backends = {'
16 "tk": "TkAgg",
16 "tk": "TkAgg",
17 "gtk": "GTKAgg",
17 "gtk": "GTKAgg",
18 "gtk3": "GTK3Agg",
18 "gtk3": "GTK3Agg",
19 "gtk4": "GTK4Agg",
19 "wx": "WXAgg",
20 "wx": "WXAgg",
20 "qt4": "Qt4Agg",
21 "qt4": "Qt4Agg",
21 "qt5": "Qt5Agg",
22 "qt5": "Qt5Agg",
@@ -42,10 +43,11 b' backend2gui = dict(zip(backends.values(), backends.keys()))'
42 backend2gui['Qt4Agg'] = 'qt'
43 backend2gui['Qt4Agg'] = 'qt'
43 # In the reverse mapping, there are a few extra valid matplotlib backends that
44 # In the reverse mapping, there are a few extra valid matplotlib backends that
44 # map to the same GUI support
45 # map to the same GUI support
45 backend2gui['GTK'] = backend2gui['GTKCairo'] = 'gtk'
46 backend2gui["GTK"] = backend2gui["GTKCairo"] = "gtk"
46 backend2gui['GTK3Cairo'] = 'gtk3'
47 backend2gui["GTK3Cairo"] = "gtk3"
47 backend2gui['WX'] = 'wx'
48 backend2gui["GTK4Cairo"] = "gtk4"
48 backend2gui['CocoaAgg'] = 'osx'
49 backend2gui["WX"] = "wx"
50 backend2gui["CocoaAgg"] = "osx"
49 # And some backends that don't need GUI integration
51 # And some backends that don't need GUI integration
50 del backend2gui["nbAgg"]
52 del backend2gui["nbAgg"]
51 del backend2gui["agg"]
53 del backend2gui["agg"]
@@ -14,6 +14,7 b' backends = ['
14 "gtk",
14 "gtk",
15 "gtk2",
15 "gtk2",
16 "gtk3",
16 "gtk3",
17 "gtk4",
17 "tk",
18 "tk",
18 "wx",
19 "wx",
19 "pyglet",
20 "pyglet",
@@ -7,9 +7,9 b' loop, so you can use both a GUI and an interactive prompt together. IPython'
7 supports a number of common GUI toolkits, but from IPython 3.0, it is possible
7 supports a number of common GUI toolkits, but from IPython 3.0, it is possible
8 to integrate other event loops without modifying IPython itself.
8 to integrate other event loops without modifying IPython itself.
9
9
10 Supported event loops include ``qt4``, ``qt5``, ``gtk2``, ``gtk3``, ``wx``,
10 Supported event loops include ``qt4``, ``qt5``, ``gtk2``, ``gtk3``, ``gtk4``,
11 ``osx`` and ``tk``. Make sure the event loop you specify matches the GUI
11 ``wx``, ``osx`` and ``tk``. Make sure the event loop you specify matches the
12 toolkit used by your own code.
12 GUI toolkit used by your own code.
13
13
14 To make IPython GUI event loop integration occur automatically at every
14 To make IPython GUI event loop integration occur automatically at every
15 startup, set the ``c.InteractiveShellApp.gui`` configuration key in your
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 <...snip...>
44 <...snip...>
45 --matplotlib=<CaselessStrEnum> (InteractiveShellApp.matplotlib)
45 --matplotlib=<CaselessStrEnum> (InteractiveShellApp.matplotlib)
46 Default: None
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 Configure matplotlib for interactive use with the default matplotlib
48 Configure matplotlib for interactive use with the default matplotlib
49 backend.
49 backend.
50 <...snip...>
50 <...snip...>
@@ -902,7 +902,8 b' For users, enabling GUI event loop integration is simple. You simple use the'
902 %gui [GUINAME]
902 %gui [GUINAME]
903
903
904 With no arguments, ``%gui`` removes all GUI support. Valid ``GUINAME``
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 Thus, to use wxPython interactively and create a running :class:`wx.App`
908 Thus, to use wxPython interactively and create a running :class:`wx.App`
908 object, do::
909 object, do::
@@ -150,6 +150,7 b''
150 "&nbsp;&nbsp;<a href='gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
150 "&nbsp;&nbsp;<a href='gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
151 "&nbsp;&nbsp;<a href='gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
151 "&nbsp;&nbsp;<a href='gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
152 "&nbsp;&nbsp;<a href='gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n",
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 "&nbsp;&nbsp;<a href='gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
154 "&nbsp;&nbsp;<a href='gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
154 "&nbsp;&nbsp;<a href='gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
155 "&nbsp;&nbsp;<a href='gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
155 "&nbsp;&nbsp;<a href='gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
156 "&nbsp;&nbsp;<a href='gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
@@ -160,6 +161,7 b''
160 " gui-glut.py\n",
161 " gui-glut.py\n",
161 " gui-gtk.py\n",
162 " gui-gtk.py\n",
162 " gui-gtk3.py\n",
163 " gui-gtk3.py\n",
164 " gui-gtk4.py\n",
163 " gui-pyglet.py\n",
165 " gui-pyglet.py\n",
164 " gui-qt.py\n",
166 " gui-qt.py\n",
165 " gui-tk.py\n",
167 " gui-tk.py\n",
@@ -3180,6 +3180,7 b''
3180 "&nbsp;&nbsp;<a href='./gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
3180 "&nbsp;&nbsp;<a href='./gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n",
3181 "&nbsp;&nbsp;<a href='./gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
3181 "&nbsp;&nbsp;<a href='./gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n",
3182 "&nbsp;&nbsp;<a href='./gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n",
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 "&nbsp;&nbsp;<a href='./gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
3184 "&nbsp;&nbsp;<a href='./gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n",
3184 "&nbsp;&nbsp;<a href='./gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
3185 "&nbsp;&nbsp;<a href='./gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n",
3185 "&nbsp;&nbsp;<a href='./gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
3186 "&nbsp;&nbsp;<a href='./gui/gui-tk.py' target='_blank'>gui-tk.py</a><br>\n",
@@ -3230,6 +3231,7 b''
3230 " gui-glut.py\n",
3231 " gui-glut.py\n",
3231 " gui-gtk.py\n",
3232 " gui-gtk.py\n",
3232 " gui-gtk3.py\n",
3233 " gui-gtk3.py\n",
3234 " gui-gtk4.py\n",
3233 " gui-pyglet.py\n",
3235 " gui-pyglet.py\n",
3234 " gui-qt.py\n",
3236 " gui-qt.py\n",
3235 " gui-tk.py\n",
3237 " gui-tk.py\n",
General Comments 0
You need to be logged in to leave comments. Login now