Tool to convert .Glade (or xml) file to C source

I am looking for a tool that can convert a .Glade (or xml) file to source C.
I have tried g2c (Glade To C Translator), but I am looking for Windows binaries.

Anyone knows any good window tool.

Thanks,
PP.

+3
source share
3 answers

glade2 works for me. though, if you use the new glade3 features, this will not help you.

+4
source

You do not need a tool. Just write a script in your favorite scripting language to format your glade file as a string literal C:

, glade_file.c:

const gchar *my_glade_file = 
    "<interface>"
        "<object class=\"GtkDialog\">"
            "<et-cetera />"
        "</object>"
    "</interface>";

glade_file.c , :

extern const gchar *my_glade_file;
result = gtk_builder_add_from_string(builder, my_glade_file, -1, &error);
+5

I needed to write a small python script to help others:

import xml.dom.minidom
class XmlWriter:
    def __init__(self):
        self.snippets = []
    def write(self, data):
        if data.isspace(): return
        self.snippets.append(data)
    def __str__(self):
        return ''.join(self.snippets)

if __name__ == "__main__":
    writer = XmlWriter()
    xml = xml.dom.minidom.parse("example.glade")
    xml.writexml(writer)
    strippedXml = ("%s" % (writer)).replace('"', '\\"')

    byteCount = len(strippedXml)
    baseOffset=0
    stripSize=64

    output = open("example.h", 'w')
    output.write("static const char gladestring [] = \n{\n")
    while baseOffset < byteCount:
        skipTrailingQuote = 0
        if baseOffset+stripSize < byteCount and strippedXml[baseOffset+stripSize] == '"':
            skipTrailingQuote = 1
        output.write('  "%s"\n' % (strippedXml[baseOffset:baseOffset+stripSize+skipTrailingQuote]))
        baseOffset += stripSize + skipTrailingQuote

    output.write("};\n")
    output.close()
+1
source

Source: https://habr.com/ru/post/1744470/


All Articles