| 1 |
.. currentmodule:: gi.repository |
| 2 |
|
| 3 |
GTK4 Basics |
| 4 |
=========== |
| 5 |
|
| 6 |
Main loop and Signals |
| 7 |
--------------------- |
| 8 |
Like most GUI toolkits, GTK uses an event-driven programming model. |
| 9 |
When the user is doing nothing, GTK+ sits in the main loop and waits for input. |
| 10 |
If the user performs some action - say, a mouse click - then the main loop |
| 11 |
"wakes up" and delivers an event to GTK. |
| 12 |
|
| 13 |
When widgets receive an event, they frequently emit one or more signals. |
| 14 |
Signals notify your program that "something interesting happened" by invoking |
| 15 |
functions you've connected to the signal. Such functions are commonly known |
| 16 |
as *callbacks*. |
| 17 |
When your callbacks are invoked, you would typically take some action - for |
| 18 |
example, when an Open button is clicked you might display a file chooser |
| 19 |
dialog. After a callback finishes, GTK will return to the main loop and await |
| 20 |
more user input. |
| 21 |
|
| 22 |
:class:`Gtk.Application` will run the main loop for you, so you don't need to |
| 23 |
worry about it. |
| 24 |
|
| 25 |
A :class:`Gtk.Widget` it's also a :class:`GObject.Object`, so to know how to |
| 26 |
interact with these signals you must read the |
| 27 |
:ref:`GObject Basics <basics-signals>`. |
| 28 |
|
| 29 |
.. seealso:: `Library initialization and main loop`_ in GTK documentation. |
| 30 |
|
| 31 |
Properties |
| 32 |
---------- |
| 33 |
Read: :ref:`GObject Basics: Properties <basics-properties>`. |
| 34 |
|
| 35 |
|
| 36 |
.. _Library initialization and main loop: https://docs.gtk.org/gtk4/initialization.html |