| 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(widget, 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) |