gobject-introspection r201 - in trunk: . giscanner
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r201 - in trunk: . giscanner
- Date: Mon, 21 Apr 2008 20:40:10 +0100 (BST)
Author: johan
Date: Mon Apr 21 19:40:09 2008
New Revision: 201
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=201&view=rev
Log:
2008-04-21 Johan Dahlin <johan gnome org>
* giscanner/gobjecttreebuilder.py:
* giscanner/treebuilder.py:
Strip namespaces before objects, so we'll export
GtkButton as Button in the gtk namespace
Modified:
trunk/ChangeLog
trunk/giscanner/gobjecttreebuilder.py
trunk/giscanner/treebuilder.py
Modified: trunk/giscanner/gobjecttreebuilder.py
==============================================================================
--- trunk/giscanner/gobjecttreebuilder.py (original)
+++ trunk/giscanner/gobjecttreebuilder.py Mon Apr 21 19:40:09 2008
@@ -105,14 +105,23 @@
def _get_attribute(self, name):
return self._output_ns.get(name)
- def _strip_namespace(self, name):
- # gtk_init_check -> init_check
- prefix = self._namespace_name.lower() + '_'
- lower = name.lower()
- if lower.startswith(prefix):
- name = name[len(prefix):]
+ def _strip_namespace(self, node):
+ prefix = self._namespace_name.lower()
+ if isinstance(node, Function):
+ # gtk_init_check -> init_check
+ prefix += '_'
+ name = node.name.lower()
+ elif isinstance(node, (Interface, Class, Struct, Enum)):
+ # GtkButton -> Button
+ # GtkTreeModel -> TreeModel
+ # etc
+ name = node.name.lower()
+ else:
+ raise NotImplementedError(node)
- return name
+ if name.startswith(prefix):
+ old = node.name
+ node.name = node.name[len(prefix):]
def _parse_node(self, node):
if isinstance(node, Enum):
@@ -125,6 +134,7 @@
print 'Unhandled node:', node
def _parse_enum(self, enum):
+ self._strip_namespace(enum)
self._add_attribute(enum)
def _parse_function(self, func):
@@ -135,7 +145,7 @@
elif self._parse_method(func):
return
- func.name = self._strip_namespace(func.name)
+ self._strip_namespace(func)
self._add_attribute(func)
def _parse_get_type_function(self, func):
@@ -181,12 +191,15 @@
return self._parse_method_common(func, object_name, is_method=False)
def _parse_method_common(self, func, object_name, is_method):
+ orig_name = object_name
+ if object_name.lower().startswith(self._namespace_name.lower()):
+ object_name = object_name[len(self._namespace_name):]
class_ = self._get_attribute(object_name)
if class_ is None or not isinstance(class_, (GLibObject, GLibBoxed)):
return False
# GtkButton -> gtk_button_, so we can figure out the method name
- prefix = to_underscores(object_name).lower() + '_'
+ prefix = to_underscores(orig_name).lower() + '_'
if not func.name.startswith(prefix):
return False
@@ -232,20 +245,24 @@
klass = (GLibFlags if ftype_id == cgobject.TYPE_FLAGS else GLibEnum)
cenum = klass(cgobject.type_name(type_id), members, symbol)
+ self._strip_namespace(cenum)
self._add_attribute(cenum, replace=True)
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)
+ self._strip_namespace(node)
self._add_attribute(node, replace=True)
def _introspect_interface(self, type_id, symbol):
type_name = cgobject.type_name(type_id)
node = GLibInterface(type_name, [], symbol)
+ self._strip_namespace(node)
self._add_attribute(node, replace=True)
def _introspect_boxed(self, type_id, symbol):
type_name = cgobject.type_name(type_id)
node = GLibBoxed(type_name, [], symbol)
+ self._strip_namespace(node)
self._add_attribute(node, replace=True)
Modified: trunk/giscanner/treebuilder.py
==============================================================================
--- trunk/giscanner/treebuilder.py (original)
+++ trunk/giscanner/treebuilder.py Mon Apr 21 19:40:09 2008
@@ -68,7 +68,8 @@
self.constructors = []
def __repr__(self):
- return 'Class(%r, %r, %r)' % (
+ return '%s(%r, %r, %r)' % (
+ self.__class__.__name__,
self.name, self.parent, self.methods)
@@ -78,7 +79,9 @@
self.methods = methods
def __repr__(self):
- return 'Interface(%r, %r)' % (self.name, self.methods)
+ return '%s(%r, %r)' % (
+ self.__class__.__name__,
+ self.name, self.methods)
class Constant(Node):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]