Assert that the tagname of the nodes are correct, factor out a method to a function which doesn't use the instance state.

svn path=/trunk/; revision=18393
This commit is contained in:
Johan Dahlin 2007-07-07 15:59:53 +00:00
parent c83ba1d9c6
commit 1acfcddb68

View File

@ -55,6 +55,7 @@ except ImportError:
subprocess = None
def get_child_nodes(node):
assert node.tagName == 'object'
nodes = []
for child in node.childNodes:
if child.nodeType == Node.TEXT_NODE:
@ -65,6 +66,7 @@ def get_child_nodes(node):
return nodes
def get_object_properties(node):
assert node.tagName == 'object'
properties = {}
for child in node.childNodes:
if child.nodeType == Node.TEXT_NODE:
@ -75,6 +77,11 @@ def get_object_properties(node):
properties[child.getAttribute('name')] = value
return properties
def get_property(node, property_name):
assert node.tagName == 'object'
properties = get_object_properties(node)
return properties.get(property_name)
def get_object_node(child_node):
assert child_node.tagName == 'child'
nodes = []
@ -86,6 +93,7 @@ def get_object_node(child_node):
assert len(nodes) == 1, nodes
return nodes[0]
class GtkBuilderConverter(object):
def __init__(self, skip_windows, root):
@ -148,10 +156,6 @@ class GtkBuilderConverter(object):
self.root_objects.append(obj)
return obj
def _get_property(self, node, property_name):
properties = get_object_properties(node)
return properties.get(property_name)
def _parse(self):
glade_iface = self._dom.getElementsByTagName("glade-interface")
assert glade_iface, ("Badly formed XML, there is "
@ -304,10 +308,10 @@ class GtkBuilderConverter(object):
if (children and
children[0].getAttribute('internal-child') == 'image'):
image = get_object_node(children[0])
properties['stock_id'] = self._get_property(image, 'stock')
properties['stock_id'] = get_property(image, 'stock')
elif object_class == 'GtkMenuItem':
name = 'GtkAction'
label = self._get_property(node, 'label')
label = get_property(node, 'label')
if label is not None:
properties['label'] = label
elif object_class == 'GtkSeparatorMenuItem':
@ -315,8 +319,8 @@ class GtkBuilderConverter(object):
else:
raise NotImplementedError(object_class)
if self._get_property(node, 'use_stock') == 'True':
properties['stock_id'] = self._get_property(node, 'label')
if get_property(node, 'use_stock') == 'True':
properties['stock_id'] = get_property(node, 'label')
properties['name'] = object_id
action = self._create_object(name,
object_id,