Commit 2624bd2b authored by Simon Feltman's avatar Simon Feltman

Move gobject sub-module Python files into the main gi package

This moves the signalhelper, propertyhelper, and constants Python modules
from gi/_gobject into gi. Keep gi/_gobject/__init__.py around because it is
still needed to maintain the "_PyGObject_API" exposed by pygobject.h. This
allows external modules compiled with prior versions of PyGObject to
continue working with newer versions.

https://bugzilla.gnome.org/show_bug.cgi?id=712197
parent d3e8946d
......@@ -58,7 +58,10 @@ nobase_pyexec_PYTHON = \
gi/module.py \
gi/importer.py \
gi/pygtkcompat.py \
gi/docstring.py
gi/docstring.py \
gi/_constants.py \
gi/_propertyhelper.py \
gi/_signalhelper.py
# if we build in a separate tree, we need to symlink the *.py files from the
# source tree; Python does not accept the extensions and modules in different
......
......@@ -24,24 +24,27 @@ from __future__ import absolute_import
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
import sys
import os
# we can't have pygobject 2 loaded at the same time we load the internal _gobject
if 'gobject' in sys.modules:
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".')
from ._gi import _gobject
from ._gi import _API
from ._gi import Repository
from ._gi import PyGIDeprecationWarning
# Force loading the GObject typelib so we have available the wrappers for
# base classes such as GInitiallyUnowned
import gi._gobject
gi # pyflakes
_API = _API # pyflakes
PyGIDeprecationWarning = PyGIDeprecationWarning
import os
_versions = {}
_overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
version_info = gi._gobject.pygobject_version[:]
version_info = _gobject.pygobject_version[:]
__version__ = "{0}.{1}.{2}".format(*version_info)
......
......@@ -2,7 +2,7 @@
# pygobject - Python bindings for the GObject library
# Copyright (C) 2006-2007 Johan Dahlin
#
# gobject/constants.py: GObject type constants
# gi/_constants.py: GObject type constants
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
......@@ -19,8 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
import gi._gi
_gobject = gi._gi._gobject
from ._gi import _gobject
TYPE_INVALID = _gobject.TYPE_INVALID
TYPE_NONE = _gobject.type_from_name('void')
......
......@@ -4,10 +4,7 @@ PLATFORM_VERSION = 3.0
pygobjectdir = $(pyexecdir)/gi/_gobject
pygobject_PYTHON = \
__init__.py \
constants.py \
propertyhelper.py \
signalhelper.py
__init__.py
# if we build in a separate tree, we need to symlink the *.py files from the
# source tree; Python does not accept the extensions and modules in different
......
......@@ -19,44 +19,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
# this can go when things are a little further along
import sys
# we can't have pygobject 2 loaded at the same time we load the internal _gobject
if 'gobject' in sys.modules:
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".')
# Needed for compatibility with "pygobject.h"
import gi._gi
_gobject = gi._gi._gobject
from . import propertyhelper
from . import signalhelper
GObject = _gobject.GObject
GType = _gobject.GType
_PyGObject_API = _gobject._PyGObject_API
pygobject_version = _gobject.pygobject_version
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)
_PyGObject_API = gi._gi._gobject._PyGObject_API
......@@ -2,7 +2,7 @@
# pygobject - Python bindings for the GObject library
# Copyright (C) 2007 Johan Dahlin
#
# gobject/propertyhelper.py: GObject property wrapper/helper
# gi/_propertyhelper.py: GObject property wrapper/helper
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
......@@ -24,7 +24,7 @@ import sys
import gi._gi
_gobject = gi._gi._gobject
from .constants import \
from ._constants import \
TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, \
TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, \
TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, \
......
......@@ -2,7 +2,7 @@
# pygobject - Python bindings for the GObject library
# Copyright (C) 2012 Simon Feltman
#
# gobject/signalhelper.py: GObject signal binding decorator object
# gi/_signalhelper.py: GObject signal binding decorator object
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
......@@ -22,8 +22,7 @@
import sys
import inspect
import gi._gi
_gobject = gi._gi._gobject
from ._gi import _gobject
# Callable went away in python 3.0 and came back in 3.2.
# Use versioning to figure out when to define it, otherwise we have to deal with
......
......@@ -54,15 +54,15 @@ from ._gi import \
enum_add, \
enum_register_new_gtype_and_add, \
flags_add, \
flags_register_new_gtype_and_add
flags_register_new_gtype_and_add, \
_gobject
from .types import \
GObjectMeta, \
GIObjectMeta, \
StructMeta
import gi._gi
GInterface = gi._gi._gobject.GInterface
GInterface = _gobject.GInterface
from ._gobject.constants import \
from ._constants import \
TYPE_NONE, \
TYPE_BOXED, \
TYPE_POINTER, \
......@@ -183,13 +183,13 @@ class IntrospectionModule(object):
interfaces = tuple(interface for interface in get_interfaces_for_object(info)
if not issubclass(parent, interface))
bases = (parent,) + interfaces
metaclass = GObjectMeta
metaclass = GIObjectMeta
elif isinstance(info, CallbackInfo):
bases = (CCallback,)
metaclass = GObjectMeta
metaclass = GIObjectMeta
elif isinstance(info, InterfaceInfo):
bases = (GInterface,)
metaclass = GObjectMeta
metaclass = GIObjectMeta
elif isinstance(info, (StructInfo, UnionInfo)):
if g_type.is_a(TYPE_BOXED):
bases = (Boxed,)
......
......@@ -31,9 +31,10 @@ from gi.overrides import override
from gi.repository import GLib
from gi import PyGIDeprecationWarning
from gi._gobject import _gobject
from gi._gobject import propertyhelper
from gi._gobject import signalhelper
from gi import _propertyhelper as propertyhelper
from gi import _signalhelper as signalhelper
_gobject = gi._gi._gobject
GObjectModule = gi.module.get_introspection_module('GObject')
......
......@@ -3,7 +3,7 @@ import warnings
from gi import PyGIDeprecationWarning
from gi._gi import CallableInfo
from gi._gobject.constants import \
from gi._constants import \
TYPE_NONE, \
TYPE_INVALID
......
......@@ -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:
......
......@@ -90,8 +90,8 @@ def enable():
# gobject
from gi.repository import GObject
sys.modules['gobject'] = GObject
from gi._gobject import propertyhelper
sys.modules['gobject.propertyhelper'] = propertyhelper
from gi import _propertyhelper
sys.modules['gobject.propertyhelper'] = _propertyhelper
# gio
from gi.repository import Gio
......
......@@ -2406,7 +2406,7 @@ class TestMRO(unittest.TestCase):
pass
expected = (E, D, B, C, A, GIMarshallingTests.Object,
GObject.Object, GObject.Object.__base__, gi._gobject.GObject,
GObject.Object, GObject.Object.__base__, gi._gi._gobject.GObject,
object)
self.assertEqual(expected, E.__mro__)
......
......@@ -8,7 +8,9 @@ import warnings
from gi.repository import GObject, GLib
from gi import PyGIDeprecationWarning
from gi.module import get_introspection_module
from gi._gobject import _gobject
import gi
_gobject = gi._gi._gobject
import testhelper
......
......@@ -23,7 +23,7 @@ from gi.repository import Gio
from gi.repository import GLib
from gi.repository import Regress
from gi.repository import GIMarshallingTests
from gi._gobject import propertyhelper
from gi import _propertyhelper as propertyhelper
if sys.version_info < (3, 0):
TEST_UTF8 = "\xe2\x99\xa5"
......
......@@ -5,7 +5,7 @@ import unittest
import sys
from gi.repository import GObject, GLib
from gi._gobject import signalhelper
from gi import _signalhelper as signalhelper
import testhelper
from compathelper import _long
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment