#!/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 <henrique@async.com.br>
-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
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:
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
# 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):
return
if (node.tagName == 'object' and
- node.getAttribute('class') == 'GtkDialog'):
+ node.getAttribute('class') in DIALOGS):
dialog = node
break
node = node.parentNode
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")
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)