PyGTKCompat


The pygtkcompat module provides a PyGTK compatible API on top of gobject-introspection which makes it possible to run your application on top of both PyGTK and gobject-introspection at the same time.

Before using it you should port your application to using latest API, available 2.24, for instance:

  • widget.window should be widget.get_window()
    container.child should be container.get_child()
    widget.flags() & gtk.REALIZED should be container.get_realized()

and so on.

Once an application has been updated to the latest PyGTK API, you can then import pygtkcompat and enable the parts you need. For instance, to enable PyGTK compatible API on top of the Gtk 3.0 typelib, use the following:

  • from gi import pygtkcompat
    
    pygtkcompat.enable() 
    pygtkcompat.enable_gtk(version='3.0')
    

That's it, if you're lucky enough and you're not using any strange/weird apis you should be able to run your application. If you want an app to be compatible with both PyGTK and PyGI, you can use the following technique:

  • try:
        from gi import pygtkcompat
    except ImportError:
        pygtkcompat = None
    
    if pygtkcompat is not None:
        pygtkcompat.enable() 
        pygtkcompat.enable_gtk(version='3.0')
    
    import gtk
    

    Note

    Porting the application from 2 to 3 is best covered in http://developer.gnome.org/gtk3/3.2/gtk-migrating-2-to-3.html. That usually includes things such as change expose-event to draw and do drawing with cairo.

Projects/PyGObject/PyGTKCompat (last edited 2013-11-23 00:13:41 by WilliamJonMcCann)