# HG changeset patch # User Edouard Tisserant <edouard.tisserant@gmail.com> # Date 1619991837 -7200 # Node ID f2bfb047d0e6c776ee06554c398ddfa7c4f6f77c # Parent 315f17e74ef5f5150b471b6760e32921f0221a91 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages diff -r 315f17e74ef5 -r f2bfb047d0e6 svghmi/gen_dnd_widget_svg.xslt --- a/svghmi/gen_dnd_widget_svg.xslt Sun May 02 23:15:23 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.xslt Sun May 02 23:43:57 2021 +0200 @@ -1,11 +1,11 @@ <?xml version="1.0"?> -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn"> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn"> <xsl:output method="xml"/> <xsl:param name="hmi_path"/> - <xsl:variable name="svg" select="/svg:svg"/> <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/> <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/> <xsl:variable name="indexed_hmitree" select="/.."/> + <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"/> <xsl:template mode="parselabel" match="*"> <xsl:variable name="label" select="@inkscape:label"/> <xsl:variable name="id" select="@id"/> @@ -51,22 +51,29 @@ <xsl:for-each select="str:split($paths, '@')"> <xsl:if test="string-length(.) > 0"> <path> - <xsl:variable name="pathminmax" select="str:split(.,',')"/> - <xsl:variable name="path" select="$pathminmax[1]"/> + <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/> + <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/> + <xsl:variable name="path" select="$path_match[2]"/> + <xsl:variable name="path_accepts" select="$path_match[3]"/> <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/> <xsl:attribute name="value"> <xsl:value-of select="$path"/> </xsl:attribute> + <xsl:if test="string-length($path_accepts)"> + <xsl:attribute name="accepts"> + <xsl:value-of select="$path_accepts"/> + </xsl:attribute> + </xsl:if> <xsl:choose> - <xsl:when test="$pathminmaxcount = 3"> + <xsl:when test="$pathminmaxcount = 2"> <xsl:attribute name="min"> + <xsl:value-of select="$pathminmax[1]"/> + </xsl:attribute> + <xsl:attribute name="max"> <xsl:value-of select="$pathminmax[2]"/> </xsl:attribute> - <xsl:attribute name="max"> - <xsl:value-of select="$pathminmax[3]"/> - </xsl:attribute> </xsl:when> - <xsl:when test="$pathminmaxcount = 2"> + <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount > 2"> <xsl:message terminate="yes"> <xsl:text>Widget id:</xsl:text> <xsl:value-of select="$id"/> @@ -128,9 +135,9 @@ <xsl:text>@</xsl:text> <xsl:value-of select="@value"/> <xsl:if test="string-length(@min)>0 or string-length(@max)>0"> - <xsl:text>:</xsl:text> + <xsl:text>,</xsl:text> <xsl:value-of select="@min"/> - <xsl:text>:</xsl:text> + <xsl:text>,</xsl:text> <xsl:value-of select="@max"/> </xsl:if> </xsl:template> @@ -214,7 +221,7 @@ <xsl:value-of select="$svg_widget_type"/> </msg> </xsl:variable> - <xsl:value-of select="ns:GiveDetails($testmsg)"/> + <xsl:value-of select="ns:PassMessage($testmsg)"/> <xsl:apply-templates mode="inline_svg" select="/"/> </xsl:template> </xsl:stylesheet> diff -r 315f17e74ef5 -r f2bfb047d0e6 svghmi/gen_dnd_widget_svg.ysl2 --- a/svghmi/gen_dnd_widget_svg.ysl2 Sun May 02 23:15:23 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.ysl2 Sun May 02 23:43:57 2021 +0200 @@ -11,7 +11,6 @@ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:xhtml="http://www.w3.org/1999/xhtml" /* Namespace to invoke python code */ xmlns:ns="beremiz" @@ -20,7 +19,6 @@ exclude-result-prefixes="ns func exsl regexp str dyn" { param "hmi_path"; - const "svg", "/svg:svg"; const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; const "subhmitree", "ns:GetSubHMITree()"; @@ -84,7 +82,7 @@ msg value "$svg_widget_type"; } - value "ns:GiveDetails($testmsg)"; + value "ns:PassMessage($testmsg)"; apply "/", mode="inline_svg"; } diff -r 315f17e74ef5 -r f2bfb047d0e6 svghmi/ui.py --- a/svghmi/ui.py Sun May 02 23:15:23 2021 +0200 +++ b/svghmi/ui.py Sun May 02 23:43:57 2021 +0200 @@ -293,6 +293,10 @@ for msg in msgs: self.msg += msg.text + "\n" + def PassMessage(self, _context, msgs): + for msg in msgs: + self.msg += msg.text + "\n" + def GetSubHMITree(self, _context): return [self.hmitree_node.etree()] @@ -312,7 +316,7 @@ transform = XSLTransform( os.path.join(ScriptDirectory, "gen_dnd_widget_svg.xslt"), [("GetSubHMITree", self.GetSubHMITree), - ("GiveDetails", self.GiveDetails)]) + ("PassMessage", self.GiveDetails)]) svgdom = etree.parse(self.selected_SVG)