1""" 2GObject compatibility loader; supports ``gi`` and ``pgi``. 3 4The binding selection rules are as follows: 5- if ``gi`` has already been imported, use it; else 6- if ``pgi`` has already been imported, use it; else 7- if ``gi`` can be imported, use it; else 8- if ``pgi`` can be imported, use it; else 9- error out. 10 11Thus, to force usage of PGI when both bindings are installed, import it first. 12""" 13 14from __future__ import (absolute_import, division, print_function, 15 unicode_literals) 16 17import six 18 19import importlib 20import sys 21 22 23if "gi" in sys.modules: 24 import gi 25elif "pgi" in sys.modules: 26 import pgi as gi 27else: 28 try: 29 import gi 30 except ImportError: 31 try: 32 import pgi as gi 33 except ImportError: 34 raise ImportError("The Gtk3 backend requires PyGObject or pgi") 35 36 37gi.require_version("Gtk", "3.0") 38globals().update( 39 {name: 40 importlib.import_module("{}.repository.{}".format(gi.__name__, name)) 41 for name in ["GLib", "GObject", "Gtk", "Gdk"]}) 42