# HG changeset patch # User Edouard Tisserant # Date 1589388607 -7200 # Node ID 00825316ed00f30871166e8fc9516dd1099a91d5 # Parent 5ad82541b46e60484256f74d0e6d4e6410169731 SVGHMI: Update Button widget to class declaration, and add a button widget in tests/svghmi. diff -r 5ad82541b46e -r 00825316ed00 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed May 13 18:47:09 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Wed May 13 18:50:07 2020 +0200 @@ -868,6 +868,8 @@ constructor(elt_id,args,indexes,members){ + this.element_id = elt_id; + this.element = id(elt_id); this.args = args; @@ -880,6 +882,8 @@ } + + unsub(){ /* remove subsribers */ @@ -1078,9 +1082,10 @@ - - - on_click: function(evt) { + + class BackWidget extends Widget{ + + on_click(evt) { if(jump_history.length > 1){ @@ -1092,44 +1097,47 @@ } - }, - - init: function() { - - this.element.setAttribute("onclick", "hmi_widgets[' - - '].on_click(evt)"); - - }, - - - - - frequency: 5, - - init: function() { - - this.element.addEventListener( - - "mousedown", - - evt => { - - change_hmi_value(this.indexes[0], "=1"); - - }); - - this.element.addEventListener( - - "mouseup", - - evt => { - - change_hmi_value(this.indexes[0], "=0"); - - }); - - }, + } + + init() { + + this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); + + } + + } + + + + class ButtonWidget extends Widget{ + + frequency = 5; + + init() { + + this.element.addEventListener( + + "mousedown", + + evt => { + + change_hmi_value(this.indexes[0], "=1"); + + }); + + this.element.addEventListener( + + "mouseup", + + evt => { + + change_hmi_value(this.indexes[0], "=0"); + + }); + + } + + } @@ -1767,7 +1775,6 @@ - @@ -3104,11 +3111,15 @@ let maxfreq = 0; - for(let widget of widgets) - - if(maxfreq < widget.frequency) - - maxfreq = widget.frequency; + for(let widget of widgets){ + + let wf = widget.frequency; + + if(wf != undefined && maxfreq < wf) + + maxfreq = wf; + + } diff -r 5ad82541b46e -r 00825316ed00 svghmi/widget_button.ysl2 --- a/svghmi/widget_button.ysl2 Wed May 13 18:47:09 2020 +0200 +++ b/svghmi/widget_button.ysl2 Wed May 13 18:50:07 2020 +0200 @@ -1,18 +1,20 @@ // widget_button.ysl2 -template "widget[@type='Button']", mode="widget_defs" { - param "hmi_element"; - | frequency: 5, - | init: function() { - | this.element.addEventListener( - | "mousedown", - | evt => { - | change_hmi_value(this.indexes[0], "=1"); - | }); - | this.element.addEventListener( - | "mouseup", - | evt => { - | change_hmi_value(this.indexes[0], "=0"); - | }); - | }, -} \ No newline at end of file +template "widget[@type='Button']", mode="widget_class" + || + class ButtonWidget extends Widget{ + frequency = 5; + init() { + this.element.addEventListener( + "mousedown", + evt => { + change_hmi_value(this.indexes[0], "=1"); + }); + this.element.addEventListener( + "mouseup", + evt => { + change_hmi_value(this.indexes[0], "=0"); + }); + } + } + || diff -r 5ad82541b46e -r 00825316ed00 tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed May 13 18:47:09 2020 +0200 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed May 13 18:50:07 2020 +0200 @@ -16,7 +16,7 @@ version="1.1" id="hmi0" sodipodi:docname="svghmi.svg" - inkscape:version="0.92.4 (5da689c313, 2019-01-14)"> + inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"> @@ -127,13 +127,13 @@ inkscape:current-layer="hmi0" showgrid="false" units="px" - inkscape:zoom="0.35355339" - inkscape:cx="-418.67433" - inkscape:cy="-1206.7258" + inkscape:zoom="0.70710678" + inkscape:cx="263.37056" + inkscape:cy="-24.461312" inkscape:window-width="1920" - inkscape:window-height="1080" + inkscape:window-height="1348" inkscape:window-x="3815" - inkscape:window-y="968" + inkscape:window-y="700" inkscape:window-maximized="0" showguides="true" inkscape:guide-bbox="true" /> @@ -912,29 +912,29 @@ 8888 8888 @@ -1124,196 +1124,6 @@ - 8888 - - - - dhu - - - - plop - - - - mhoo - - - - yodl - - - - mhe - - - + + + + + + up + +