svghmi/widget_input.ysl2
author Edouard Tisserant
Mon, 15 Mar 2021 11:25:24 +0100
branchsvghmi
changeset 3188 c173452bf894
parent 3155 99ce78ddd353
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     1
// widget_input.ysl2
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2763
diff changeset
     2
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     3
template "widget[@type='Input']", mode="widget_class"{
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     4
||
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     5
    class InputWidget extends Widget{
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     6
         on_op_click(opstr) {
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3100
diff changeset
     7
             this.change_hmi_value(0, opstr);
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     8
         }
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
     9
         edit_callback(new_val) {
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    10
             this.apply_hmi_value(0, new_val);
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    11
         }
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    12
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    13
         is_inhibited = false;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    14
         alert(msg){
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    15
             this.is_inhibited = true;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    16
             this.display = msg;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    17
             setTimeout(() => this.stopalert(), 1000);
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    18
             this.request_animate();
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    19
         }
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    20
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    21
         stopalert(){
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    22
             this.is_inhibited = false;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    23
             this.display = this.last_value;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    24
             this.request_animate();
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    25
         }
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    26
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    27
         overshot(new_val, max) {
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    28
             this.alert("max");
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    29
         }
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    30
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    31
         undershot(new_val, min) {
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    32
             this.alert("min");
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    33
         }
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    34
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    35
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    36
    }
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    37
||
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    38
}
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    39
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    40
template "widget[@type='Input']", mode="widget_defs" {
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    41
    param "hmi_element";
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    42
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    43
    const "value_elt" optional_labels("value");
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    44
    const "have_value","string-length($value_elt)>0";
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    45
    value "$value_elt";
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    46
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    47
    const "edit_elt" optional_labels("edit");
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    48
    const "have_edit","string-length($edit_elt)>0";
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    49
    value "$edit_elt";
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    50
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    51
    if "$have_value"
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    52
    |     frequency: 5,
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    53
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    54
    |     dispatch: function(value) {
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    55
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    56
3155
99ce78ddd353 SVGHMI: finally found why HMI:Input wasnt't initializing properly: vsprintf takes a list. Also, removed intermediate variable last_val, since edit_value() works on strings anyhow, and in case of formated floats, it is better to workl on already formated value.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3153
diff changeset
    57
    if "$have_value or $have_edit" {
3153
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    58
        choose{
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    59
            when "count(arg) = 1" {
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    60
    |         this.last_value = vsprintf("«arg[1]/@value»", [value]);
3153
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    61
            }
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    62
            otherwise {
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    63
    |         this.last_value = value;
3153
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    64
            }
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    65
        }
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    66
    |         if(!this.is_inhibited){
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    67
    |             this.display = this.last_value;
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    68
    if "$have_value" {
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    69
    |             this.request_animate();
3155
99ce78ddd353 SVGHMI: finally found why HMI:Input wasnt't initializing properly: vsprintf takes a list. Also, removed intermediate variable last_val, since edit_value() works on strings anyhow, and in case of formated floats, it is better to workl on already formated value.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3153
diff changeset
    70
    }
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    71
    |         }
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    72
    }
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    73
    |     },
2836
ce6cecdb7320 SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents: 2834
diff changeset
    74
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    75
    if "$have_value" {
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    76
    |     animate: function(){
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    77
    |         this.value_elt.textContent = String(this.display);
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    78
    |     },
3100
c51f9cf365c6 SVGHMI: Input widget overrides undershot() and overshot() methods to display "min: xxx" or "max: xxx" when user input goes out of given range.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3094
diff changeset
    79
    }
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    80
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    81
    |     init: function() {
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    82
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    83
    if "$have_edit" {
3188
c173452bf894 SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
Edouard Tisserant
parents: 3155
diff changeset
    84
    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_value);
3153
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    85
        if "$have_value" {
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    86
    |         this.value_elt.style.pointerEvents = "none";
671283404554 Allow printf-like formating in HMI:Input, usefull for example when dealing with floating point numbers.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3118
diff changeset
    87
        }
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    88
    }
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    89
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    90
    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    91
    |         id("«@id»").onclick = () => this.on_op_click("«func:escape_quotes(@inkscape:label)»");
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    92
    }
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    93
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    94
    |     },
2753
9a7e12e96399 SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff changeset
    95
}