author | Edouard Tisserant |
Mon, 19 Oct 2020 10:15:26 +0200 | |
branch | svghmi |
changeset 3065 | c369a742443d |
parent 3062 | 9ec338a99a18 |
child 3085 | 6b1b23971960 |
permissions | -rw-r--r-- |
2944 | 1 |
// widget_button.ysl2 |
2 |
||
3024 | 3 |
template "widget[@type='Button']", mode="widget_class"{ |
3009 | 4 |
|| |
5 |
class ButtonWidget extends Widget{ |
|
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 | 10 |
active_style = undefined; |
11 |
inactive_style = undefined; |
|
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(){ |
3062 | 28 |
if (this.active_style && this.inactive_style) { |
29 |
// redraw button on screen refresh |
|
30 |
if (this.state_hmi) { |
|
31 |
this.active_elt.setAttribute("style", this.active_style); |
|
32 |
this.inactive_elt.setAttribute("style", "display:none"); |
|
33 |
} else { |
|
34 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
35 |
this.active_elt.setAttribute("style", "display:none"); |
|
36 |
} |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
37 |
} |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
38 |
} |
3009 | 39 |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
40 |
on_click(evt) { |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
41 |
//set state and apply if plc is 0 |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
42 |
this.plc_lock = true; |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
43 |
if(this.state_plc == 0){ |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
44 |
this.apply_hmi_value(0, 1); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
45 |
} |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
46 |
//redraw button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
47 |
this.request_animate(); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
48 |
} |
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
49 |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
50 |
on_press(evt) { |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
51 |
//set graphic |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
52 |
this.state_hmi = 1; |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
53 |
//redraw button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
54 |
this.request_animate(); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
55 |
} |
3009 | 56 |
|
57 |
init() { |
|
58 |
this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
|
59 |
this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
|
60 |
||
61 |
if (this.active_style && this.inactive_style) { |
|
62 |
this.active_elt.setAttribute("style", "display:none"); |
|
63 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
64 |
} |
|
65 |
||
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
66 |
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
|
67 |
this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)"); |
3009 | 68 |
} |
69 |
} |
|
70 |
|| |
|
3024 | 71 |
} |
3009 | 72 |
|
73 |
||
2976
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
74 |
template "widget[@type='Button']", mode="widget_defs" { |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
75 |
param "hmi_element"; |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
76 |
optional_labels("active inactive"); |
3009 | 77 |
|, |
3000
a9a45977bac0
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2976
diff
changeset
|
78 |
} |