New method (GtkBuilderConverter._create_object): Conditionally take a node
2008-01-18 Johan Dahlin <johan@gnome.org> * 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=/trunk/; revision=19383
This commit is contained in:
committed by
Johan Dahlin
parent
188894d18e
commit
6805e87247
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2008-01-18 Johan Dahlin <johan@gnome.org>
|
||||||
|
|
||||||
|
* 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-16 Mathias Hasselmann <mathias@openismus.com>
|
2008-01-16 Mathias Hasselmann <mathias@openismus.com>
|
||||||
|
|
||||||
Change GtkCalendarDetailFunc to return newly allocated string. (#339540)
|
Change GtkCalendarDetailFunc to return newly allocated string. (#339540)
|
||||||
|
|||||||
@ -82,6 +82,17 @@ def get_property(node, property_name):
|
|||||||
properties = get_properties(node)
|
properties = get_properties(node)
|
||||||
return properties.get(property_name)
|
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):
|
def get_signal_nodes(node):
|
||||||
assert node.tagName == 'object'
|
assert node.tagName == 'object'
|
||||||
signals = []
|
signals = []
|
||||||
@ -126,9 +137,11 @@ def get_object_node(child_node):
|
|||||||
def copy_properties(node, props, prop_dict):
|
def copy_properties(node, props, prop_dict):
|
||||||
assert node.tagName == 'object'
|
assert node.tagName == 'object'
|
||||||
for prop_name in props:
|
for prop_name in props:
|
||||||
value = get_property(node, prop_name)
|
child = get_property_node(node, prop_name)
|
||||||
if value is not None:
|
if child is not None:
|
||||||
prop_dict[prop_name] = value
|
prop_dict[prop_name] = child
|
||||||
|
|
||||||
|
return node
|
||||||
|
|
||||||
class GtkBuilderConverter(object):
|
class GtkBuilderConverter(object):
|
||||||
|
|
||||||
@ -166,6 +179,21 @@ class GtkBuilderConverter(object):
|
|||||||
if w.getAttribute(attribute) == value]
|
if w.getAttribute(attribute) == value]
|
||||||
|
|
||||||
def _create_object(self, obj_class, obj_id, template=None, **properties):
|
def _create_object(self, obj_class, obj_id, template=None, **properties):
|
||||||
|
"""
|
||||||
|
Creates a new <object> 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:
|
if template is not None:
|
||||||
count = 1
|
count = 1
|
||||||
while True:
|
while True:
|
||||||
@ -180,9 +208,15 @@ class GtkBuilderConverter(object):
|
|||||||
obj.setAttribute('class', obj_class)
|
obj.setAttribute('class', obj_class)
|
||||||
obj.setAttribute('id', obj_id)
|
obj.setAttribute('id', obj_id)
|
||||||
for name, value in properties.items():
|
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.setAttribute('name', name)
|
||||||
prop.appendChild(self._dom.createTextNode(value))
|
|
||||||
obj.appendChild(prop)
|
obj.appendChild(prop)
|
||||||
self.objects[obj_id] = obj
|
self.objects[obj_id] = obj
|
||||||
return obj
|
return obj
|
||||||
@ -371,18 +405,18 @@ class GtkBuilderConverter(object):
|
|||||||
if (children and
|
if (children and
|
||||||
children[0].getAttribute('internal-child') == 'image'):
|
children[0].getAttribute('internal-child') == 'image'):
|
||||||
image = get_object_node(children[0])
|
image = get_object_node(children[0])
|
||||||
stock_id = get_property(image, 'stock')
|
child = get_property_node(image, 'stock')
|
||||||
if stock_id is not None:
|
if child is not None:
|
||||||
properties['stock_id'] = stock_id
|
properties['stock_id'] = child
|
||||||
elif object_class == 'GtkSeparatorMenuItem':
|
elif object_class == 'GtkSeparatorMenuItem':
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(object_class)
|
raise NotImplementedError(object_class)
|
||||||
|
|
||||||
if get_property(node, 'use_stock') == 'True':
|
if get_property(node, 'use_stock') == 'True':
|
||||||
stock_id = get_property(node, 'label')
|
child = get_property_node(node, 'label')
|
||||||
if stock_id is not None:
|
if child:
|
||||||
properties['stock_id'] = stock_id
|
properties['stock_id'] = child
|
||||||
|
|
||||||
properties['name'] = object_id
|
properties['name'] = object_id
|
||||||
action = self._create_object(name,
|
action = self._create_object(name,
|
||||||
|
|||||||
Reference in New Issue
Block a user