usveticic@3014: // widget_multistate.ysl2 usveticic@3014: usveticic@3014: template "widget[@type='MultiState']", mode="widget_class" usveticic@3014: || usveticic@3014: class MultiStateWidget extends Widget{ usveticic@3014: frequency = 5; usveticic@3014: state = 0; usveticic@3014: dispatch(value) { usveticic@3014: this.state = value; usveticic@3014: for(let choice of this.choices){ usveticic@3014: if(this.state != choice.value){ usveticic@3014: choice.elt.setAttribute("style", "display:none"); usveticic@3014: } else { usveticic@3014: choice.elt.setAttribute("style", choice.style); usveticic@3014: } usveticic@3014: } usveticic@3014: } usveticic@3014: usveticic@3014: on_click(evt) { usveticic@3014: //get current selected value usveticic@3014: let next_ind; usveticic@3014: for(next_ind=0; next_ind next_ind){ usveticic@3014: this.state = this.choices[next_ind].value; usveticic@3014: } usveticic@3014: else{ usveticic@3014: this.state = this.choices[0].value; usveticic@3014: } usveticic@3014: usveticic@3014: //post value to plc Edouard@3018: this.apply_hmi_value(0, this.state); usveticic@3014: } usveticic@3014: usveticic@3014: init() { usveticic@3014: this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); usveticic@3014: } usveticic@3014: } usveticic@3014: || usveticic@3014: usveticic@3014: template "widget[@type='MultiState']", mode="widget_defs" { usveticic@3014: param "hmi_element"; usveticic@3014: | choices: [ usveticic@3014: const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; usveticic@3014: foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" { usveticic@3014: const "literal", "regexp:match(@inkscape:label,$regex)[2]"; usveticic@3014: | { usveticic@3014: | elt:id("«@id»"), usveticic@3014: | style:"«@style»", usveticic@3014: | value:«$literal» usveticic@3014: | }`if "position()!=last()" > ,` usveticic@3014: } usveticic@3014: | ], Edouard@3018: }