From fa0b0e258aff23dded18aa3705791299a63d7b9a Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 1 Dec 2022 23:59:27 +0200 Subject: Update docs and code examples to GTK 4 --- docs/getting_started.rst | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'docs/getting_started.rst') diff --git a/docs/getting_started.rst b/docs/getting_started.rst index e6921af8..01874efa 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -13,14 +13,27 @@ the following content and save it somewhere: .. code:: python + import sys + import gi - gi.require_version("Gtk", "3.0") - from gi.repository import Gtk - window = Gtk.Window(title="Hello World") - window.show() - window.connect("destroy", Gtk.main_quit) - Gtk.main() + gi.require_version("Gtk", "4.0") + from gi.repository import GLib, Gtk + + + class MyApplication(Gtk.Application): + def __init__(self): + super().__init__(application_id="com.example.MyGtkApplication") + GLib.set_application_name('My Gtk Application') + + def do_activate(self): + window = Gtk.ApplicationWindow(application=self, title="Hello World") + window.present() + + + app = MyApplication() + exit_status = app.run(sys.argv) + sys.exit(exit_status) Before we can run the example application we need to install PyGObject, GTK and their dependencies. Follow the instructions for your platform below. @@ -45,8 +58,8 @@ libraries. There are also typing stubs available here `PyGObject-stubs `` #) In the mingw32 terminal execute ``python3 hello.py`` - a window should appear. @@ -61,13 +74,13 @@ libraries. There are also typing stubs available here `PyGObject-stubs