[pygobject/wip/jfelder/gtk4-toolbutton: 2/3] gtk overrides: Drop Gtk.main for Gtk4



commit f3248b7bd5cf99950a60ecedb45d5ef85b9af4eb
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Mar 16 20:46:17 2020 +0100

    gtk overrides: Drop Gtk.main for Gtk4
    
    It has been removed (gtk commit
    4dd780a96b1d37903ab88a4ae4536329cd9e164e)
    
    The associated tests are updated or skipped for Gtk 4.

 gi/overrides/Gtk.py         | 24 +++++++++++-------------
 tests/test_ossig.py         |  3 +++
 tests/test_overrides_gtk.py | 29 +++++++++++++++++++++++------
 3 files changed, 37 insertions(+), 19 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 74555d16..b4213642 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1614,22 +1614,20 @@ if Gtk._version == '3.0':
     Menu = override(Menu)
     __all__.append('Menu')
 
-_Gtk_main_quit = Gtk.main_quit
-
-
-@override(Gtk.main_quit)
-def main_quit(*args):
-    _Gtk_main_quit()
-
+if Gtk._version in ("2.0", "3.0"):
+    _Gtk_main_quit = Gtk.main_quit
 
-_Gtk_main = Gtk.main
+    @override(Gtk.main_quit)
+    def main_quit(*args):
+        _Gtk_main_quit()
 
+    _Gtk_main = Gtk.main
 
-@override(Gtk.main)
-def main(*args, **kwargs):
-    with register_sigint_fallback(Gtk.main_quit):
-        with wakeup_on_signal():
-            return _Gtk_main(*args, **kwargs)
+    @override(Gtk.main)
+    def main(*args, **kwargs):
+        with register_sigint_fallback(Gtk.main_quit):
+            with wakeup_on_signal():
+                return _Gtk_main(*args, **kwargs)
 
 
 if Gtk._version in ("2.0", "3.0"):
diff --git a/tests/test_ossig.py b/tests/test_ossig.py
index b59f2f5a..9340c02b 100644
--- a/tests/test_ossig.py
+++ b/tests/test_ossig.py
@@ -24,8 +24,10 @@ from contextlib import contextmanager
 
 try:
     from gi.repository import Gtk
+    Gtk_version = Gtk._version
 except ImportError:
     Gtk = None
+    Gtk_version = None
 from gi.repository import Gio, GLib
 from gi._ossighelper import wakeup_on_signal, register_sigint_fallback
 
@@ -90,6 +92,7 @@ class TestOverridesWakeupOnAlarm(unittest.TestCase):
             app.run()
 
     @unittest.skipIf(Gtk is None or os.name == "nt", "not on Windows")
+    @unittest.skipIf(Gtk is None or Gtk_version == "4.0", "not in gtk4")
     def test_gtk_main(self):
         signal.signal(signal.SIGALRM, lambda *args: Gtk.main_quit())
         GLib.idle_add(signal.setitimer, signal.ITIMER_REAL, 0.001)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 0b4eae60..d0c6442e 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -65,8 +65,14 @@ def realized(widget):
         window.add(widget)
 
     widget.realize()
-    while Gtk.events_pending():
-        Gtk.main_iteration()
+    if Gtk._version == "4.0":
+        context = GLib.MainContext()
+        while context.pending():
+            context.iteration(False)
+    else:
+        while Gtk.events_pending():
+            Gtk.main_iteration()
+
     assert widget.get_realized()
     yield widget
 
@@ -74,8 +80,13 @@ def realized(widget):
         window.remove(widget)
         window.destroy()
 
-    while Gtk.events_pending():
-        Gtk.main_iteration()
+    if Gtk._version == "4.0":
+        context = GLib.MainContext()
+        while context.pending():
+            context.iteration(False)
+    else:
+        while Gtk.events_pending():
+            Gtk.main_iteration()
 
 
 @unittest.skipUnless(Gtk, 'Gtk not available')
@@ -806,6 +817,7 @@ class TestGtk(unittest.TestCase):
         self.assertEqual(stock_item.stock_id, 'gtk-ok')
         self.assertEqual(Gtk.stock_lookup('nosuchthing'), None)
 
+    @unittest.skipIf(Gtk_version == "4.0", "not in gtk4")
     def test_gtk_main(self):
         # with no arguments
         GLib.idle_add(Gtk.main_quit)
@@ -2396,8 +2408,13 @@ class TestTreeView(unittest.TestCase):
 
         with realized(tree):
             tree.set_cursor(model[0].path)
-            while Gtk.events_pending():
-                Gtk.main_iteration()
+            if Gtk._version == "4.0":
+                context = GLib.MainContext()
+                while context.pending():
+                    context.iteration(False)
+            else:
+                while Gtk.events_pending():
+                    Gtk.main_iteration()
 
             self.assertEqual(tree.get_column(0).get_title(), 'Head1')
             self.assertEqual(tree.get_column(1).get_title(), 'Head2')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]