[pygobject/gsoc2009: 85/160] Fix enums and flags
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 85/160] Fix enums and flags
- Date: Fri, 14 Aug 2009 21:29:13 +0000 (UTC)
commit f06877c357ef6f9db2b7e154b4ef02e400aef9b8
Author: Simon van der Linden <svdlinden src gnome org>
Date: Fri Jul 31 12:46:44 2009 +0200
Fix enums and flags
Fix enums and flags so that they conform to existing (PyGObject) GEnum and GFlags
implementations.
gi/module.py | 7 ++++++-
gi/types.py | 11 +----------
2 files changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index e790706..49e7d56 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -91,9 +91,14 @@ class DynamicModule(object):
elif type_.is_a(gobject.TYPE_FLAGS):
value = gobject.flags_from_g_type(type_)
else:
- raise TypeError, "Must be either a subtype of gobject.TYPE_ENUM, or gobject.TYPE_FLAGS"
+ raise TypeError, "Must be a subtype of either gobject.TYPE_ENUM, or gobject.TYPE_FLAGS"
value.__info__ = info
value.__module__ = info.getNamespace()
+
+ for value_info in info.getValues():
+ name = value_info.getName().upper()
+ setattr(value, name, value(value_info.getValue()))
+
elif isinstance(info, RegisteredTypeInfo):
# Check if there is already a Python wrapper.
gtype = info.getGType()
diff --git a/gi/types.py b/gi/types.py
index 682b4ad..00198ef 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -28,8 +28,7 @@ from ._gi import \
setObjectHasNewConstructor, \
InterfaceInfo, \
ObjectInfo, \
- StructInfo, \
- EnumInfo
+ StructInfo
def Function(info):
@@ -76,9 +75,6 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
cls._setup_fields()
cls._setup_methods()
- if isinstance(cls.__info__, EnumInfo):
- cls._setup_values()
-
def _setup_methods(cls):
constructor_infos = []
method_infos = cls.__info__.getMethods()
@@ -119,11 +115,6 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
name = field_info.getName().replace('-', '_')
setattr(cls, name, Field(field_info))
- def _setup_values(cls):
- for value_info in cls.__info__.getValues():
- name = value_info.getName().upper()
- setattr(cls, name, value_info.getValue())
-
class GIStruct(object):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]