# HG changeset patch
# User Edouard Tisserant
# Date 1585917461 -7200
# Node ID c8d923dd707fea540782022f5de43858c04d7424
# Parent 4f3b130fd19743967bfaa39e967c95f5e07eba1b
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
diff -r 4f3b130fd197 -r c8d923dd707f svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Fri Apr 03 09:52:57 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Fri Apr 03 14:37:41 2020 +0200
@@ -951,13 +951,13 @@
", "
- ", this.edit_callback, this.last_val);
+ ", this, this.last_val);
},
edit_callback: function(new_val) {
- apply_hmi_value(this.indexes[0], opstr);
+ apply_hmi_value(this.indexes[0], new_val);
this.value_elt.textContent = String(new_val);
@@ -1187,8 +1187,171 @@
+
+
+
+
+ Esc Enter BackSpace Keys Info Value
+
+
+
+
+
+ Sign CapsLock Shift Space
+
+
+
init: function() {
+
+ id("
+
+ ").setAttribute("onclick", "hmi_widgets['
+
+ '].on_key_click('
+
+ ')");
+
+
+
+ if(this.
+
+ _elt)
+
+ this.
+
+ _elt.setAttribute("onclick", "hmi_widgets['
+
+ '].on_
+
+ _click()");
+
+
+ },
+
+ on_key_click: function(symbols) {
+
+ var syms = symbols.split(" ");
+
+ this.shift = this.caps;
+
+ this.editstr += syms[this.shift?syms.length: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");
+
+ },
+
+ on_Space_click: function() {
+
+ this.editstr += " ";
+
+ console.log("Space");
+
+ },
+
+ caps: false,
+
+ on_CapsLock_click: function() {
+
+ this.caps = !this.caps;
+
+ console.log("CapsLock");
+
+ },
+
+ shift: false,
+
+ on_Shift_click: function() {
+
+ this.shift = true;
+
+ console.log("Shift");
+
+ },
+
+
+ coordinates: [
+
+ ,
+
+ ],
+
+ editstr: "",
+
+ result_callback_obj: undefined,
+
+ start_edit: function(info, valuetype, callback_obj, initial) {
+
+ show_modal.call(this);
+
+ this.editstr = initial;
+
+ this.result_callback_obj = callback_obj;
+
+ this.Info_elt.textContent = info;
+
+ this.shift = false;
+
+ this.caps = false;
+
+ this.update();
+
+ },
+
+ update: function() {
+
+ /* TODO Swith shift and capslock active/inactive elements */
+
+ this.Value_elt.textContent = this.editstr;
+
},
@@ -2367,6 +2530,8 @@
+ var xmlns = "http://www.w3.org/2000/svg";
+
var edit_callback;
function edit_value(path, valuetype, callback, initial) {
@@ -2379,16 +2544,32 @@
edit_callback = callback;
-
-
- let [element, parent] = detachable_elements[keypadid];
-
- tmpgrp = document.createElement("g");
+ let widget = hmi_widgets[keypadid];
+
+ widget.start_edit(path, valuetype, callback, initial);
+
+ };
+
+
+
+ var current_modal; /* TODO stack ?*/
+
+
+
+ function show_modal() {
+
+ let [element, parent] = detachable_elements[this.element.id];
+
+
+
+ tmpgrp = document.createElementNS(xmlns,"g");
tmpgrpattr = document.createAttribute("transform");
+ let [xcoord,ycoord] = this.coordinates;
+
let [xdest,ydest] = page_desc[current_visible_page].bbox;
tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")";
@@ -2403,9 +2584,27 @@
+ current_modal = [this.element.id, tmpgrp];
+
};
+ function end_modal() {
+
+ let [eltid, tmpgrp] = current_modal;
+
+ let [element, parent] = detachable_elements[this.element.id];
+
+
+
+ parent.removeChild(tmpgrp);
+
+
+
+ current_modal = undefined;
+
+ };
+
diff -r 4f3b130fd197 -r c8d923dd707f svghmi/svghmi.js
--- a/svghmi/svghmi.js Fri Apr 03 09:52:57 2020 +0200
+++ b/svghmi/svghmi.js Fri Apr 03 14:37:41 2020 +0200
@@ -474,11 +474,19 @@
let [keypadid, xcoord, ycoord] = keypads[valuetype];
console.log('XXX TODO : Edit value', path, valuetype, callback, initial, keypadid);
edit_callback = callback;
-
- let [element, parent] = detachable_elements[keypadid];
+ let widget = hmi_widgets[keypadid];
+ widget.start_edit(path, valuetype, callback, initial);
+};
+
+var current_modal; /* TODO stack ?*/
+
+function show_modal() {
+ let [element, parent] = detachable_elements[this.element.id];
+
tmpgrp = document.createElementNS(xmlns,"g");
tmpgrpattr = document.createAttribute("transform");
+ let [xcoord,ycoord] = this.coordinates;
let [xdest,ydest] = page_desc[current_visible_page].bbox;
tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")";
tmpgrp.setAttributeNode(tmpgrpattr);
@@ -486,5 +494,14 @@
tmpgrp.appendChild(element);
parent.appendChild(tmpgrp);
-};
-
+ current_modal = [this.element.id, tmpgrp];
+};
+
+function end_modal() {
+ let [eltid, tmpgrp] = current_modal;
+ let [element, parent] = detachable_elements[this.element.id];
+
+ parent.removeChild(tmpgrp);
+
+ current_modal = undefined;
+};
diff -r 4f3b130fd197 -r c8d923dd707f svghmi/widget_input.ysl2
--- a/svghmi/widget_input.ysl2 Fri Apr 03 09:52:57 2020 +0200
+++ b/svghmi/widget_input.ysl2 Fri Apr 03 14:37:41 2020 +0200
@@ -33,11 +33,11 @@
}
| },
| on_edit_click: function(opstr) {
- | edit_value("«path/@value»", "«path/@type»", this.edit_callback, this.last_val);
+ | edit_value("«path/@value»", "«path/@type»", this, this.last_val);
| },
| edit_callback: function(new_val) {
- | apply_hmi_value(this.indexes[0], opstr);
+ | apply_hmi_value(this.indexes[0], new_val);
if "$have_value"{
| this.value_elt.textContent = String(new_val);
/* TODO gray out value until refreshed */
diff -r 4f3b130fd197 -r c8d923dd707f svghmi/widget_keypad.ysl2
--- a/svghmi/widget_keypad.ysl2 Fri Apr 03 09:52:57 2020 +0200
+++ b/svghmi/widget_keypad.ysl2 Fri Apr 03 14:37:41 2020 +0200
@@ -1,6 +1,77 @@
// widget_keypad.ysl2
template "widget[@type='Keypad']", mode="widget_defs" {
+ param "hmi_element";
+ labels("Esc Enter BackSpace Keys Info Value");
+ optional_labels("Sign CapsLock Shift Space");
| 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')" {
+ | if(this.«.»_elt)
+ | this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()");
+ }
+ | },
+ | on_key_click: function(symbols) {
+ | var syms = symbols.split(" ");
+ | this.shift = this.caps;
+ | this.editstr += syms[this.shift?syms.length: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");
+ | },
+ | on_Space_click: function() {
+ | this.editstr += " ";
+ | console.log("Space");
+ | },
+ | caps: false,
+ | on_CapsLock_click: function() {
+ | this.caps = !this.caps;
+ | console.log("CapsLock");
+ | },
+ | shift: false,
+ | on_Shift_click: function() {
+ | this.shift = true;
+ | console.log("Shift");
+ | },
+ const "g", "$geometry[@Id = $hmi_element/@id]";
+ | coordinates: [«$g/@x», «$g/@y»],
+ | editstr: "",
+ | result_callback_obj: undefined,
+ | start_edit: function(info, valuetype, callback_obj, initial) {
+ | show_modal.call(this);
+ | this.editstr = initial;
+ | this.result_callback_obj = callback_obj;
+ | this.Info_elt.textContent = info;
+ | this.shift = false;
+ | this.caps = false;
+ | this.update();
+ | },
+ | update: function() {
+ | /* TODO Swith shift and capslock active/inactive elements */
+ | this.Value_elt.textContent = this.editstr;
| },
}
diff -r 4f3b130fd197 -r c8d923dd707f tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Fri Apr 03 09:52:57 2020 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Fri Apr 03 14:37:41 2020 +0200
@@ -124,17 +124,17 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:document-units="px"
- inkscape:current-layer="hmi0"
+ inkscape:current-layer="g2432"
showgrid="false"
units="px"
inkscape:zoom="0.35355339"
- inkscape:cx="-314.31196"
- inkscape:cy="282.25622"
- inkscape:window-width="1600"
- inkscape:window-height="886"
+ inkscape:cx="-418.67433"
+ inkscape:cy="-1206.7258"
+ inkscape:window-width="1800"
+ inkscape:window-height="836"
inkscape:window-x="0"
inkscape:window-y="27"
- inkscape:window-maximized="0"
+ inkscape:window-maximized="1"
showguides="true"
inkscape:guide-bbox="true" />
+/-
+ information
-
-
- Shift
-
-
-
- Shift
-
-
- Esc
@@ -2443,44 +2416,77 @@
y="38.296417"
style="text-align:start;text-anchor:start;stroke-width:0.47690967px">text
+ id="g421"
+ inkscape:label="inactive">
+
+ Shift
Shift
-
- Shift
+
+
+ Shift
+
Shift
+ information