SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
--- a/svghmi/detachable_pages.ysl2 Mon Mar 01 15:45:13 2021 +0100
+++ b/svghmi/detachable_pages.ysl2 Mon Mar 01 15:46:23 2021 +0100
@@ -51,20 +51,15 @@
// should be implemented in python or even C,
// as this is still the main bottleneck here
const "_overlapping_geometry" {
- const "k", "'overlapping'";
- const "m", "'computing belonging of widgets to pages'";
- value "ns:ProgressStart($k, $m)";
foreach "$hmi_pages | $keypads" {
- const "k2", "concat('overlapping:', @id)";
- const "m2", "concat('collecting membership of ', @inkscape:label)";
- value "ns:ProgressStart($k2, $m2)";
+ const "k", "concat('overlapping:', @id)";
+ value "ns:ProgressStart($k, concat('collecting membership of ', @inkscape:label))";
elt {
attrib "id" > «@id»
copy "func:overlapping_geometry(.)";
}
- value "ns:ProgressEnd($k2, $m2)";
- }
- value "ns:ProgressEnd($k, $m)";
+ value "ns:ProgressEnd($k)";
+ }
}
const "overlapping_geometry", "exsl:node-set($_overlapping_geometry)";
@@ -142,8 +137,9 @@
const "desc", "func:widget(@id)";
- const "msg", "concat('generating page description ', $desc/arg[1]/@value)";
- value "ns:ProgressStart($msg)";
+ const "pagename", "$desc/arg[1]/@value";
+ const "msg", "concat('generating page description ', $pagename)";
+ value "ns:ProgressStart($pagename, $msg)";
const "page", ".";
const "p", "$geometry[@Id = $page/@id]";
@@ -163,7 +159,7 @@
"""$sumarized_page/
ancestor-or-self::*[@id = $detachable_elements/@id]""";
- | "«$desc/arg[1]/@value»": {
+ | "«$pagename»": {
//| widget: hmi_widgets["«@id»"],
| bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
if "$desc/path/@value" {
@@ -196,7 +192,7 @@
with "page_desc", "$desc";
}
| }`if "position()!=last()" > ,`
- value "ns:ProgressEnd($msg)";
+ value "ns:ProgressEnd($pagename)";
}
emit "definitions:page-desc" {
--- a/svghmi/gen_index_xhtml.xslt Mon Mar 01 15:45:13 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt Mon Mar 01 15:46:23 2021 +0100
@@ -1,6 +1,6 @@
<?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:debug="debug" xmlns:preamble="preamble" xmlns:declarations="declarations" xmlns:definitions="definitions" xmlns:epilogue="epilogue" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions">
- <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
+<xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" 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:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0">
+ <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
<xsl:variable name="svg" select="/svg:svg"/>
<xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
<xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -441,22 +441,17 @@
</xsl:choose>
</func:function>
<xsl:variable name="_overlapping_geometry">
- <xsl:variable name="k" select="'overlapping'"/>
- <xsl:variable name="m" select="'computing belonging of widgets to pages'"/>
- <xsl:value-of select="ns:ProgressStart($k, $m)"/>
<xsl:for-each select="$hmi_pages | $keypads">
- <xsl:variable name="k2" select="concat('overlapping:', @id)"/>
- <xsl:variable name="m2" select="concat('collecting membership of ', @inkscape:label)"/>
- <xsl:value-of select="ns:ProgressStart($k2, $m2)"/>
+ <xsl:variable name="k" select="concat('overlapping:', @id)"/>
+ <xsl:value-of select="ns:ProgressStart($k, concat('collecting membership of ', @inkscape:label))"/>
<elt>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:copy-of select="func:overlapping_geometry(.)"/>
</elt>
- <xsl:value-of select="ns:ProgressEnd($k2, $m2)"/>
+ <xsl:value-of select="ns:ProgressEnd($k)"/>
</xsl:for-each>
- <xsl:value-of select="ns:ProgressEnd($k, $m)"/>
</xsl:variable>
<xsl:variable name="overlapping_geometry" select="exsl:node-set($_overlapping_geometry)"/>
<func:function name="func:all_related_elements">
@@ -544,8 +539,9 @@
</xsl:message>
</xsl:if>
<xsl:variable name="desc" select="func:widget(@id)"/>
- <xsl:variable name="msg" select="concat('generating page description ', $desc/arg[1]/@value)"/>
- <xsl:value-of select="ns:ProgressStart($msg)"/>
+ <xsl:variable name="pagename" select="$desc/arg[1]/@value"/>
+ <xsl:variable name="msg" select="concat('generating page description ', $pagename)"/>
+ <xsl:value-of select="ns:ProgressStart($pagename, $msg)"/>
<xsl:variable name="page" select="."/>
<xsl:variable name="p" select="$geometry[@Id = $page/@id]"/>
<xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
@@ -555,7 +551,7 @@
<xsl:variable name="sumarized_page" select="func:sumarized_elements($page_all_elements)"/>
<xsl:variable name="required_detachables" select="$sumarized_page/ ancestor-or-self::*[@id = $detachable_elements/@id]"/>
<xsl:text> "</xsl:text>
- <xsl:value-of select="$desc/arg[1]/@value"/>
+ <xsl:value-of select="$pagename"/>
<xsl:text>": {
</xsl:text>
<xsl:text> bbox: [</xsl:text>
@@ -646,7 +642,7 @@
</xsl:if>
<xsl:text>
</xsl:text>
- <xsl:value-of select="ns:ProgressEnd($msg)"/>
+ <xsl:value-of select="ns:ProgressEnd($pagename)"/>
</xsl:template>
<definitions:page-desc/>
<xsl:template match="definitions:page-desc">
@@ -1697,7 +1693,7 @@
</xsl:text>
</xsl:template>
<xsl:variable name="excluded_types" select="str:split('Page VarInit VarInitPersistent')"/>
- <xsl:key name="TypesKey" match="widget" use="@type"/>
+ <xsl:key use="@type" name="TypesKey" match="widget"/>
<declarations:hmi-classes/>
<xsl:template match="declarations:hmi-classes">
<xsl:text>
@@ -6791,7 +6787,7 @@
<xsl:comment>
<xsl:apply-templates select="document('')/*/debug:*"/>
</xsl:comment>
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
<head/>
<body style="margin:0;overflow:hidden;user-select:none;touch-action:none;">
<xsl:copy-of select="$result_svg"/>
--- a/svghmi/svghmi.py Mon Mar 01 15:45:13 2021 +0100
+++ b/svghmi/svghmi.py Mon Mar 01 15:46:23 2021 +0100
@@ -430,14 +430,6 @@
#self.HMITreeView = HMITreeView(self)
return HMITreeSelector(parent)
-def _ProgressArgs(args):
- if len(args) == 2:
- key, message = args
- else:
- key, = args
- message = key
- return str(key), str(message), time.time()
-
class SVGHMI(object):
XSD = """<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
@@ -506,7 +498,7 @@
return True
def GetSVGGeometry(self):
- t = time.time()
+ self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)")
# invoke inskscape -S, csv-parse output, produce elements
InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
@@ -531,23 +523,22 @@
res.append(etree.Element("bbox", **attrs))
- self.GetCTRoot().logger.write(" Start collecting SVG geometry (Inkscape)\n")
- self.GetCTRoot().logger.write(" Finished collecting SVG geometry (Inkscape) in %.3fs\n"%(time.time()-t))
+ self.ProgressEnd("inkscape")
return res
def GetHMITree(self):
global hmi_tree_root
- t = time.time()
+ self.ProgressStart("hmitree", "getting HMI tree")
res = [hmi_tree_root.etree(add_hash=True)]
- self.GetCTRoot().logger.write(" Start getting HMI tree\n")
- self.GetCTRoot().logger.write(" Fnished getting HMI tree in %.3fs\n"%(time.time()-t))
+ self.ProgressEnd("hmitree")
return res
def GetTranslations(self, _context, msgs):
- t = time.time()
+ self.ProgressStart("i18n", "getting Translations")
messages = EtreeToMessages(msgs)
if len(messages) == 0:
+ self.ProgressEnd("i18n")
return
SaveCatalog(self._getPOTpath(), messages)
@@ -559,23 +550,22 @@
ret = TranslationToEtree(langs,translated_messages)
- self.GetCTRoot().logger.write(" Start getting Translations\n")
- self.GetCTRoot().logger.write(" Finished getting Translations in %.3fs\n"%(time.time()-t))
+ self.ProgressEnd("i18n")
return ret
- times = {}
-
- def ProgressStart(self, _context, *args):
- k,m,t = _ProgressArgs(args)
- self.times[k] = t
- # self.GetCTRoot().logger.write(" Start %s: %.3f\n"%(m, t - self.transform_begin))
- self.GetCTRoot().logger.write(" Start %s\n"%m)
-
- def ProgressEnd(self, _context, *args):
- k,m,t = _ProgressArgs(args)
- self.GetCTRoot().logger.write(" Finished %s in %.3f\n"%(m, t - self.times[k]))
- self.times[k] = t
+ times_msgs = {}
+ indent = 1
+ def ProgressStart(self, k, m):
+ self.times_msgs[k] = (time.time(), m)
+ self.GetCTRoot().logger.write(" "*self.indent + "Start %s...\n"%m)
+ self.indent = self.indent + 1
+
+ def ProgressEnd(self, k):
+ t = time.time()
+ oldt, m = self.times_msgs[k]
+ self.indent = self.indent - 1
+ self.GetCTRoot().logger.write(" "*self.indent + "... finished in %.3fs\n"%(t - oldt))
def CTNGenerate_C(self, buildpath, locations):
@@ -600,21 +590,21 @@
[("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()),
("GetHMITree", lambda *_ignored:self.GetHMITree()),
("GetTranslations", self.GetTranslations),
- ("ProgressStart", self.ProgressStart),
- ("ProgressEnd", self.ProgressEnd)])
-
- t = time.time()
+ ("ProgressStart", lambda _ign,k,m:self.ProgressStart(str(k),str(m))),
+ ("ProgressEnd", lambda _ign,k:self.ProgressEnd(str(k)))])
+
+ self.ProgressStart("svg", "source SVG parsing")
# load svg as a DOM with Etree
svgdom = etree.parse(svgfile)
- self.GetCTRoot().logger.write(" Source SVG parsing: %.3f\n"%(time.time()-t))
+ self.ProgressEnd("svg")
# call xslt transform on Inkscape's SVG to generate XHTML
try:
- self.transform_begin = time.time()
+ self.ProgressStart("xslt", "XSLT transform")
result = transform.transform(svgdom) # , profile_run=True)
- self.GetCTRoot().logger.write(" XSLT transform: %.3f\n"%(time.time()-self.transform_begin))
+ self.ProgressEnd("xslt")
except XSLTApplyError as e:
self.FatalError("SVGHMI " + view_name + ": " + e.message)
finally: