[pygobject/wip/mschraal/gtk4-container-removal] gtk overrides: Remove Container use for GTK4
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/wip/mschraal/gtk4-container-removal] gtk overrides: Remove Container use for GTK4
- Date: Mon, 8 Jun 2020 19:03:17 +0000 (UTC)
commit 224309b264947848899a4df931d0b5f58e7326ab
Author: Marinus Schraal <mschraal gnome org>
Date: Mon Jun 8 16:27:55 2020 +0200
gtk overrides: Remove Container use for GTK4
gi/overrides/Gtk.py | 33 +++++++++++++++++----------------
tests/test_overrides_gtk.py | 18 +++++++++++++-----
2 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 64a5088e..5092bca2 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -165,24 +165,23 @@ Widget = override(Widget)
__all__.append('Widget')
-class Container(Gtk.Container, Widget):
+if Gtk._version in ("2.0", "3.0"):
+ class Container(Gtk.Container, Widget):
- def __len__(self):
- return len(self.get_children())
+ def __len__(self):
+ return len(self.get_children())
- def __contains__(self, child):
- return child in self.get_children()
+ def __contains__(self, child):
+ return child in self.get_children()
- def __iter__(self):
- return iter(self.get_children())
+ def __iter__(self):
+ return iter(self.get_children())
- def __bool__(self):
- return True
+ def __bool__(self):
+ return True
- # alias for Python 2.x object protocol
- __nonzero__ = __bool__
-
- if Gtk._version in ("2.0", "3.0"):
+ # alias for Python 2.x object protocol
+ __nonzero__ = __bool__
def child_get_property(self, child, property_name, value=None):
if value is None:
@@ -207,9 +206,11 @@ class Container(Gtk.Container, Widget):
get_focus_chain = strip_boolean_result(Gtk.Container.get_focus_chain)
-
-Container = override(Container)
-__all__.append('Container')
+ Container = override(Container)
+ __all__.append('Container')
+else:
+ class Container(object):
+ pass
class Editable(Gtk.Editable):
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index ff3acba9..99342a63 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -58,7 +58,10 @@ def realized(widget):
if toplevel is None:
window = Gtk.Window()
- window.add(widget)
+ if Gtk._version == "4.0":
+ window.set_child(widget)
+ else:
+ window.add(widget)
widget.realize()
if Gtk._version == "4.0":
@@ -161,6 +164,7 @@ def test_wrapper_toggle_refs():
@unittest.skipUnless(Gtk, 'Gtk not available')
@ignore_gi_deprecation_warnings
class TestGtk(unittest.TestCase):
+ @unittest.skipIf(Gtk_version == "4.0", "not in gtk4")
def test_container(self):
box = Gtk.Box()
self.assertTrue(isinstance(box, Gtk.Box))
@@ -557,7 +561,8 @@ class TestGtk(unittest.TestCase):
# test Gtk.Button
button = Gtk.Button()
self.assertTrue(isinstance(button, Gtk.Button))
- self.assertTrue(isinstance(button, Gtk.Container))
+ if Gtk._version != "4.0":
+ self.assertTrue(isinstance(button, Gtk.Container))
self.assertTrue(isinstance(button, Gtk.Widget))
if Gtk_version != "4.0":
@@ -579,7 +584,8 @@ class TestGtk(unittest.TestCase):
# test Gtk.LinkButton
button = Gtk.LinkButton(uri='http://www.Gtk.org', label='Gtk')
self.assertTrue(isinstance(button, Gtk.Button))
- self.assertTrue(isinstance(button, Gtk.Container))
+ if Gtk._version != "4.0":
+ self.assertTrue(isinstance(button, Gtk.Container))
self.assertTrue(isinstance(button, Gtk.Widget))
self.assertEqual('http://www.Gtk.org', button.get_uri())
self.assertEqual('Gtk', button.get_label())
@@ -662,7 +668,8 @@ class TestGtk(unittest.TestCase):
def test_table(self):
table = Gtk.Table()
self.assertTrue(isinstance(table, Gtk.Table))
- self.assertTrue(isinstance(table, Gtk.Container))
+ if Gtk._version != "4.0":
+ self.assertTrue(isinstance(table, Gtk.Container))
self.assertTrue(isinstance(table, Gtk.Widget))
self.assertEqual(table.get_size(), (1, 1))
self.assertEqual(table.get_homogeneous(), False)
@@ -683,7 +690,8 @@ class TestGtk(unittest.TestCase):
def test_scrolledwindow(self):
sw = Gtk.ScrolledWindow()
self.assertTrue(isinstance(sw, Gtk.ScrolledWindow))
- self.assertTrue(isinstance(sw, Gtk.Container))
+ if Gtk._version != "4.0":
+ self.assertTrue(isinstance(sw, Gtk.Container))
self.assertTrue(isinstance(sw, Gtk.Widget))
sb = sw.get_hscrollbar()
self.assertEqual(sw.get_hadjustment(), sb.get_adjustment())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]