# HG changeset patch
# User Edouard Tisserant
# Date 1581944264 -3600
# Node ID f4dd234faa111a6d7c469810949c2ce7fa20ea5a
# Parent 459bf80d3f4677beab30074948d25f1041518157
SVGHMI: Added mostly untested switch widget
diff -r 459bf80d3f46 -r f4dd234faa11 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Fri Feb 14 21:41:13 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Mon Feb 17 13:57:44 2020 +0100
@@ -1107,13 +1107,68 @@
frequency: 5,
-
- frequency: 5,
+
+
+ frequency: 5,
+
+ dispatch: function(value) {
+
+ for(let choice of this.choices){
+
+ if(value != choice.value){
+
+ choice.elt.setAttribute("style", "display:none");
+
+ } else {
+
+ choice.elt.setAttribute("style", choice.style);
+
+ }
+
+ }
+
+ },
+
+ init: function() {
+
+ // Hello Switch
+
+ },
+
+ choices: [
+
+
+
+
+ {
+
+ elt:document.getElementById("
+
+ "),
+
+ style:"
+
+ ",
+
+ value:
+
+
+
+ }
+
+ ,
+
+
+
+
+ ],
- on_click: function() {
+ on_click: function(evt) {
+
+ console.log(evt);
switch_page(this.args[0]);
@@ -1123,7 +1178,7 @@
this.element.setAttribute("onclick", "hmi_widgets['
- '].on_click()");
+ '].on_click(evt)");
},
diff -r 459bf80d3f46 -r f4dd234faa11 svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Fri Feb 14 21:41:13 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Mon Feb 17 13:57:44 2020 +0100
@@ -468,12 +468,37 @@
template "widget[@type='Toggle']", mode="widget_defs" {
| frequency: 5,
}
- template "widget[@type='Change']", mode="widget_defs" {
- | frequency: 5,
+ template "widget[@type='Switch']", mode="widget_defs" {
+ param "hmi_element";
+ | frequency: 5,
+ | dispatch: function(value) {
+ | for(let choice of this.choices){
+ | if(value != choice.value){
+ | choice.elt.setAttribute("style", "display:none");
+ | } else {
+ | choice.elt.setAttribute("style", choice.style);
+ | }
+ | }
+ | },
+ | init: function() {
+ | // Hello Switch
+ | },
+ | choices: [
+ const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+)(#.*)?$'"!;
+ foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" {
+ const "literal", "regexp:match(@inkscape:label,$regex)[2]";
+ | {
+ | elt:document.getElementById("«@id»"),
+ | style:"«@style»",
+ | value:«$literal»
+ | }`if "position()!=last()" > ,`
+ }
+ | ],
}
template "widget[@type='Jump']", mode="widget_defs" {
param "hmi_element";
- | on_click: function() {
+ | on_click: function(evt) {
+ | console.log(evt);
| switch_page(this.args[0]);
| },
| init: function() {
@@ -482,7 +507,7 @@
event must be registered by adding attribute to element instead
TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
*/
- | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click()");
+ | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
| },
}
}