Re: maintaining both gtk2 and 3 compatibility



Hi Richard.

On 11/09/2011 11:54 AM, Richard Henwood wrote:
> Is it feasible to keep backward compatibility with gtk2 (gnome2) or should I rip out all the wnck2 packages (below) and maintain two separate code trees?

> richard@wc-hp:~/tools/skype-record$ dpkg -l '*wnck*'
> Desired=Unknown/Install/Remove/Purge/Hold
> | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
> |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
> ||/ Name               Version            Description
> +++-==================-==================-====================================================
> ii  gir1.2-wnck-3.0    3.2.0-0ubuntu1     GObject introspection data for the WNCK library
> ii  libwnck-3-0        3.2.0-0ubuntu1     Window Navigator Construction Kit - runtime files
> ii  libwnck-3-common   3.2.0-0ubuntu1     Window Navigator Construction Kit - common files
> ii  libwnck-3-dev      3.2.0-0ubuntu1     Window Navigator Construction Kit - development file
> ii  libwnck-common     1:2.30.7-0ubuntu1  Window Navigator Construction Kit - common files
> un  libwnck-dev        <none>             (no description available)
> ii  libwnck22          1:2.30.7-0ubuntu1  Window Navigator Construction Kit - runtime files
> ii  python-wnck        2.32.0-0ubuntu6    Python bindings for the WNCK library
> un  wncksyncdaemon     <none>             (no description available)

Yes, it is feasible, but it is a burden to maintain. I am maintaining
two trees for my python projects because the API changes are
substantial. GTK enums are incompatible, so you may want to trees once
you are using them.  I reccomend Trunk is gtk3, I backport some changes
to older gtk2 releases.

I have one case where the API is pretty similar and I decided to delay
the split. You can alias your imports so that most of the code thinks it
is working with GTK3.

try:
    from gi.repository import GObject
    from gi.repository import Gtk
    from gi.repository import WebKit
except ImportError:
    import pygtk
    pygtk.require("2.0")
    import glib as GObject
    import gtk as Gtk
    import webkit as WebKit

You may also need to check for cases of API change:
# Check for available API, avoid hasattr because it
# swallows keyboard and system interrupts.
method = getattr(thing, 'method_name', None)
if method is not None:
    method(arg1)


-- 

__C U R T I S  C.  H O V E Y_______
Guilty of stealing everything I am.

Attachment: signature.asc
Description: OpenPGP digital signature



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