# HG changeset patch # User Edouard Tisserant # Date 1619993048 -7200 # Node ID b2b6bf45aa2d0363759903cabc908fda1ca2d3f4 # Parent f2bfb047d0e6c776ee06554c398ddfa7c4f6f77c SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation. diff -r f2bfb047d0e6 -r b2b6bf45aa2d svghmi/Makefile --- a/svghmi/Makefile Sun May 02 23:43:57 2021 +0200 +++ b/svghmi/Makefile Mon May 03 00:04:08 2021 +0200 @@ -11,7 +11,7 @@ yml2path ?= $(abspath ../../yml2) -ysl2files := gen_index_xhtml.ysl2 gen_dnd_widget_svg.ysl2 +ysl2files := gen_index_xhtml.ysl2 gen_dnd_widget_svg.ysl2 analyse_widget.ysl2 ysl2includes := $(filter-out $(ysl2files), $(wildcard *.ysl2)) xsltfiles := $(patsubst %.ysl2, %.xslt, $(ysl2files)) diff -r f2bfb047d0e6 -r b2b6bf45aa2d svghmi/analyse_widget.xslt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/analyse_widget.xslt Mon May 03 00:04:08 2021 +0200 @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Widget id: + + label: + + has wrong syntax of path section + + + + + + + + + PAGE_LOCAL + + + + + HMI_LOCAL + + + + + + + + Widget id: + + label: + + path section + + use min and max on non mumeric value + + + + + + + + + + + + + + + + + + + + + : + + + + @ + + + , + + , + + + + + HMI: + + + + + + + + + + + diff -r f2bfb047d0e6 -r b2b6bf45aa2d svghmi/analyse_widget.ysl2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/analyse_widget.ysl2 Mon May 03 00:04:08 2021 +0200 @@ -0,0 +1,20 @@ +include yslt_noindent.yml2 + +istylesheet + /* From Inkscape */ + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + + extension-element-prefixes="ns func exsl regexp str dyn" + exclude-result-prefixes="ns func exsl regexp str dyn svg inkscape" { + + const "indexed_hmitree", "/.."; // compatibility with parse_labels.ysl2 + include parse_labels.ysl2 + + const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; + + template "/" + widgets + apply "$hmi_elements", mode="parselabel"; + +} diff -r f2bfb047d0e6 -r b2b6bf45aa2d svghmi/ui.py --- a/svghmi/ui.py Sun May 02 23:43:57 2021 +0200 +++ b/svghmi/ui.py Mon May 03 00:04:08 2021 +0200 @@ -299,10 +299,54 @@ def GetSubHMITree(self, _context): return [self.hmitree_node.etree()] + def AnalyseWidget(self): + self.msg = "" + + try: + if self.selected_SVG is None: + raise Exception(_("No widget selected")) + + transform = XSLTransform( + os.path.join(ScriptDirectory, "analyse_widget.xslt"),[]) + + svgdom = etree.parse(self.selected_SVG) + + result = transform.transform(svgdom) + + for entry in transform.get_error_log(): + self.msg += "XSLT: " + entry.message + "\n" + + except Exception as e: + self.msg += str(e) + except XSLTApplyError as e: + self.msg += "Widget analysis error: " + e.message + else: + return result + + def UpdateUI(self, signature): + if signature is not None: + print(etree.tostring(signature, pretty_print=True)) + widgets = signature.getroot() + for widget in widgets: + widget_type = widget.get("type") + print(widget_type) + for path in widget: + path_value = path.get("value") + path_accepts = map( + str.strip, path.get("accepts", '')[1:-1].split(',')) + print(path_value, path_accepts) + + def ValidateWidget(self): self.msg = "" + signature = self.AnalyseWidget() + + self.UpdateUI(signature) + + return + if self.tempf is not None: os.unlink(self.tempf.name) self.tempf = None diff -r f2bfb047d0e6 -r b2b6bf45aa2d svghmi/widgetlib/modern_knob_1.svg --- a/svghmi/widgetlib/modern_knob_1.svg Sun May 02 23:43:57 2021 +0200 +++ b/svghmi/widgetlib/modern_knob_1.svg Mon May 03 00:04:08 2021 +0200 @@ -159,16 +159,16 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="0.35" - inkscape:cx="41.428571" - inkscape:cy="555.71429" + inkscape:zoom="1.979899" + inkscape:cx="208.80035" + inkscape:cy="841.9769" inkscape:document-units="mm" - inkscape:current-layer="svg2637" + inkscape:current-layer="g3058" showgrid="false" - inkscape:window-width="1414" - inkscape:window-height="840" - inkscape:window-x="1690" - inkscape:window-y="117" + inkscape:window-width="1623" + inkscape:window-height="1446" + inkscape:window-x="3346" + inkscape:window-y="244" inkscape:window-maximized="0" /> @@ -178,7 +178,7 @@ image/svg+xml - + @@ -206,7 +206,7 @@