svghmi/widget_button.ysl2
author usveticic
Thu, 24 Sep 2020 11:52:40 +0200
branchsvghmi
changeset 3059 e0db3f6a5f39
parent 3058 6ea4b7e1a9ed
child 3062 9ec338a99a18
permissions -rw-r--r--
Button and toggle reworked to use animate and dispatch
Slider added buttons to incremente/decrement by 1
Init for animate widget
Changed test svg and plc
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     1
// widget_button.ysl2
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
3024
Edouard Tisserant
parents: 3018
diff changeset
     3
template "widget[@type='Button']", mode="widget_class"{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     4
    ||
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     5
    class ButtonWidget extends Widget{
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     6
        frequency = 5;
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     7
        state_plc = 0;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     8
        state_hmi = 0;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
     9
        plc_lock = false;
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    10
        active_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    11
        inactive_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    12
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    13
        dispatch(value) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    14
            this.state_plc = value;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    15
            if(this.plc_lock){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    16
                if(this.state_plc == 1){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    17
                    this.apply_hmi_value(0, 0);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    18
                    this.plc_lock = false;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    19
                }
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    20
            }
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    21
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    22
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    23
            this.state_hmi = this.state_plc;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    24
            this.request_animate();
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    25
        }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    26
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    27
        animate(){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    28
           // redraw button on screen refresh
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    29
           if (this.state_hmi) {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    30
               this.active_elt.setAttribute("style", this.active_style);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    31
               this.inactive_elt.setAttribute("style", "display:none");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    32
           } else {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    33
               this.inactive_elt.setAttribute("style", this.inactive_style);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    34
               this.active_elt.setAttribute("style", "display:none");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    35
           }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    36
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    37
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    38
        on_click(evt) {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    39
            //set state and apply if plc is 0
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    40
            this.plc_lock = true;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    41
            if(this.state_plc == 0){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    42
                this.apply_hmi_value(0, 1);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    43
            }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    44
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    45
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    46
        }
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    47
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    48
        on_press(evt) {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    49
            //set graphic
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    50
            this.state_hmi = 1;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    51
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    52
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    53
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    54
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    55
         init() {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    56
            this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    57
            this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    58
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    59
            if (this.active_style && this.inactive_style) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    60
                this.active_elt.setAttribute("style", "display:none");
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    61
                this.inactive_elt.setAttribute("style", this.inactive_style);
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    62
            }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    63
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    64
            this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    65
            this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)");
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    66
         }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    67
    }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    68
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    69
}
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    70
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    71
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    72
template "widget[@type='Button']", mode="widget_defs" {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    73
    param "hmi_element";
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    74
    optional_labels("active inactive");
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    75
    |,
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    76
}