gobject-introspection r205 - in trunk: . giscanner



Author: johan
Date: Mon Apr 21 21:03:05 2008
New Revision: 205
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=205&view=rev

Log:
2008-04-21  Johan Dahlin  <johan gnome org>

	* giscanner/gidlwriter.py:
	* giscanner/gobjecttreebuilder.py:
	* giscanner/treebuilder.py:
	Add support for properties.
	Refactor Class/Interface support a bit, to share more code and
	always initialize their method attribute to an empty list.



Modified:
   trunk/ChangeLog
   trunk/giscanner/gidlwriter.py
   trunk/giscanner/gobjecttreebuilder.py
   trunk/giscanner/treebuilder.py

Modified: trunk/giscanner/gidlwriter.py
==============================================================================
--- trunk/giscanner/gidlwriter.py	(original)
+++ trunk/giscanner/gidlwriter.py	Mon Apr 21 21:03:05 2008
@@ -25,10 +25,8 @@
             self._write_function(node)
         elif isinstance(node, Enum):
             self._write_enum(node)
-        elif isinstance(node, Class):
+        elif isinstance(node, (Class, Interface)):
             self._write_class(node)
-        elif isinstance(node, Interface):
-            self._write_interface(node)
         elif isinstance(node, GLibBoxed):
             self._write_boxed(node)
         else:
@@ -82,24 +80,23 @@
             attrs.append(('nick', member.nick))
         self.write_tag('member', attrs)
 
-    def _write_class(self, class_):
-        attrs = [('name', class_.name),
-                 ('parent', class_.parent)]
-        if isinstance(class_, GLibObject):
-            attrs.append(('get-type', class_.get_type))
-        with self.tagcontext('object', attrs):
-            for method in class_.constructors:
-                self._write_constructor(method)
-            for method in class_.methods:
-                self._write_method(method)
-
-    def _write_interface(self, interface):
-        attrs = [('name', interface.name)]
-        if isinstance(interface, GLibInterface):
-            attrs.append(('get-type', interface.get_type))
-        with self.tagcontext('interface', attrs):
-            for method in interface.methods:
+    def _write_class(self, node):
+        attrs = [('name', node.name)]
+        if isinstance(node, Class):
+            tag_name = 'object'
+            attrs.append(('parent', node.parent))
+        else:
+            tag_name = 'interface'
+        if isinstance(node, (GLibObject, GLibInterface)):
+            attrs.append(('get-type', node.get_type))
+        with self.tagcontext(tag_name, attrs):
+            if isinstance(node, Class):
+                for method in node.constructors:
+                    self._write_constructor(method)
+            for method in node.methods:
                 self._write_method(method)
+            for prop in node.properties:
+                self._write_property(prop)
 
     def _write_boxed(self, boxed):
         attrs = [('name', boxed.name)]
@@ -110,3 +107,8 @@
                 self._write_constructor(method)
             for method in boxed.methods:
                 self._write_method(method)
+
+    def _write_property(self, prop):
+        attrs = [('name', prop.name),
+                 ('prop', prop.type)]
+        self.write_tag('property', attrs)

Modified: trunk/giscanner/gobjecttreebuilder.py
==============================================================================
--- trunk/giscanner/gobjecttreebuilder.py	(original)
+++ trunk/giscanner/gobjecttreebuilder.py	Mon Apr 21 21:03:05 2008
@@ -3,7 +3,8 @@
 import os
 
 from . import cgobject
-from .treebuilder import Class, Enum, Function, Interface, Member, Struct
+from .treebuilder import (Class, Enum, Function, Interface, Member, Property,
+                          Struct)
 from .odict import odict
 
 
@@ -55,13 +56,13 @@
 
 
 class GLibObject(Class):
-    def __init__(self, name, parent, methods, get_type):
-        Class.__init__(self, name, parent, methods)
+    def __init__(self, name, parent, get_type):
+        Class.__init__(self, name, parent)
         self.get_type = get_type
 
 
 class GLibBoxed(Struct):
-    def __init__(self, name, methods, get_type):
+    def __init__(self, name, get_type):
         Struct.__init__(self, name)
         self.constructors = []
         self.methods = []
@@ -69,11 +70,15 @@
 
 
 class GLibInterface(Interface):
-    def __init__(self, name, methods, get_type):
-        Interface.__init__(self, name, methods)
+    def __init__(self, name, get_type):
+        Interface.__init__(self, name)
         self.get_type = get_type
 
 
+class GLibProperty(Property):
+    pass
+
+
 class GObjectTreeBuilder(object):
     def __init__(self, namespace_name):
         self._namespace_name = namespace_name
@@ -255,21 +260,39 @@
     def _introspect_object(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
         parent_name = cgobject.type_name(cgobject.type_parent(type_id))
-        node = GLibObject(type_name, parent_name, [], symbol)
+        node = GLibObject(type_name, parent_name, symbol)
+        self._introspect_properties(node, type_id)
         self._strip_namespace(node)
         self._add_attribute(node)
         self._remove_attribute(type_name)
 
     def _introspect_interface(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
-        node = GLibInterface(type_name, [], symbol)
+        node = GLibInterface(type_name, symbol)
         self._strip_namespace(node)
+        self._introspect_properties(node, type_id)
         self._add_attribute(node)
         self._remove_attribute(type_name)
 
     def _introspect_boxed(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
-        node = GLibBoxed(type_name, [], symbol)
+        node = GLibBoxed(type_name, symbol)
         self._strip_namespace(node)
         self._add_attribute(node)
         self._remove_attribute(type_name)
+
+    def _introspect_properties(self, node, type_id):
+        fundamental_type_id = cgobject.type_fundamental(type_id)
+        if fundamental_type_id == cgobject.TYPE_OBJECT:
+            pspecs = cgobject.object_class_list_properties(type_id)
+        elif fundamental_type_id == cgobject.TYPE_INTERFACE:
+            pspecs = cgobject.object_interface_list_properties(type_id)
+        else:
+            raise AssertionError
+
+        for pspec in pspecs:
+            if pspec.owner_type != type_id:
+                continue
+            node.properties.append(Property(
+                pspec.name,
+                cgobject.type_name(pspec.value_type)))

Modified: trunk/giscanner/treebuilder.py
==============================================================================
--- trunk/giscanner/treebuilder.py	(original)
+++ trunk/giscanner/treebuilder.py	Mon Apr 21 21:03:05 2008
@@ -61,11 +61,12 @@
 
 
 class Class(Node):
-    def __init__(self, name, parent, methods):
+    def __init__(self, name, parent):
         self.name = name
         self.parent = parent
-        self.methods = methods
+        self.methods = []
         self.constructors = []
+        self.properties = []
 
     def __repr__(self):
         return '%s(%r, %r, %r)' % (
@@ -74,9 +75,10 @@
 
 
 class Interface(Node):
-    def __init__(self, name, methods):
+    def __init__(self, name):
         self.name = name
-        self.methods = methods
+        self.methods = []
+        self.properties = []
 
     def __repr__(self):
         return '%s(%r, %r)' % (
@@ -95,6 +97,17 @@
             self.name, self.type, self.value)
 
 
+class Property(Node):
+    def __init__(self, name, type):
+        self.name = name
+        self.type = type
+
+    def __repr__(self):
+        return '%s(%r, %r, %r)' % (
+            self.__class__.__name__,
+            self.name, self.type, self.value)
+
+
 class TreeBuilder(object):
     def __init__(self, generator):
         self.generator = generator



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]