diff options
author | Johan Dahlin <jdahlin@async.com.br> | 2007-07-08 14:33:20 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2007-07-08 14:33:20 +0000 |
commit | 36fda88e844aba1286a6278bf51b59bac3745f78 (patch) | |
tree | 5309da0e0f09a5eca58ab82ff8a92c320a0f5869 /gtk/gtk-builder-convert | |
parent | a318353ac3b6aa0eb586c59272ace6c54c48834b (diff) | |
download | gdk-pixbuf-36fda88e844aba1286a6278bf51b59bac3745f78.tar.gz |
Improve the way properties are copied over from a menuitem to an action.
2007-07-08 Johan Dahlin <jdahlin@async.com.br>
* gtk/gtk-builder-convert: Improve the way properties
are copied over from a menuitem to an action.
svn path=/trunk/; revision=18404
Diffstat (limited to 'gtk/gtk-builder-convert')
-rwxr-xr-x | gtk/gtk-builder-convert | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/gtk/gtk-builder-convert b/gtk/gtk-builder-convert index a08e8a8ec..d77f8c3d1 100755 --- a/gtk/gtk-builder-convert +++ b/gtk/gtk-builder-convert @@ -103,6 +103,12 @@ def get_object_node(child_node): assert len(nodes) == 1, nodes return nodes[0] +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 class GtkBuilderConverter(object): @@ -287,6 +293,9 @@ class GtkBuilderConverter(object): if node.hasAttribute('constructor'): return + # Only convert toplevel menu objects + if node.parentNode != self._interface: + return uimgr = self._create_root_object('GtkUIManager', template='uimanager') @@ -320,14 +329,14 @@ class GtkBuilderConverter(object): object_class = obj_node.getAttribute('class') if object_class in ['GtkMenuItem', 'GtkImageMenuItem', - 'GtkCheckMenuItem']: + 'GtkCheckMenuItem', + 'GtkRadioMenuItem']: menu = self._dom.createElement(name) elif object_class == 'GtkSeparatorMenuItem': return self._dom.createElement('separator') else: raise NotImplementedError(object_class) - menu.setAttribute('name', obj_node.getAttribute('id')) menu.setAttribute('action', obj_node.getAttribute('id')) self._add_action_from_menuitem(uimgr, obj_node) if children: @@ -339,11 +348,31 @@ class GtkBuilderConverter(object): child.parentNode.removeChild(child) return menu + def _menuitem_to_action(self, node, properties): + copy_properties(node, ['label'], properties) + + def _togglemenuitem_to_action(self, node, properties): + self._menuitem_to_action(node, properties) + copy_properties(node, ['active'], properties) + + def _radiomenuitem_to_action(self, node, properties): + self._togglemenuitem_to_action(node, properties) + copy_properties(node, ['group'], properties) + def _add_action_from_menuitem(self, uimgr, node): properties = {} object_class = node.getAttribute('class') object_id = node.getAttribute('id') - if object_class == 'GtkImageMenuItem': + if object_class == 'GtkMenuItem': + name = 'GtkAction' + self._menuitem_to_action(node, properties) + elif object_class == 'GtkCheckMenuItem': + name = 'GtkToggleAction' + self._togglemenuitem_to_action(node, properties) + elif object_class == 'GtkRadioMenuItem': + name = 'GtkRadioAction' + self._radiomenuitem_to_action(node, properties) + elif object_class == 'GtkImageMenuItem': name = 'GtkAction' children = get_child_nodes(node) if (children and @@ -352,21 +381,8 @@ class GtkBuilderConverter(object): stock_id = get_property(image, 'stock') if stock_id is not None: properties['stock_id'] = stock_id - elif object_class == 'GtkMenuItem': - name = 'GtkAction' - label = get_property(node, 'label') - if label is not None: - properties['label'] = label elif object_class == 'GtkSeparatorMenuItem': return - elif object_class == 'GtkCheckMenuItem': - name = 'GtkToggleAction' - label = get_property(node, 'label') - if label is not None: - properties['label'] = label - active = get_property(node, 'active') - if active is not None: - properties['active'] = active else: raise NotImplementedError(object_class) |