[pygobject] Correct the Gtk.Window hierarchy



commit 27ac9c1de6487035b18ef4511c155d251cb6d39d
Author: Johan Dahlin <johan gnome org>
Date:   Fri Mar 16 09:59:57 2012 +0100

    Correct the Gtk.Window hierarchy
    
    We need to make sure that all Gtk.Dialog subclasses inherit from
    the overridden Window class. For that to be done automaticly we need
    to create the Window class before the Dialog class.
    
    Now when it's inherited properly we need to avoid calling the Window
    constructor twice as it passes in a construct-only parameter. So add
    **kwargs to the Window constructor to allow us to pass in any kind
    of GObject property to it and refactor the Dialog subclasses to pass
    in all properties to the same constructor.
    
    Also adds a bunch of tests to make sure that the hiearchy is correct.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672158
    
    Signed-off-by: Martin Pitt <martin pitt ubuntu com>

 gi/overrides/Gtk.py     |   56 +++++++++++++++++++++++-----------------------
 tests/test_overrides.py |   35 +++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 30 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 809f051..6ce3b04 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -384,6 +384,16 @@ Builder = override(Builder)
 __all__.append('Builder')
 
 
+# NOTE: This must come before any other Window/Dialog subclassing, to ensure
+# that we have a correct inheritance hierarchy.
+class Window(Gtk.Window):
+    def __init__(self, type=Gtk.WindowType.TOPLEVEL, **kwargs):
+        Gtk.Window.__init__(self, type=type, **kwargs)
+
+Window = override(Window)
+__all__.append('Window')
+
+
 class Dialog(Gtk.Dialog, Container):
 
     def __init__(self,
@@ -470,8 +480,9 @@ class MessageDialog(Gtk.MessageDialog, Dialog):
         Gtk.MessageDialog.__init__(self,
                                    _buttons_property=buttons,
                                    message_type=message_type,
+                                   parent=parent,
+                                   flags=flags,
                                    **kwds)
-        Dialog.__init__(self, parent=parent, flags=flags)
 
     def format_secondary_text(self, message_format):
         self.set_property('secondary-use-markup', False)
@@ -484,23 +495,21 @@ class MessageDialog(Gtk.MessageDialog, Dialog):
 MessageDialog = override(MessageDialog)
 __all__.append('MessageDialog')
 
-class AboutDialog(Gtk.AboutDialog, Dialog):
+class AboutDialog(Gtk.AboutDialog):
     def __init__(self, **kwds):
         Gtk.AboutDialog.__init__(self, **kwds)
-        Dialog.__init__(self)
 
 AboutDialog = override(AboutDialog)
 __all__.append('AboutDialog')
 
-class ColorSelectionDialog(Gtk.ColorSelectionDialog, Dialog):
+class ColorSelectionDialog(Gtk.ColorSelectionDialog):
     def __init__(self, title=None, **kwds):
-        Gtk.ColorSelectionDialog.__init__(self, **kwds)
-        Dialog.__init__(self, title=title)
+        Gtk.ColorSelectionDialog.__init__(self, title=title, **kwds)
 
 ColorSelectionDialog = override(ColorSelectionDialog)
 __all__.append('ColorSelectionDialog')
 
-class FileChooserDialog(Gtk.FileChooserDialog, Dialog):
+class FileChooserDialog(Gtk.FileChooserDialog):
     def __init__(self,
                  title=None,
                  parent=None,
@@ -509,24 +518,21 @@ class FileChooserDialog(Gtk.FileChooserDialog, Dialog):
                  **kwds):
         Gtk.FileChooserDialog.__init__(self,
                                        action=action,
+                                       title=title,
+                                       parent=parent,
+                                       buttons=buttons,
                                        **kwds)
-        Dialog.__init__(self,
-                        title=title,
-                        parent=parent,
-                        buttons=buttons)
-
 FileChooserDialog = override(FileChooserDialog)
 __all__.append('FileChooserDialog')
 
-class FontSelectionDialog(Gtk.FontSelectionDialog, Dialog):
+class FontSelectionDialog(Gtk.FontSelectionDialog):
     def __init__(self, title=None, **kwds):
-        Gtk.FontSelectionDialog.__init__(self, **kwds)
-        Dialog.__init__(self, title=title)
+        Gtk.FontSelectionDialog.__init__(self, title=title, **kwds)
 
 FontSelectionDialog = override(FontSelectionDialog)
 __all__.append('FontSelectionDialog')
 
-class RecentChooserDialog(Gtk.RecentChooserDialog, Dialog):
+class RecentChooserDialog(Gtk.RecentChooserDialog):
     def __init__(self,
                  title=None,
                  parent=None,
@@ -534,11 +540,12 @@ class RecentChooserDialog(Gtk.RecentChooserDialog, Dialog):
                  buttons=None,
                  **kwds):
 
-        Gtk.RecentChooserDialog.__init__(self, recent_manager=manager, **kwds)
-        Dialog.__init__(self,
-                        title=title,
-                        parent=parent,
-                        buttons=buttons)
+        Gtk.RecentChooserDialog.__init__(self,
+                recent_manager=manager,
+                title=title,
+                parent=parent,
+                buttons=buttons,
+                **kwds)
 
 RecentChooserDialog = override(RecentChooserDialog)
 __all__.append('RecentChooserDialog')
@@ -1390,13 +1397,6 @@ Arrow = override(Arrow)
 __all__.append('Arrow')
 
 
-class Window(Gtk.Window):
-    def __init__(self, type=Gtk.WindowType.TOPLEVEL):
-        Gtk.Window.__init__(self, type=type)
-
-Window = override(Window)
-__all__.append('Window')
-
 if Gtk._version != '2.0':
     class Menu(Gtk.Menu):
         def popup(self, parent_menu_shell, parent_menu_item, func, data, button, activate_time):
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index e64c099..c030603 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -558,6 +558,9 @@ class TestGtk(unittest.TestCase):
 
     def test_container(self):
         box = Gtk.Box()
+        self.failUnless(isinstance(box, Gtk.Box))
+        self.failUnless(isinstance(box, Gtk.Container))
+        self.failUnless(isinstance(box, Gtk.Widget))
         self.assertTrue(box)
         label = Gtk.Label()
         label2 = Gtk.Label()
@@ -736,6 +739,8 @@ class TestGtk(unittest.TestCase):
         dialog = Gtk.Dialog (title='Foo',
                              flags=Gtk.DialogFlags.MODAL,
                              buttons=('test-button1', 1))
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
 
         dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
 
@@ -750,12 +755,16 @@ class TestGtk(unittest.TestCase):
 
         # Gtk.AboutDialog
         dialog = Gtk.AboutDialog()
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
 
         # Gtk.MessageDialog
         dialog = Gtk.MessageDialog (title='message dialog test',
                                     flags=Gtk.DialogFlags.MODAL,
                                     buttons=Gtk.ButtonsType.OK,
                                     message_format='dude!')
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
 
         self.assertEquals('message dialog test', dialog.get_title())
         self.assertTrue(dialog.get_modal())
@@ -772,12 +781,16 @@ class TestGtk(unittest.TestCase):
 
         # Gtk.ColorSelectionDialog
         dialog = Gtk.ColorSelectionDialog("color selection dialog test")
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
         self.assertEquals('color selection dialog test', dialog.get_title())
 
         # Gtk.FileChooserDialog
         dialog = Gtk.FileChooserDialog (title='file chooser dialog test',
                                         buttons=('test-button1', 1),
                                         action=Gtk.FileChooserAction.SAVE)
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
 
         dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
         self.assertEquals('file chooser dialog test', dialog.get_title())
@@ -793,6 +806,8 @@ class TestGtk(unittest.TestCase):
 
         # Gtk.FontSelectionDialog
         dialog = Gtk.ColorSelectionDialog("font selection dialog test")
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
         self.assertEquals('font selection dialog test', dialog.get_title())
 
         # Gtk.RecentChooserDialog
@@ -800,6 +815,8 @@ class TestGtk(unittest.TestCase):
         dialog = Gtk.RecentChooserDialog (title='recent chooser dialog test',
                                           buttons=('test-button1', 1),
                                           manager=test_manager)
+        self.failUnless(isinstance(dialog, Gtk.Dialog))
+        self.failUnless(isinstance(dialog, Gtk.Window))
 
         dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
         self.assertEquals('recent chooser dialog test', dialog.get_title())
@@ -1527,6 +1544,9 @@ class TestGtk(unittest.TestCase):
 
         # test Gtk.Button
         button = Gtk.Button()
+        self.failUnless(isinstance(button, Gtk.Button))
+        self.failUnless(isinstance(button, Gtk.Container))
+        self.failUnless(isinstance(button, Gtk.Widget))
         button = Gtk.Button(stock=Gtk.STOCK_CLOSE)
         self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
         self.assertTrue(button.get_use_stock())
@@ -1534,8 +1554,11 @@ class TestGtk(unittest.TestCase):
 
         # test Gtk.LinkButton
         self.assertRaises(TypeError, Gtk.LinkButton)
-        button = Gtk.LinkButton('http://www.gtk.org', 'Gtk')
-        self.assertEquals('http://www.gtk.org', button.get_uri())
+        button = Gtk.LinkButton('http://www.Gtk.org', 'Gtk')
+        self.failUnless(isinstance(button, Gtk.Button))
+        self.failUnless(isinstance(button, Gtk.Container))
+        self.failUnless(isinstance(button, Gtk.Widget))
+        self.assertEquals('http://www.Gtk.org', button.get_uri())
         self.assertEquals('Gtk', button.get_label())
 
     def test_inheritance(self):
@@ -1578,6 +1601,7 @@ class TestGtk(unittest.TestCase):
 
     def test_label(self):
         label = Gtk.Label(label='Hello')
+        self.failUnless(isinstance(label, Gtk.Widget))
         self.assertEquals(label.get_text(), 'Hello')
 
     def adjustment_check(self, adjustment, value=0.0, lower=0.0, upper=0.0,
@@ -1611,6 +1635,9 @@ class TestGtk(unittest.TestCase):
 
     def test_table(self):
         table = Gtk.Table()
+        self.failUnless(isinstance(table, Gtk.Table))
+        self.failUnless(isinstance(table, Gtk.Container))
+        self.failUnless(isinstance(table, Gtk.Widget))
         self.assertEquals(table.get_size(), (1,1))
         self.assertEquals(table.get_homogeneous(), False)
         table = Gtk.Table(2, 3)
@@ -1629,11 +1656,15 @@ class TestGtk(unittest.TestCase):
         self.assertEquals(table.get_homogeneous(), True)
 
         label = Gtk.Label(label='Hello')
+        self.failUnless(isinstance(label, Gtk.Widget))
         table.attach(label, 0, 1, 0, 1)
         self.assertEquals(label, table.get_children()[0])
 
     def test_scrolledwindow(self):
         sw = Gtk.ScrolledWindow()
+        self.failUnless(isinstance(sw, Gtk.ScrolledWindow))
+        self.failUnless(isinstance(sw, Gtk.Container))
+        self.failUnless(isinstance(sw, Gtk.Widget))
         sb = sw.get_hscrollbar()
         self.assertEquals(sw.get_hadjustment(), sb.get_adjustment())
         sb = sw.get_vscrollbar()



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