grim/gir2glade

initial revision
draft
2018-05-08, Gary Kramlich
364e1cb95e3f
Parents
Children 66a42ebdec52
initial revision
  • +22 -0
    README.md
  • +90 -0
    gir2glade.xls
  • --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/README.md Tue May 08 01:11:12 2018 -0500
    @@ -0,0 +1,22 @@
    +# gir2glade
    +
    +gir2glade is an XSL Transform for creating a [glade](https://glade.gnome.org)
    +catalog from a [gobject-introspection](200~https://wiki.gnome.org/action/show/Projects/GObjectIntrospection?action=show&redirect=GObjectIntrospection)
    +gir file.
    +
    +It can be used on any gir file with any XSLT processor.
    +
    +The following will create the glade catalog and output it to stdout.
    +
    +```
    +xsltproc gir2glade.xsl GtkIM-0.0.gir
    +```
    +
    +You can save it to a file with
    +
    +```
    +xsltproc gir2glade.xsl GtkIM-0.0.gir > gtkim.xml
    +```
    +
    +Then add the path you wrote it to to glade's catalog search path and you're set!
    +
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/gir2glade.xls Tue May 08 01:11:12 2018 -0500
    @@ -0,0 +1,90 @@
    +<?xml version="1.0" encoding="utf-8"?>
    +<xsl:stylesheet version="1.0"
    + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    + xmlns:gir="http://www.gtk.org/introspection/core/1.0"
    + xmlns:c="http://www.gtk.org/introspection/c/1.0"
    + xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
    +
    + <xsl:output method="xml" encoding="UTF-8" indent="yes" version="1.0"/>
    +
    + <xsl:strip-space elements="*"/>
    +
    + <xsl:template name="library-name">
    + <xsl:param name="lib"></xsl:param>
    +
    + <xsl:variable name="split">
    + <xsl:value-of select="substring-after($lib, 'lib')"/>
    + </xsl:variable>
    +
    + <xsl:choose>
    + <xsl:when test="contains($split, '.so')">
    + <xsl:value-of select="substring-before($split, '.so')"/>
    + </xsl:when>
    + <xsl:otherwise>
    + <xsl:text>unsupported</xsl:text>
    + </xsl:otherwise>
    + </xsl:choose>
    + </xsl:template>
    +
    + <xsl:template match="gir:repository">
    + <xsl:element name="glade-catalog">
    + <xsl:apply-templates/>
    + </xsl:element>
    + </xsl:template>
    +
    + <xsl:template match="gir:namespace">
    + <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
    + <xsl:attribute name="version"><xsl:value-of select="@version"/></xsl:attribute>
    +
    + <!-- clean up the library name -->
    + <xsl:attribute name="library">
    + <xsl:call-template name="library-name">
    + <xsl:with-param name="lib"><xsl:value-of select="@shared-library"/></xsl:with-param>
    + </xsl:call-template>
    + </xsl:attribute>
    +
    + <!-- add each widget class if it's implements Gtk.Buildable -->
    + <xsl:element name="glade-widget-classes">
    + <xsl:for-each select="gir:class">
    + <xsl:call-template name="class"/>
    + </xsl:for-each>
    + </xsl:element>
    +
    + <!-- add a referench for each widget class to the widget group if it implement Gtk.Buildable -->
    + <xsl:element name="glade-widget-group">
    + <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
    + <xsl:attribute name="title"><xsl:value-of select="@name"/></xsl:attribute>
    +
    + <xsl:for-each select="gir:class">
    + <xsl:call-template name="class-group"/>
    + </xsl:for-each>
    + </xsl:element>
    + </xsl:template>
    +
    + <xsl:template name="class">
    + <xsl:if test="gir:implements[@name='Gtk.Buildable']">
    + <xsl:element name="glade-widget-class">
    + <xsl:attribute name="name"><xsl:value-of select="@c:type"/></xsl:attribute>
    + <xsl:attribute name="generic-name"><xsl:value-of select="@c:symbol-prefix"/></xsl:attribute>
    + <xsl:attribute name="title"><xsl:value-of select="@name"/></xsl:attribute>
    + <xsl:attribute name="get-type-function"><xsl:value-of select="@glib:get-type"/></xsl:attribute>
    +
    + <xsl:if test="property">
    + <xsl:element name="properties">
    + <xsl:for-each select="property">
    + <xsl:attribute name="id"><xsl:value-of select="@name"/></xsl:attribute>
    + </xsl:for-each>
    + </xsl:element>
    + </xsl:if>
    + </xsl:element>
    + </xsl:if>
    + </xsl:template>
    +
    + <xsl:template name="class-group">
    + <xsl:if test="gir:implements[@name='Gtk.Buildable']">
    + <xsl:element name="glade-widget-class-ref">
    + <xsl:attribute name="name"><xsl:value-of select="@c:type"/></xsl:attribute>
    + </xsl:element>
    + </xsl:if>
    + </xsl:template>
    +</xsl:stylesheet>