1.1 --- a/XSLForms/Prepare.py Mon Jun 22 21:45:16 2009 +0200
1.2 +++ b/XSLForms/Prepare.py Mon Jun 22 23:33:43 2009 +0200
1.3 @@ -1,9 +1,9 @@
1.4 #!/usr/bin/env python
1.5
1.6 """
1.7 -Preparation of templating stylesheets.
1.8 +Preparation of templating stylesheets and related resources.
1.9
1.10 -Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.11 +Copyright (C) 2005, 2006, 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk>
1.12
1.13 This program is free software; you can redistribute it and/or modify it under
1.14 the terms of the GNU Lesser General Public License as published by the Free
1.15 @@ -138,42 +138,15 @@
1.16
1.17 _make_document(template_name, output_name, stylesheet_names, encoding)
1.18
1.19 -# Qt Designer functions.
1.20 +# Translation-related functions.
1.21
1.22 -def make_qt_fragment(template_name, output_name, widget_name, stylesheet_names=["QtDesignerExtract.xsl"], encoding=None):
1.23 - _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"widget-name" : widget_name})
1.24 -
1.25 -def ensure_qt_fragment(template_name, output_name, widget_name):
1.26 - _ensure_document(template_name, output_name, make_qt_fragment, widget_name)
1.27 +def find_translation_keys(template_name, output_name, stylesheet_names=["FindTranslationKeys.xsl"], encoding=None):
1.28
1.29 -# Qt Designer Web functions.
1.30 -
1.31 -def make_qt_template(template_name, output_name, stylesheet_names=["QtDesigner.xsl"], encoding=None):
1.32 - _make_document(template_name, output_name, stylesheet_names, encoding)
1.33 + """
1.34 + Find translation keys in the document identified by 'template_name',
1.35 + producing a translations document with the given 'output_name'.
1.36 + """
1.37
1.38 -def ensure_qt_template(template_name, output_name):
1.39 - _ensure_document(template_name, output_name, make_qt_template)
1.40 -
1.41 -def make_qt_stylesheet(template_name, output_name, stylesheet_names=["QtDesigner.xsl", "PrepareMacro.xsl", "Prepare.xsl"], encoding=None):
1.42 _make_document(template_name, output_name, stylesheet_names, encoding)
1.43
1.44 -def ensure_qt_stylesheet(template_name, output_name):
1.45 - _ensure_document(template_name, output_name, make_qt_stylesheet)
1.46 -
1.47 -# Qt Designer Web functions for fragments.
1.48 -
1.49 -def make_qt_template_fragment(template_name, output_name, widget_name, stylesheet_names=["QtDesignerExtract.xsl", "QtDesigner.xsl"], encoding=None):
1.50 - _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"widget-name" : widget_name})
1.51 -
1.52 -def ensure_qt_template_fragment(template_name, output_name, widget_name):
1.53 - _ensure_document(template_name, output_name, make_qt_template_fragment, widget_name)
1.54 -
1.55 -def make_qt_stylesheet_fragment(template_name, output_name, widget_name,
1.56 - stylesheet_names=["QtDesignerExtract.xsl", "QtDesigner.xsl", "PrepareMacro.xsl", "Prepare.xsl"], encoding=None):
1.57 -
1.58 - _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"widget-name" : widget_name})
1.59 -
1.60 -def ensure_qt_stylesheet_fragment(template_name, output_name, widget_name):
1.61 - _ensure_document(template_name, output_name, make_qt_stylesheet_fragment, widget_name)
1.62 -
1.63 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/XSLForms/XSL/QtDesigner.xsl Mon Jun 22 21:45:16 2009 +0200
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,373 +0,0 @@
3.4 -<?xml version="1.0"?>
3.5 -<!--
3.6 -An experimental Qt Designer form conversion stylesheet.
3.7 -
3.8 -Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
3.9 -
3.10 -This program is free software; you can redistribute it and/or modify it under
3.11 -the terms of the GNU Lesser General Public License as published by the Free
3.12 -Software Foundation; either version 3 of the License, or (at your option) any
3.13 -later version.
3.14 -
3.15 -This program is distributed in the hope that it will be useful, but WITHOUT
3.16 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.17 -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
3.18 -details.
3.19 -
3.20 -You should have received a copy of the GNU Lesser General Public License along
3.21 -with this program. If not, see <http://www.gnu.org/licenses/>.
3.22 --->
3.23 -<xsl:stylesheet version="1.0"
3.24 - xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3.25 - xmlns:set="http://exslt.org/sets"
3.26 - xmlns:math="http://exslt.org/math"
3.27 - xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
3.28 -
3.29 - <xsl:output indent="yes"/>
3.30 -
3.31 -
3.32 -
3.33 - <!-- Start at the top, producing a template file. -->
3.34 -
3.35 - <xsl:template match="UI">
3.36 - <html xmlns="http://www.w3.org/1999/xhtml">
3.37 - <head>
3.38 - <title><xsl:value-of select="widget/property[@name='caption']/string/text()"/></title>
3.39 - <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles/styles.css" rel="stylesheet" type="text/css" />
3.40 - <script type="text/javascript" src="scripts/sarissa.js"> </script>
3.41 - <script type="text/javascript" src="scripts/XSLForms.js"> </script>
3.42 - </head>
3.43 - <body>
3.44 - <form method="post">
3.45 - <xsl:apply-templates select="widget"/>
3.46 - </form>
3.47 - </body>
3.48 - </html>
3.49 - </xsl:template>
3.50 -
3.51 -
3.52 -
3.53 - <!-- Reproduce the layout. -->
3.54 -
3.55 - <xsl:template match="grid">
3.56 - <xsl:variable name="grid" select="."/>
3.57 - <table xmlns="http://www.w3.org/1999/xhtml" width="100%">
3.58 - <!-- Get the row numbers in ascending order. -->
3.59 - <xsl:for-each select="set:distinct($grid/*/@row)">
3.60 - <xsl:sort select="." data-type="number" order="ascending"/>
3.61 - <xsl:variable name="row" select="."/>
3.62 - <tr>
3.63 - <!-- Get all elements in the row, ordered by column number. -->
3.64 - <xsl:call-template name="grid-column">
3.65 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row]/@column)"/>
3.66 - <xsl:with-param name="row" select="$row"/>
3.67 - <xsl:with-param name="grid" select="$grid"/>
3.68 - <xsl:with-param name="last-column">-1</xsl:with-param>
3.69 - </xsl:call-template>
3.70 - </tr>
3.71 - </xsl:for-each>
3.72 - </table>
3.73 - </xsl:template>
3.74 -
3.75 - <xsl:template name="grid-column">
3.76 - <xsl:param name="column"/>
3.77 - <xsl:param name="row"/>
3.78 - <xsl:param name="grid"/>
3.79 - <xsl:param name="last-column"/>
3.80 - <xsl:param name="last-colspan">1</xsl:param>
3.81 - <!-- Insert missing cells. -->
3.82 - <xsl:if test="$column != $last-column + $last-colspan">
3.83 - <xsl:variable name="spanned-columns" select="$grid/*[$row > @row and @row + @rowspan > $row and @column > $last-column and $column > @column]/@column"/>
3.84 - <xsl:choose>
3.85 - <xsl:when test="count($spanned-columns) != 0">
3.86 - <xsl:variable name="last-spanned-column" select="math:highest($spanned-columns)"/>
3.87 - <xsl:variable name="last-spanned-colspan" select="$last-spanned-column/../@colspan"/>
3.88 - <xsl:if test="$column != $last-spanned-column + $last-spanned-colspan">
3.89 - <td colspan="{$column - $last-spanned-column - $last-spanned-colspan}" xmlns="http://www.w3.org/1999/xhtml">
3.90 - </td>
3.91 - </xsl:if>
3.92 - </xsl:when>
3.93 - <xsl:otherwise>
3.94 - <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml">
3.95 - </td>
3.96 - </xsl:otherwise>
3.97 - </xsl:choose>
3.98 - </xsl:if>
3.99 - <!-- Remember useful information. -->
3.100 - <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/>
3.101 - <xsl:variable name="this-colspan" select="$this-column/@colspan"/>
3.102 - <!-- Insert this cell. -->
3.103 - <td xmlns="http://www.w3.org/1999/xhtml">
3.104 - <!-- Add colspan and rowspan details. -->
3.105 - <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/>
3.106 - <!-- Transform the element. -->
3.107 - <xsl:apply-templates select="$this-column"/>
3.108 - </td>
3.109 - <!-- Find remaining cells in this row. -->
3.110 - <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0">
3.111 - <xsl:choose>
3.112 - <xsl:when test="$this-colspan">
3.113 - <xsl:call-template name="grid-column">
3.114 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/>
3.115 - <xsl:with-param name="row" select="$row"/>
3.116 - <xsl:with-param name="grid" select="$grid"/>
3.117 - <xsl:with-param name="last-column" select="$column"/>
3.118 - <xsl:with-param name="last-colspan" select="$this-colspan"/>
3.119 - </xsl:call-template>
3.120 - </xsl:when>
3.121 - <xsl:otherwise>
3.122 - <xsl:call-template name="grid-column">
3.123 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/>
3.124 - <xsl:with-param name="row" select="$row"/>
3.125 - <xsl:with-param name="grid" select="$grid"/>
3.126 - <xsl:with-param name="last-column" select="$column"/>
3.127 - </xsl:call-template>
3.128 - </xsl:otherwise>
3.129 - </xsl:choose>
3.130 - </xsl:if>
3.131 - </xsl:template>
3.132 -
3.133 - <xsl:template match="spacer">
3.134 - </xsl:template>
3.135 -
3.136 - <xsl:template match="vbox">
3.137 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.138 - </xsl:template>
3.139 -
3.140 - <xsl:template match="hbox">
3.141 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.142 - </xsl:template>
3.143 -
3.144 - <xsl:template match="widget">
3.145 - <xsl:apply-templates select="property[@name='geometry']"/>
3.146 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.147 - </xsl:template>
3.148 -
3.149 - <!-- Container widgets. -->
3.150 -
3.151 - <xsl:template match="widget[@class='QFrame']">
3.152 - <div xmlns="http://www.w3.org/1999/xhtml">
3.153 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.154 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.155 - <xsl:apply-templates select="property[@name='geometry']"/>
3.156 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.157 - </div>
3.158 - </xsl:template>
3.159 -
3.160 - <xsl:template match="widget[@class='QTabWidget']">
3.161 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.162 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.163 - <xsl:apply-templates select="property[@name='geometry']"/>
3.164 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.165 - </xsl:template>
3.166 -
3.167 - <xsl:template match="widget[@class='QWidgetStack']">
3.168 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.169 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.170 - <xsl:apply-templates select="property[@name='geometry']"/>
3.171 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
3.172 - </xsl:template>
3.173 -
3.174 - <xsl:template match="widget[@class='QWidget']">
3.175 - <!-- NOTE: Suppress overriding of names. -->
3.176 - <xsl:if test="not(../@class) or ../@class != 'QTabWidget'">
3.177 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.178 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.179 - </xsl:if>
3.180 - <xsl:apply-templates select="property[@name='geometry']"/>
3.181 - <xsl:apply-templates select="*[not(local-name() = 'property') and not(local-name() = 'attribute')]"/>
3.182 - </xsl:template>
3.183 -
3.184 - <!-- Specific widgets. -->
3.185 -
3.186 - <xsl:template match="widget[@class='QComboBox']">
3.187 - <select xmlns="http://www.w3.org/1999/xhtml">
3.188 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.189 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
3.190 - <!-- NOTE: Adding _enum suffix. -->
3.191 - <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/>
3.192 - <xsl:attribute name="template:multiple-choice-field"><xsl:value-of select="$field-name"/>,value</xsl:attribute>
3.193 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
3.194 - <xsl:apply-templates select="item">
3.195 - <xsl:with-param name="enum-name" select="$enum-name"/>
3.196 - </xsl:apply-templates>
3.197 - </select>
3.198 - </xsl:template>
3.199 -
3.200 - <xsl:template match="widget[@class='QListBox']">
3.201 - <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple">
3.202 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.203 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
3.204 - <!-- NOTE: Adding _enum suffix. -->
3.205 - <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/>
3.206 - <xsl:attribute name="template:multiple-choice-list-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$enum-name"/></xsl:attribute>
3.207 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
3.208 - <xsl:apply-templates select="item">
3.209 - <xsl:with-param name="enum-name" select="$enum-name"/>
3.210 - <xsl:with-param name="item-type">list</xsl:with-param>
3.211 - </xsl:apply-templates>
3.212 - </select>
3.213 - </xsl:template>
3.214 -
3.215 - <xsl:template match="item">
3.216 - <xsl:param name="enum-name"/>
3.217 - <xsl:param name="item-type"/>
3.218 - <option xmlns="http://www.w3.org/1999/xhtml">
3.219 - <xsl:choose>
3.220 - <xsl:when test="$item-type = 'list'">
3.221 - <xsl:attribute name="template:multiple-choice-list-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute>
3.222 - </xsl:when>
3.223 - <xsl:otherwise>
3.224 - <xsl:attribute name="template:multiple-choice-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute>
3.225 - </xsl:otherwise>
3.226 - </xsl:choose>
3.227 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.228 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
3.229 - <xsl:value-of select="$value-prop/string/text()"/>
3.230 - </option>
3.231 - </xsl:template>
3.232 -
3.233 - <xsl:template match="widget[@class='QLabel']">
3.234 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.235 - <!-- NOTE: Permitting element generation from the text. -->
3.236 - <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/>
3.237 - </xsl:template>
3.238 -
3.239 - <xsl:template match="widget[@class='QPushButton']">
3.240 - <input xmlns="http://www.w3.org/1999/xhtml" type="submit">
3.241 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.242 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
3.243 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.244 - <xsl:choose>
3.245 - <xsl:when test="starts-with($field-name, 'add_')">
3.246 - <xsl:variable name="affected-element" select="substring-after($field-name, 'add_')"/>
3.247 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute>
3.248 - </xsl:when>
3.249 - <xsl:when test="starts-with($field-name, 'remove_')">
3.250 - <xsl:variable name="affected-element" select="substring-after($field-name, 'remove_')"/>
3.251 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute>
3.252 - </xsl:when>
3.253 - <xsl:otherwise>
3.254 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/></xsl:attribute>
3.255 - </xsl:otherwise>
3.256 - </xsl:choose>
3.257 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
3.258 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
3.259 - </input>
3.260 - </xsl:template>
3.261 -
3.262 - <xsl:template match="widget[@class='QLineEdit']">
3.263 - <input xmlns="http://www.w3.org/1999/xhtml" type="text">
3.264 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.265 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.266 - <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.267 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.268 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
3.269 - </input>
3.270 - </xsl:template>
3.271 -
3.272 - <xsl:template match="widget[@class='QTextEdit']">
3.273 - <textarea xmlns="http://www.w3.org/1999/xhtml">
3.274 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.275 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.276 - <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.277 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.278 - <xsl:value-of select="$value-prop/string/text()"/>
3.279 - </textarea>
3.280 - </xsl:template>
3.281 -
3.282 - <xsl:template match="widget[@class='QRadioButton']">
3.283 - <input xmlns="http://www.w3.org/1999/xhtml" type="radio">
3.284 - <xsl:variable name="name-prop" select="property[@name='name']"/>
3.285 - <xsl:variable name="value-prop" select="property[@name='text']"/>
3.286 - <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.287 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
3.288 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
3.289 - </input>
3.290 - </xsl:template>
3.291 -
3.292 -
3.293 -
3.294 - <!-- Geometry. -->
3.295 -
3.296 - <xsl:template match="property[@name='geometry']">
3.297 - <xsl:apply-templates select="rect/*[1]">
3.298 - <xsl:with-param name="style">position: absolute</xsl:with-param>
3.299 - </xsl:apply-templates>
3.300 - </xsl:template>
3.301 -
3.302 - <xsl:template name="make-geometry">
3.303 - <xsl:param name="style"/>
3.304 - <xsl:variable name="dimension" select="following-sibling::*[1]"/>
3.305 - <xsl:choose>
3.306 - <xsl:when test="not($dimension)">
3.307 - <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute>
3.308 - </xsl:when>
3.309 - <xsl:otherwise>
3.310 - <xsl:apply-templates select="$dimension">
3.311 - <xsl:with-param name="style" select="$style"/>
3.312 - </xsl:apply-templates>
3.313 - </xsl:otherwise>
3.314 - </xsl:choose>
3.315 - </xsl:template>
3.316 -
3.317 - <xsl:template match="x">
3.318 - <xsl:param name="style"/>
3.319 - <xsl:call-template name="make-geometry">
3.320 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param>
3.321 - </xsl:call-template>
3.322 - </xsl:template>
3.323 -
3.324 - <xsl:template match="y">
3.325 - <xsl:param name="style"/>
3.326 - <xsl:call-template name="make-geometry">
3.327 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param>
3.328 - </xsl:call-template>
3.329 - </xsl:template>
3.330 -
3.331 - <xsl:template match="width">
3.332 - <xsl:param name="style"/>
3.333 - <xsl:call-template name="make-geometry">
3.334 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param>
3.335 - </xsl:call-template>
3.336 - </xsl:template>
3.337 -
3.338 - <xsl:template match="height">
3.339 - <xsl:param name="style"/>
3.340 - <xsl:call-template name="make-geometry">
3.341 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param>
3.342 - </xsl:call-template>
3.343 - </xsl:template>
3.344 -
3.345 -
3.346 -
3.347 - <!-- Identification. -->
3.348 -
3.349 - <xsl:template match="property[@name='name']">
3.350 - </xsl:template>
3.351 -
3.352 -
3.353 -
3.354 - <!-- Labels and values. -->
3.355 -
3.356 - <xsl:template match="property[@name='text']">
3.357 - </xsl:template>
3.358 -
3.359 -
3.360 -
3.361 - <!-- Captions. -->
3.362 -
3.363 - <xsl:template match="property[@name='caption']">
3.364 - </xsl:template>
3.365 -
3.366 -
3.367 -
3.368 - <!-- Copy attributes. -->
3.369 -
3.370 - <xsl:template match="@*">
3.371 - <xsl:copy>
3.372 - <xsl:apply-templates select="node()"/>
3.373 - </xsl:copy>
3.374 - </xsl:template>
3.375 -
3.376 -</xsl:stylesheet>