# HG changeset patch # User Edouard Tisserant # Date 1615450431 -3600 # Node ID 1d3408e46ab1cce9537b29b0f77f1b49a90686bf # Parent 50d0fef791d5aa6b73d1bb78a7d19d876f5ddd8c# Parent ca9774c0f6a74ce325f1233a2aad214e7d4ff4b3 merge diff -r ca9774c0f6a7 -r 1d3408e46ab1 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed Mar 10 10:01:05 2021 +0100 +++ b/svghmi/gen_index_xhtml.xslt Thu Mar 11 09:13:51 2021 +0100 @@ -1,6 +1,6 @@ - - + + @@ -1693,7 +1693,7 @@ - + @@ -4535,7 +4535,7 @@ cache = [0,100,50]; - init() { + init_common() { this.spread_json_data_bound = this.spread_json_data.bind(this); @@ -4940,13 +4940,6 @@ data - - - - forward backward cursor - - - visible: @@ -4968,6 +4961,20 @@ + }, + + init() { + + this.init_common(); + + + id(" + + ").onclick = this.make_on_click(" + + "); + + } @@ -6801,7 +6808,7 @@ - + diff -r ca9774c0f6a7 -r 1d3408e46ab1 svghmi/svghmi.py --- a/svghmi/svghmi.py Wed Mar 10 10:01:05 2021 +0100 +++ b/svghmi/svghmi.py Thu Mar 11 09:13:51 2021 +0100 @@ -362,7 +362,7 @@ # Backup HMI Tree in XML form so that it can be loaded without building hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") - hmitree_backup_file = open(hmitree_backup_path, 'w') + hmitree_backup_file = open(hmitree_backup_path, 'wb') hmitree_backup_file.write(etree.tostring(hmi_tree_root.etree())) hmitree_backup_file.close() @@ -449,7 +449,7 @@ buildpath = self.Controler.GetCTRoot()._getBuildPath() hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") if os.path.exists(hmitree_backup_path): - hmitree_backup_file = open(hmitree_backup_path, 'r') + hmitree_backup_file = open(hmitree_backup_path, 'rb') hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot()) return HMITreeSelector(parent) @@ -602,51 +602,74 @@ target_fname = "svghmi_"+location_str+".xhtml" - target_path = os.path.join(self._getBuildPath(), target_fname) - target_file = open(target_path, 'wb') + build_path = self._getBuildPath() + target_path = os.path.join(build_path, target_fname) + hash_path = os.path.join(build_path, "svghmi.md5") self.GetCTRoot().logger.write("SVGHMI:\n") if os.path.exists(svgfile): - # TODO : move to __init__ - transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"), - [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()), - ("GetHMITree", lambda *_ignored:self.GetHMITree()), - ("GetTranslations", self.GetTranslations), - ("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.ProgressEnd("svg") - - # call xslt transform on Inkscape's SVG to generate XHTML - try: - self.ProgressStart("xslt", "XSLT transform") - result = transform.transform(svgdom) # , profile_run=True) - self.ProgressEnd("xslt") - except XSLTApplyError as e: - self.FatalError("SVGHMI " + view_name + ": " + e.message) - finally: - for entry in transform.get_error_log(): - message = "SVGHMI: "+ entry.message + "\n" - self.GetCTRoot().logger.write_warning(message) - - result.write(target_file, encoding="utf-8") - # print(str(result)) - # print(transform.xslt.error_log) - # print(etree.tostring(result.xslt_profile,pretty_print=True)) - - # TODO - # - Errors on HMI semantics - # - ... maybe something to have a global view of what is declared in SVG. + hasher = hashlib.md5() + hmi_tree_root._hash(hasher) + with open(svgfile, 'rb') as afile: + while True: + buf = afile.read(65536) + if len(buf) > 0: + hasher.update(buf) + else: + break + digest = hasher.hexdigest() + + if os.path.exists(hash_path): + with open(hash_path, 'rb') as digest_file: + last_digest = digest_file.read() + else: + last_digest = None + + if digest != last_digest: + + transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"), + [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()), + ("GetHMITree", lambda *_ignored:self.GetHMITree()), + ("GetTranslations", self.GetTranslations), + ("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.ProgressEnd("svg") + + # call xslt transform on Inkscape's SVG to generate XHTML + try: + self.ProgressStart("xslt", "XSLT transform") + result = transform.transform(svgdom) # , profile_run=True) + self.ProgressEnd("xslt") + except XSLTApplyError as e: + self.FatalError("SVGHMI " + view_name + ": " + e.message) + finally: + for entry in transform.get_error_log(): + message = "SVGHMI: "+ entry.message + "\n" + self.GetCTRoot().logger.write_warning(message) + + target_file = open(target_path, 'wb') + result.write(target_file, encoding="utf-8") + target_file.close() + + # print(str(result)) + # print(transform.xslt.error_log) + # print(etree.tostring(result.xslt_profile,pretty_print=True)) + + with open(hash_path, 'wb') as digest_file: + digest_file.write(digest) + else: + self.GetCTRoot().logger.write(" No changes - XSLT transformation skipped\n") else: - # TODO : use default svg that expose the HMI tree as-is + target_file = open(target_path, 'wb') target_file.write(""" @@ -654,8 +677,7 @@ """) - - target_file.close() + target_file.close() res += ((target_fname, open(target_path, "rb")),) diff -r ca9774c0f6a7 -r 1d3408e46ab1 svghmi/widget_jsontable.ysl2 --- a/svghmi/widget_jsontable.ysl2 Wed Mar 10 10:01:05 2021 +0100 +++ b/svghmi/widget_jsontable.ysl2 Thu Mar 11 09:13:51 2021 +0100 @@ -5,7 +5,7 @@ class JsonTableWidget extends Widget{ // arbitrary defaults to avoid missing entries in query cache = [0,100,50]; - init() { + init_common() { this.spread_json_data_bound = this.spread_json_data.bind(this); this.handle_http_response_bound = this.handle_http_response.bind(this); this.fetch_error_bound = this.fetch_error.bind(this); @@ -254,7 +254,6 @@ template "widget[@type='JsonTable']", mode="widget_defs" { param "hmi_element"; labels("data"); - optional_labels("forward backward cursor"); const "data_elt", "$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']"; | visible: «count($data_elt/*[@inkscape:label])», | spread_json_data: function(janswer) { @@ -267,5 +266,12 @@ with "expressions","$initexpr_ns"; with "widget_elts","$hmi_element/*[@inkscape:label = 'data']/descendant::svg:*"; } + | }, + | init() { + | this.init_common(); + foreach "$hmi_element/*[starts-with(@inkscape:label,'action_')]" { + | id("«@id»").onclick = this.make_on_click("«func:escape_quotes(@inkscape:label)»"); + } | } -} + +} diff -r ca9774c0f6a7 -r 1d3408e46ab1 tests/svghmi/py_ext_0@py_ext/pyfile.xml --- a/tests/svghmi/py_ext_0@py_ext/pyfile.xml Wed Mar 10 10:01:05 2021 +0100 +++ b/tests/svghmi/py_ext_0@py_ext/pyfile.xml Thu Mar 11 09:13:51 2021 +0100 @@ -37,7 +37,12 @@ extra = newdata[u'extra'] options = newdata[u'options'] - if len(options) == 2 : + if len(options) == 1 : + action, = options + if action == "action_reset": + del Alarms[:] + AlarmIndex.clear() + elif len(options) == 2 : action, alarmid = options if action == "onClick[acknowledge]": AlarmIndex[int(alarmid)][2] = "ack" diff -r ca9774c0f6a7 -r 1d3408e46ab1 tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed Mar 10 10:01:05 2021 +0100 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Mar 11 09:13:51 2021 +0100 @@ -128,12 +128,12 @@ inkscape:current-layer="hmi0" showgrid="false" units="px" - inkscape:zoom="0.42177816" - inkscape:cx="-871.66754" - inkscape:cy="136.19693" - inkscape:window-width="1600" - inkscape:window-height="836" - inkscape:window-x="0" + inkscape:zoom="1.6871126" + inkscape:cx="-820.55411" + inkscape:cy="162.70697" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="1600" inkscape:window-y="27" inkscape:window-maximized="1" showguides="true" @@ -5214,6 +5214,44 @@ transform="translate(0,-377.48864)" inkscape:label="[0]" /> + + + + + + reset + +