svghmi/widget_input.ysl2
author Edouard Tisserant
Thu, 20 Aug 2020 14:12:49 +0200
branchsvghmi
changeset 3032 2f6dfb99d094
parent 3010 893cc309f5e2
child 3034 793ce2117258
permissions -rw-r--r--
SVGHMI: Behave when project path include spaces, and make more understandable error in case of problem extracting geometry with inkscape.
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
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
     3
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
     4
    param "hmi_element";
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 3004
diff changeset
     5
    optional_labels("key_pos");
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
     6
    const "value_elt" {
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
     7
        optional_labels("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
     8
    }
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
     9
    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
    10
    value "$value_elt";
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
    11
    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
    12
    |     frequency: 5,
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    13
    |     last_val: undefined,
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
    14
    |     dispatch: function(value) {
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    15
    |         this.last_val = 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
    16
    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
    17
    |         this.value_elt.textContent = String(value);
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
    18
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
    19
    |     },
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
    20
    const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
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
    21
    |     init: function() {
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
    22
    if "$edit_elt_id" {
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    23
    |         id("«$edit_elt_id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_edit_click()");
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
    24
    }
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
    25
    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
2910
1a1caf71b1cc SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents: 2883
diff changeset
    26
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].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
    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
    |     },
2910
1a1caf71b1cc SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents: 2883
diff changeset
    29
    |     on_op_click: function(opstr) {
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3001
diff changeset
    30
    |         let new_val = this.change_hmi_value(0, opstr);
2921
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    31
    //     if "$have_value"{
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    32
    // |         this.value_elt.textContent = String(new_val);
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    33
    //           /* TODO gray out value until refreshed */
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    34
    //     }
2910
1a1caf71b1cc SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents: 2883
diff changeset
    35
    |     },
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    36
    |     on_edit_click: function(opstr) {
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 3004
diff changeset
    37
    |         var size = (typeof this.key_pos_elt !== 'undefined') ?  this.key_pos_elt.getBBox() : undefined
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 3004
diff changeset
    38
    |         edit_value("«path/@value»", "«path/@type»", this, this.last_val,size);
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    39
    |     },
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    40
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    41
    |     edit_callback: function(new_val) {
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3001
diff changeset
    42
    |         this.apply_hmi_value(0, new_val);
2921
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    43
    //     if "$have_value"{
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    44
    // |         this.value_elt.textContent = String(new_val);
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    45
    //           /* TODO gray out value until refreshed */
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    46
    //     }
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    47
    |     },
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
    48
}