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 | 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", |
@@ -42,10 +43,11 b' backend2gui = dict(zip(backends.values(), backends.keys()))' | |||
|
42 | 43 | backend2gui['Qt4Agg'] = 'qt' |
|
43 | 44 | # In the reverse mapping, there are a few extra valid matplotlib backends that |
|
44 | 45 | # map to the same GUI support |
|
45 |
backend2gui[ |
|
|
46 |
backend2gui[ |
|
|
47 | backend2gui['WX'] = 'wx' | |
|
48 |
backend2gui[ |
|
|
46 | backend2gui["GTK"] = backend2gui["GTKCairo"] = "gtk" | |
|
47 | backend2gui["GTK3Cairo"] = "gtk3" | |
|
48 | backend2gui["GTK4Cairo"] = "gtk4" | |
|
49 | backend2gui["WX"] = "wx" | |
|
50 | backend2gui["CocoaAgg"] = "osx" | |
|
49 | 51 | # And some backends that don't need GUI integration |
|
50 | 52 | del backend2gui["nbAgg"] |
|
51 | 53 | del backend2gui["agg"] |
@@ -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``, `` |
|
|
11 |
``osx`` and ``tk``. Make sure the event loop you specify matches the |
|
|
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`` |
|
|
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 | " <a href='gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n", |
|
151 | 151 | " <a href='gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n", |
|
152 | 152 | " <a href='gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n", |
|
153 | " <a href='gui/gui-gtk4.py' target='_blank'>gui-gtk4.py</a><br>\n", | |
|
153 | 154 | " <a href='gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n", |
|
154 | 155 | " <a href='gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n", |
|
155 | 156 | " <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 | " <a href='./gui/gui-glut.py' target='_blank'>gui-glut.py</a><br>\n", |
|
3181 | 3181 | " <a href='./gui/gui-gtk.py' target='_blank'>gui-gtk.py</a><br>\n", |
|
3182 | 3182 | " <a href='./gui/gui-gtk3.py' target='_blank'>gui-gtk3.py</a><br>\n", |
|
3183 | " <a href='./gui/gui-gtk4.py' target='_blank'>gui-gtk4.py</a><br>\n", | |
|
3183 | 3184 | " <a href='./gui/gui-pyglet.py' target='_blank'>gui-pyglet.py</a><br>\n", |
|
3184 | 3185 | " <a href='./gui/gui-qt.py' target='_blank'>gui-qt.py</a><br>\n", |
|
3185 | 3186 | " <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