svghmi/widget_display.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 15 May 2024 18:50:26 +0200
changeset 3944 ebd25bbe5a73
parent 3524 27d298c6f961
permissions -rw-r--r--
Tests: fix wx_widgets.pytest/test_CustomIntCtrl.py
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_display.ysl2
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
     2
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     3
widget_desc("Display") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    If Display widget is a svg:text element, then text content is replaced by
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     7
    value of given variables, space separated.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     8
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     9
    Otherwise, if Display widget is a group containing a svg:text element
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    10
    labelled "format", then text content is replaced by printf-like formated
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    11
    string. In other words, if "format" labeled text is "%d %s %f", then 3
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    12
    variables paths are expected : HMI_IN, HMI_STRING and HMI_REAL.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    14
    In case Display widget is a svg::text element, it is also possible to give
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    15
    format string as first argument.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    17
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    18
    shortdesc > Printf-like formated text display
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    19
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    20
    arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    21
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    22
    path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    23
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    24
}
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    25
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    26
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3204
diff changeset
    27
widget_class("Display")
2998
e8f707d99dc3 SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
    28
    ||
e8f707d99dc3 SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
    29
        frequency = 5;
3008
dabad70db1bf SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2998
diff changeset
    30
        dispatch(value, oldval, index) {
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    31
            this.fields[index] = value;
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    32
            if(!this.ready){
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    33
                this.readyfields[index] = true;
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    34
                this.ready = this.readyfields.every(x=>x);
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    35
            }
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    36
            this.request_animate();
2998
e8f707d99dc3 SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
    37
        }
e8f707d99dc3 SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
    38
    ||
e8f707d99dc3 SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
    39
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3204
diff changeset
    40
widget_defs("Display") {
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    41
    const "format" optional_labels("format");
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    42
    const "has_format","string-length($format)>0";
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    43
    value "$format";
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    44
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    45
    if "$hmi_element[not(self::svg:text)] and not($has_format)"
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    46
        error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format"
3008
dabad70db1bf SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2998
diff changeset
    47
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    48
    const "field_initializer" foreach "path" {
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    49
        choose{
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    50
            when "@type='HMI_STRING'" > ""
3065
c369a742443d SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents: 3035
diff changeset
    51
            otherwise > 0
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    52
        }
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    53
        if "position()!=last()" > ,
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    54
    }
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3008
diff changeset
    55
    |     fields: [«$field_initializer»],
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    56
    const "readyfield_initializer" foreach "path" {
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    57
        > false
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    58
        if "position()!=last()" > ,
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    59
    }
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    60
    |     readyfields: [«$readyfield_initializer»],
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    61
    |     ready: false,
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    62
    |     animate: function(){
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    63
    choose {
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    64
        when "$has_format" {
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    65
    |       if(this.format_elt.getAttribute("lang")) {
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    66
    |           this.format = svg_text_to_multiline(this.format_elt);
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    67
    |           this.format_elt.removeAttribute("lang");
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    68
    |       }
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    69
    |       let str = vsprintf(this.format,this.fields);
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    70
    |       multiline_to_svg_text(this.format_elt, str, !this.ready);
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    71
        }
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    72
        otherwise {
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    73
    |       let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    74
    |       multiline_to_svg_text(this.element, str, !this.ready);
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    75
        }
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    76
    }
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    77
    |     },
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    78
    |
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    79
    |     init: function() {
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    80
    if "$has_format" {
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    81
    |       this.format = svg_text_to_multiline(this.format_elt);
3524
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    82
    }
27d298c6f961 SVGHMI: force initial state of Display widget to empty string.
Edouard Tisserant
parents: 3360
diff changeset
    83
    |       this.animate();
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    84
    |     },
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
    85
}