From 3865397b582d93924ded432055a07c31543363d4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 4 Oct 2009 20:27:30 -0700 Subject: [PATCH] Upgrade gtk-builder-convert to newer version that adds useful warnings. The notes on "Migrating from libglade to GtkBuilder" in the GTK+ Reference Manual at, e.g. http://library.gnome.org/devel/gtk/unstable/gtk-migrating-GtkBuilder.html say that "While libglade can often tolerate multiple widgets having the same id in a glade file, GtkBuilder will not accept duplicate object ids." The version of gtk-builder-convert that we had previously didn't warn about duplicate ids; the new version checked in by this commit does. --- lib/gtk-contrib/gtk-builder-convert | 46 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/gtk-contrib/gtk-builder-convert b/lib/gtk-contrib/gtk-builder-convert index bfcb03c9..35b49166 100755 --- a/lib/gtk-contrib/gtk-builder-convert +++ b/lib/gtk-contrib/gtk-builder-convert @@ -1,8 +1,8 @@ #!/usr/bin/env python -# # This file was downloaded from -# http://svn.gnome.org/svn/gtk+/tags/GTK_2_14_7/gtk/gtk-builder-convert -# on 11 March 2009 +# http://git.gnome.org/cgit/gtk+/plain/gtk/gtk-builder-convert +# on 4 Oct 2009 +# # # Copyright (C) 2006-2008 Async Open Source # Henrique Romano @@ -33,7 +33,7 @@ The [INPUT] file is -r, --root Convert only widget named root and its children -h, --help display this help and exit -When OUTPUT is -, write to standard input. +When OUTPUT is -, write to standard output. Examples: gtk-builder-convert preference.glade preferences.ui @@ -46,10 +46,10 @@ import sys from xml.dom import minidom, Node -WINDOWS = ['GtkWindow', - 'GtkDialog', +DIALOGS = ['GtkDialog', 'GtkFileChooserDialog', 'GtkMessageDialog'] +WINDOWS = ['GtkWindow'] + DIALOGS # The subprocess is only available in Python 2.4+ try: @@ -261,6 +261,8 @@ class GtkBuilderConverter(object): for node in objects: self._convert(node.getAttribute("class"), node) + if self._get_object(node.getAttribute('id')) is not None: + print "WARNING: duplicate id \"" + node.getAttribute('id') + "\"" self.objects[node.getAttribute('id')] = node # Convert Gazpachos UI tag @@ -273,9 +275,14 @@ class GtkBuilderConverter(object): # Output the newly created root objects and sort them # by attribute id - for obj in sorted(self.root_objects, - key=lambda n: n.getAttribute('id'), - reverse=True): + # FIXME: Use sorted(self.root_objects, + # key=lambda n: n.getAttribute('id'), + # reverse=True): + # when we can depend on python 2.4 or higher + root_objects = self.root_objects[:] + root_objects.sort(lambda a, b: cmp(b.getAttribute('id'), + a.getAttribute('id'))) + for obj in root_objects: self._interface.childNodes.insert(0, obj) def _convert(self, klass, node): @@ -496,7 +503,7 @@ class GtkBuilderConverter(object): return if (node.tagName == 'object' and - node.getAttribute('class') == 'GtkDialog'): + node.getAttribute('class') in DIALOGS): dialog = node break node = node.parentNode @@ -543,6 +550,14 @@ class GtkBuilderConverter(object): if not prop.childNodes: parent.removeChild(prop) return + + translatable_attr = prop.attributes.get('translatable') + translatable = translatable_attr is not None and translatable_attr.value == 'yes' + has_context_attr = prop.attributes.get('context') + has_context = has_context_attr is not None and has_context_attr.value == 'yes' + comments_attr = prop.attributes.get('comments') + comments = comments_attr is not None and comments_attr.value or None + value = prop.childNodes[0].data model = self._create_root_object("GtkListStore", template="model") @@ -557,12 +572,23 @@ class GtkBuilderConverter(object): data = self._dom.createElement('data') model.appendChild(data) + if value.endswith('\n'): + value = value[:-1] for item in value.split('\n'): row = self._dom.createElement('row') data.appendChild(row) col = self._dom.createElement('col') col.setAttribute('id', '0') + if translatable: + col.setAttribute('translatable', 'yes') + if has_context: + splitting = item.split('|', 1) + if len(splitting) == 2: + context, item = splitting + col.setAttribute('context', context) + if comments is not None: + col.setAttribute('comments', comments) col.appendChild(self._dom.createTextNode(item)) row.appendChild(col) -- 2.30.2