summaryrefslogtreecommitdiff
path: root/gi/types.py
diff options
context:
space:
mode:
Diffstat (limited to 'gi/types.py')
-rw-r--r--gi/types.py41
1 files changed, 33 insertions, 8 deletions
diff --git a/gi/types.py b/gi/types.py
index c5b4bd5a..0ccfe27e 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -25,8 +25,7 @@ from __future__ import absolute_import
import sys
import warnings
-from . import _gobject
-from ._gobject.constants import TYPE_INVALID
+from ._constants import TYPE_INVALID
from .docstring import generate_doc_string
from ._gi import \
@@ -35,13 +34,16 @@ from ._gi import \
StructInfo, \
VFuncInfo, \
register_interface_info, \
- hook_up_vfunc_implementation
+ hook_up_vfunc_implementation, \
+ _gobject
-import gi._gi
-GInterface = gi._gi._gobject.GInterface
+GInterface = _gobject.GInterface
StructInfo # pyflakes
+from . import _propertyhelper as propertyhelper
+from . import _signalhelper as signalhelper
+
if (3, 0) <= sys.version_info < (3, 3):
# callable not available for python 3.0 thru 3.2
def callable(obj):
@@ -171,16 +173,39 @@ def find_vfunc_conflict_in_bases(vfunc, bases):
return None
-class GObjectMeta(_gobject.GObjectMeta, MetaClassHelper):
+class GObjectMeta(type):
+ "Metaclass for automatically registering GObject classes"
+ def __init__(cls, name, bases, dict_):
+ type.__init__(cls, name, bases, dict_)
+ propertyhelper.install_properties(cls)
+ signalhelper.install_signals(cls)
+ cls._type_register(cls.__dict__)
+
+ def _type_register(cls, namespace):
+ ## don't register the class if already registered
+ if '__gtype__' in namespace:
+ return
+
+ # Do not register a new GType for the overrides, as this would sort of
+ # defeat the purpose of overrides...
+ if cls.__module__.startswith('gi.overrides.'):
+ return
+
+ _gobject.type_register(cls, namespace.get('__gtype_name__'))
+
+_gobject._install_metaclass(GObjectMeta)
+
+
+class GIObjectMeta(GObjectMeta, MetaClassHelper):
def __init__(cls, name, bases, dict_):
- super(GObjectMeta, cls).__init__(name, bases, dict_)
+ super(GIObjectMeta, cls).__init__(name, bases, dict_)
is_gi_defined = False
if cls.__module__ == 'gi.repository.' + cls.__info__.get_namespace():
is_gi_defined = True
is_python_defined = False
- if not is_gi_defined and cls.__module__ != GObjectMeta.__module__:
+ if not is_gi_defined and cls.__module__ != GIObjectMeta.__module__:
is_python_defined = True
if is_python_defined: