# HG changeset patch # User Edouard Tisserant # Date 1614609983 -3600 # Node ID aaa203270ab076a91edfb8fe3fd60beba56e235e # Parent 91207ee5b6af429c2502989da4e92dae01f45e4e SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant. diff -r 91207ee5b6af -r aaa203270ab0 svghmi/detachable_pages.ysl2 --- 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" { diff -r 91207ee5b6af -r aaa203270ab0 svghmi/gen_index_xhtml.xslt --- 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 @@ - - + + @@ -441,22 +441,17 @@ - - - - - - + + - + - @@ -544,8 +539,9 @@ - - + + + @@ -555,7 +551,7 @@ " - + ": { bbox: [ @@ -646,7 +642,7 @@ - + @@ -1697,7 +1693,7 @@ - + @@ -6791,7 +6787,7 @@ - + diff -r 91207ee5b6af -r aaa203270ab0 svghmi/svghmi.py --- 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 = """ @@ -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: