# HG changeset patch # User Edouard Tisserant # Date 1586032374 -7200 # Node ID 3ee337c8c7690e18d3802035be7a000dad05117f # Parent c6e6051898f587b66a5246414584d11248c0fabb SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled... diff -r c6e6051898f5 -r 3ee337c8c769 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Sat Apr 04 17:47:16 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Sat Apr 04 22:32:54 2020 +0200 @@ -687,15 +687,16 @@ + - + - + - + widget must have a @@ -707,9 +708,53 @@ _elt: id(" - + "), + + + + _sub: { + + + + + + + + + + widget must have a + + / + + element + + + /* missing + + / + + element */ + + + + " + + ": id(" + + ") + + , + + + + + + + }, + + @@ -1197,10 +1242,18 @@ - Sign CapsLock Shift Space + Sign Space NumDot + + + + CapsLock Shift + + + + init: function() { @@ -1213,7 +1266,7 @@ ')"); - + if(this. _elt) @@ -1241,16 +1294,12 @@ this.update(); - console.log(symbols); - }, on_Esc_click: function() { end_modal.call(this); - console.log("Esc"); - }, on_Enter_click: function() { @@ -1261,8 +1310,6 @@ callback_obj.edit_callback(this.editstr); - console.log("Enter"); - }, on_BackSpace_click: function() { @@ -1271,8 +1318,6 @@ this.update(); - console.log("BackSpace"); - }, on_Sign_click: function() { @@ -1285,35 +1330,53 @@ this.editstr = "-" + this.editstr; - console.log("Sign"); + this.update(); }, + on_NumDot_click: function() { + + if(this.editstr.indexOf(".") == "-1"){ + + this.editstr += "."; + + this.update(); + + } + + }, + on_Space_click: function() { this.editstr += " "; - console.log("Space"); + this.update(); }, caps: false, + _caps: undefined, + on_CapsLock_click: function() { this.caps = !this.caps; - console.log("CapsLock"); + this.update(); }, shift: false, + _shift: undefined, + on_Shift_click: function() { - this.shift = true; - - console.log("Shift"); + this.shift = !this.shift; + + this.caps = false; + + this.update(); }, @@ -1326,6 +1389,8 @@ editstr: "", + _editstr: undefined, + result_callback_obj: undefined, start_edit: function(info, valuetype, callback_obj, initial) { @@ -1348,9 +1413,29 @@ update: function() { - /* TODO Swith shift and capslock active/inactive elements */ - - this.Value_elt.textContent = this.editstr; + if(this.editstr != this._editstr){ + + this._editstr = this.editstr; + + this.Value_elt.textContent = this.editstr; + + } + + if(this.shift != this._shift){ + + this._shift = this.shift; + + (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); + + } + + if(this.caps != this._caps){ + + this._caps = this.caps; + + (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); + + } }, @@ -2605,5 +2690,39 @@ }; + + + function widget_active_activable(eltsub) { + + if(eltsub.inactive_style === undefined) + + eltsub.inactive_style = eltsub.inactive.getAttribute("style"); + + eltsub.inactive.setAttribute("style", "display:none"); + + if(eltsub.active_style !== undefined) + + eltsub.active.setAttribute("style", eltsub.active_style); + + console.log("active", eltsub); + + }; + + function widget_inactive_activable(eltsub) { + + if(eltsub.active_style === undefined) + + eltsub.active_style = eltsub.active.getAttribute("style"); + + eltsub.active.setAttribute("style", "display:none"); + + if(eltsub.inactive_style !== undefined) + + eltsub.inactive.setAttribute("style", eltsub.inactive_style); + + console.log("inactive", eltsub); + + }; + diff -r c6e6051898f5 -r 3ee337c8c769 svghmi/svghmi.js --- a/svghmi/svghmi.js Sat Apr 04 17:47:16 2020 +0200 +++ b/svghmi/svghmi.js Sat Apr 04 22:32:54 2020 +0200 @@ -505,3 +505,20 @@ current_modal = undefined; }; + +function widget_active_activable(eltsub) { + if(eltsub.inactive_style === undefined) + eltsub.inactive_style = eltsub.inactive.getAttribute("style"); + eltsub.inactive.setAttribute("style", "display:none"); + if(eltsub.active_style !== undefined) + eltsub.active.setAttribute("style", eltsub.active_style); + console.log("active", eltsub); +}; +function widget_inactive_activable(eltsub) { + if(eltsub.active_style === undefined) + eltsub.active_style = eltsub.active.getAttribute("style"); + eltsub.active.setAttribute("style", "display:none"); + if(eltsub.inactive_style !== undefined) + eltsub.inactive.setAttribute("style", eltsub.inactive_style); + console.log("inactive", eltsub); +}; diff -r c6e6051898f5 -r 3ee337c8c769 svghmi/widget_keypad.ysl2 --- a/svghmi/widget_keypad.ysl2 Sat Apr 04 17:47:16 2020 +0200 +++ b/svghmi/widget_keypad.ysl2 Sat Apr 04 22:32:54 2020 +0200 @@ -3,12 +3,13 @@ template "widget[@type='Keypad']", mode="widget_defs" { param "hmi_element"; labels("Esc Enter BackSpace Keys Info Value"); - optional_labels("Sign CapsLock Shift Space"); + optional_labels("Sign Space NumDot"); + activable_labels("CapsLock Shift"); | init: function() { foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" { | id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')"); } - foreach "str:split('Esc Enter BackSpace Sign Space CapsLock Shift')" { + foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" { | if(this.«.»_elt) | this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()"); } @@ -19,51 +20,53 @@ | this.editstr += syms[this.shift?syms.length-1:0]; | this.shift = false; | this.update(); - | console.log(symbols); | }, | on_Esc_click: function() { | end_modal.call(this); - | console.log("Esc"); | }, | on_Enter_click: function() { | end_modal.call(this); | callback_obj = this.result_callback_obj; | callback_obj.edit_callback(this.editstr); - | console.log("Enter"); | }, | on_BackSpace_click: function() { | this.editstr = this.editstr.slice(0,this.editstr.length-1); | this.update(); - | console.log("BackSpace"); | }, | on_Sign_click: function() { | if(this.editstr[0] == "-") | this.editstr = this.editstr.slice(1,this.editstr.length); | else | this.editstr = "-" + this.editstr; - | console.log("Sign"); + | this.update(); + | }, + | on_NumDot_click: function() { + | if(this.editstr.indexOf(".") == "-1"){ + | this.editstr += "."; + | this.update(); + | } | }, | on_Space_click: function() { | this.editstr += " "; | this.update(); - | console.log("Space"); | }, | caps: false, + | _caps: undefined, | on_CapsLock_click: function() { | this.caps = !this.caps; | this.update(); - | console.log("CapsLock"); | }, | shift: false, + | _shift: undefined, | on_Shift_click: function() { - | this.shift = true; + | this.shift = !this.shift; | this.caps = false; | this.update(); - | console.log("Shift"); | }, const "g", "$geometry[@Id = $hmi_element/@id]"; | coordinates: [«$g/@x», «$g/@y»], | editstr: "", + | _editstr: undefined, | result_callback_obj: undefined, | start_edit: function(info, valuetype, callback_obj, initial) { | show_modal.call(this); @@ -75,7 +78,17 @@ | this.update(); | }, | update: function() { - | /* TODO Swith shift and capslock active/inactive elements */ - | this.Value_elt.textContent = this.editstr; + | if(this.editstr != this._editstr){ + | this._editstr = this.editstr; + | this.Value_elt.textContent = this.editstr; + | } + | if(this.shift != this._shift){ + | this._shift = this.shift; + | (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); + | } + | if(this.caps != this._caps){ + | this._caps = this.caps; + | (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); + | } | }, } diff -r c6e6051898f5 -r 3ee337c8c769 svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Sat Apr 04 17:47:16 2020 +0200 +++ b/svghmi/widgets_common.ysl2 Sat Apr 04 22:32:54 2020 +0200 @@ -11,6 +11,13 @@ with "mandatory","'no'"; }; +in xsl decl activable_labels(*ptr, name="defs_by_labels") alias call-template { + with "hmi_element", "$hmi_element"; + with "labels"{text *ptr}; + with "mandatory","'no'"; + with "subelements","'active inactive'"; +}; + template "svg:*", mode="hmi_elements" { const "widget", "func:widget(@id)"; const "eltid","@id"; @@ -51,21 +58,40 @@ function "defs_by_labels" { param "labels","''"; param "mandatory","'yes'"; + param "subelements","/.."; param "hmi_element"; const "widget_type","@type"; foreach "str:split($labels)" { const "name","."; - const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"; + const "elt","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]"; choose { - when "not($elt_id)" { + when "not($elt/@id)" { if "$mandatory='yes'" { - // TODO FIXME error > «$widget_type» widget must have a «$name» element - warning > «$widget_type» widget must have a «$name» element + error > «$widget_type» widget must have a «$name» element } // otherwise produce nothing } otherwise { - | «$name»_elt: id("«$elt_id»"), + | «$name»_elt: id("«$elt/@id»"), + if "$subelements" { + | «$name»_sub: { + foreach "str:split($subelements)" { + const "subname","."; + const "subelt","$elt/*[@inkscape:label=$subname][1]"; + choose { + when "not($subelt/@id)" { + if "$mandatory='yes'" { + error > «$widget_type» widget must have a «$name»/«$subname» element + } + | /* missing «$name»/«$subname» element */ + } + otherwise { + | "«$subname»": id("«$subelt/@id»")`if "position()!=last()" > ,` + } + } + } + | }, + } } } } diff -r c6e6051898f5 -r 3ee337c8c769 tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Sat Apr 04 17:47:16 2020 +0200 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Sat Apr 04 22:32:54 2020 +0200 @@ -1529,22 +1529,6 @@ x="636.4165" transform="scale(1.0007154,0.99928514)">0 - - - . - information + + + . +