Imported Upstream version 3.7.3
[platform/upstream/python-gobject.git] / gi / _gobject / __init__.py
1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # pygobject - Python bindings for the GObject library
3 # Copyright (C) 2006-2012  Johan Dahlin
4 #
5 #   gobject/__init__.py: initialisation file for gobject module
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 # USA
21
22 # this can go when things are a little further along
23
24 import sys
25
26 # we can't have pygobject 2 loaded at the same time we load the internal _gobject
27 if 'gobject' in sys.modules:
28     raise ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".')
29
30 from . import _gobject
31 from . import propertyhelper
32 from . import signalhelper
33
34 GObject = _gobject.GObject
35 GType = _gobject.GType
36 _PyGObject_API = _gobject._PyGObject_API
37 pygobject_version = _gobject.pygobject_version
38
39
40 class GObjectMeta(type):
41     "Metaclass for automatically registering GObject classes"
42     def __init__(cls, name, bases, dict_):
43         type.__init__(cls, name, bases, dict_)
44         propertyhelper.install_properties(cls)
45         signalhelper.install_signals(cls)
46         cls._type_register(cls.__dict__)
47
48     def _type_register(cls, namespace):
49         ## don't register the class if already registered
50         if '__gtype__' in namespace:
51             return
52
53         # Do not register a new GType for the overrides, as this would sort of
54         # defeat the purpose of overrides...
55         if cls.__module__.startswith('gi.overrides.'):
56             return
57
58         _gobject.type_register(cls, namespace.get('__gtype_name__'))
59
60 _gobject._install_metaclass(GObjectMeta)