From 2d3b39f09eab55b29b0aa5a9cd6565d5a1e772f2 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 18 Jan 2008 16:11:00 +0000 Subject: [PATCH] Merge from trunk: 2008-01-18 Johan Dahlin Merge from trunk: * gtk/gtk-builder-convert (get_property_node): New method (GtkBuilderConverter._create_object): Conditionally take a node as a property value, so don't lose translate/context attributes if they are set. (GtkBuilderConverter._add_action_from_menuitem): Send in Node as property values instead of strings. (#509153, Erik van Pienbroek) svn path=/branches/gtk-2-12/; revision=19384 --- ChangeLog | 12 +++++++++ gtk/gtk-builder-convert | 56 +++++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57f9e4a530..28c495deaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-01-18 Johan Dahlin + + Merge from trunk: + + * gtk/gtk-builder-convert (get_property_node): New method + (GtkBuilderConverter._create_object): Conditionally take a node as + a property value, so don't lose translate/context attributes if they + are set. + (GtkBuilderConverter._add_action_from_menuitem): Send in Node as + property values instead of strings. + (#509153, Erik van Pienbroek) + 2008-01-12 Andre Klapper * configure.in: add Kannada (kn) and Sinhala (si) to ALL_LINGUAS. diff --git a/gtk/gtk-builder-convert b/gtk/gtk-builder-convert index 8e5d0892a2..3544e221ac 100755 --- a/gtk/gtk-builder-convert +++ b/gtk/gtk-builder-convert @@ -82,6 +82,17 @@ def get_property(node, property_name): properties = get_properties(node) return properties.get(property_name) +def get_property_node(node, property_name): + assert node.tagName == 'object' + properties = {} + for child in node.childNodes: + if child.nodeType == Node.TEXT_NODE: + continue + if child.tagName != 'property': + continue + if child.getAttribute('name') == property_name: + return child + def get_signal_nodes(node): assert node.tagName == 'object' signals = [] @@ -126,9 +137,11 @@ def get_object_node(child_node): def copy_properties(node, props, prop_dict): assert node.tagName == 'object' for prop_name in props: - value = get_property(node, prop_name) - if value is not None: - prop_dict[prop_name] = value + child = get_property_node(node, prop_name) + if child is not None: + prop_dict[prop_name] = child + + return node class GtkBuilderConverter(object): @@ -166,6 +179,21 @@ class GtkBuilderConverter(object): if w.getAttribute(attribute) == value] def _create_object(self, obj_class, obj_id, template=None, **properties): + """ + Creates a new tag. + Optionally a name template can be provided which will be used + to avoid naming collisions. + The properties dictionary can either contain string values or Node + values. If a node is provided the name of the node will be overridden + by the dictionary key. + + @param obj_class: class of the object (class tag) + @param obj_id: identifier of the object (id tag) + @param template: name template to use, for example 'button' + @param properties: dictionary of properties + @type properties: string or Node. + @returns: Newly created node of the object + """ if template is not None: count = 1 while True: @@ -180,9 +208,15 @@ class GtkBuilderConverter(object): obj.setAttribute('class', obj_class) obj.setAttribute('id', obj_id) for name, value in properties.items(): - prop = self._dom.createElement('property') + if isinstance(value, Node): + # Reuse the node, so translatable and context still will be + # set when converting nodes. See also #509153 + prop = value + else: + prop = self._dom.createElement('property') + prop.appendChild(self._dom.createTextNode(value)) + prop.setAttribute('name', name) - prop.appendChild(self._dom.createTextNode(value)) obj.appendChild(prop) self.objects[obj_id] = obj return obj @@ -371,18 +405,18 @@ class GtkBuilderConverter(object): if (children and children[0].getAttribute('internal-child') == 'image'): image = get_object_node(children[0]) - stock_id = get_property(image, 'stock') - if stock_id is not None: - properties['stock_id'] = stock_id + child = get_property_node(image, 'stock') + if child is not None: + properties['stock_id'] = child elif object_class == 'GtkSeparatorMenuItem': return else: raise NotImplementedError(object_class) if get_property(node, 'use_stock') == 'True': - stock_id = get_property(node, 'label') - if stock_id is not None: - properties['stock_id'] = stock_id + child = get_property_node(node, 'label') + if child: + properties['stock_id'] = child properties['name'] = object_id action = self._create_object(name,