diff options
| author | Simon van der Linden <svdlinden@src.gnome.org> | 2010-01-22 13:41:21 +0100 |
|---|---|---|
| committer | Simon van der Linden <svdlinden@src.gnome.org> | 2010-01-22 13:41:21 +0100 |
| commit | eaf7cb8ebb7e34f9493ac83b2f04af4dcf45f40f (patch) | |
| tree | 92c184f82369ffc181701450fe4045ac0cef2ef3 /gi/module.py | |
| parent | b11cf2595987c1f0fc4ffd834f07c98b92aa2355 (diff) | |
| download | pygi-eaf7cb8ebb7e34f9493ac83b2f04af4dcf45f40f.tar.gz pygi-eaf7cb8ebb7e34f9493ac83b2f04af4dcf45f40f.tar.xz pygi-eaf7cb8ebb7e34f9493ac83b2f04af4dcf45f40f.zip | |
Restore the overrides support
Add a ModuleProxy in front of the DynamicModule when an overrides module is
present. There is no need for an overrides module to be a class; it can just be a module.
Add an override decorator to override the wrapper of a registered type.
Adapt Gdk and Gtk accordingly.
Add tests.
https://bugzilla.gnome.org/show_bug.cgi?id=602830
Diffstat (limited to 'gi/module.py')
| -rw-r--r-- | gi/module.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/gi/module.py b/gi/module.py index 72a6a53..61fbdfc 100644 --- a/gi/module.py +++ b/gi/module.py @@ -75,15 +75,11 @@ def get_interfaces_for_object(object_info): class DynamicModule(object): - def __str__(self): - path = repository.get_typelib_path(self.__namespace__) - return "<dynamic module %r from %r>" % (self.__name__, path) + def __init__(self, namespace): + self._namespace = namespace def __getattr__(self, name): - if self.__dict__.has_key(name): - return self.__dict__[name] - - info = repository.find_by_name(self.__namespace__, name) + info = repository.find_by_name(self._namespace, name) if not info: raise AttributeError("%r object has no attribute %r" % ( self.__class__.__name__, name)) @@ -139,7 +135,7 @@ class DynamicModule(object): name = info.get_name() dict_ = { '__info__': info, - '__module__': self.__namespace__, + '__module__': self._namespace, '__gtype__': g_type } value = metaclass(name, bases, dict_) @@ -158,10 +154,29 @@ class DynamicModule(object): self.__dict__[name] = value return value - @property - def __members__(self): - r = [] - for type_info in repository.get_infos(self.__namespace__): - r.append(type_info.get_name()) - return r + def __repr__(self): + path = repository.get_typelib_path(self._namespace) + return "<DynamicModule %r from %r>" % (self._namespace, path) + + +class ModuleProxy(object): + + def __init__(self, name, namespace, dynamic_module, overrides_module): + self.__name__ = name + + self._namespace = namespace + self._dynamic_module = dynamic_module + self._overrides_module = overrides_module + + def __getattr__(self, name): + attribute = getattr(self._overrides_module, name, None) + exports = getattr(self._overrides_module, '__all__', ()) + if attribute is not None and attribute not in exports: + attribute = None + if attribute is None: + attribute = getattr(self._dynamic_module, name) + return attribute + + def __str__(self): + return "<ModuleProxy %r>" % self.__name__ |
