svghmi/widget_input.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 29 Dec 2020 15:38:31 +0100
branchsvghmi
changeset 3101 4cbf024a6640
parent 3100 c51f9cf365c6
child 3118 e704b0487515
permissions -rw-r--r--
SVGHMI: cosmetic changes
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
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
    13
         overshot(new_val, max) {
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
    14
             this.last_display = "max: "+max;
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
    15
             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
    16
         }
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
    17
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
         undershot(new_val, min) {
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
             this.last_display = "min: "+min;
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
             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
    21
         }
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
    22
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
    23
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    24
    }
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    25
||
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    26
}
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    27
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
    28
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
    29
    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
    30
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    31
    const "key_pos_elt" optional_labels("key_pos");
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    32
    value "$key_pos_elt";
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    33
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    34
    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
    35
    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
    36
    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
    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
    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
    39
    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
    40
    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
    41
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
    42
    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
    43
    |     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
    44
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
    45
    |     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
    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
    if "$have_edit"
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    48
    |         this.last_val = 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
    49
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
    50
    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
    51
    |         this.last_display = 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
    52
    |         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
    53
    }
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
    54
    |     },
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
    55
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
    56
    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
    57
    |     animate: function(){
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
    58
    |         this.value_elt.textContent = String(this.last_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
    59
    |     },
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
    60
    }
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    61
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
    62
    |     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
    63
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    64
    if "$have_edit" {
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    65
    |         this.edit_elt.onclick = () => edit_value(
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    66
    |             "«path/@value»", "«path/@type»",
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    67
    |             this, this.last_val, 
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    68
        choose {
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    69
            when "string-length($key_pos_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
    70
    |             this.key_pos_elt.getBBox()
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    71
            otherwise
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    72
    |             undefined
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    73
        }
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    74
    |         );
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
    75
    }
3094
3e184f1e1012 SVGHMI: almost rewrote Input widget to make it new class based style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3034
diff changeset
    76
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
    77
    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
    78
    |         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
    79
    }
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    80
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    81
    |     },
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
    82
}