author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 10 Sep 2021 14:44:20 +0200 | |
branch | wxPython4 |
changeset 3312 | 2c0511479b18 |
parent 3241 | fe945f1f48b7 |
child 3478 | c04c6db09eff |
permissions | -rw-r--r-- |
2977 | 1 |
// widget_tooglebutton.ysl2 |
2 |
||
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
3 |
|
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
|
4 |
widget_desc("ToggleButton") { |
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 |
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
|
6 |
|| |
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 |
Button widget takes one boolean variable path, and reflect current true |
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 |
or false value by showing "active" or "inactive" labeled 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
|
9 |
respectively. Clicking or touching button toggles variable. |
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 |
|| |
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 |
|
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 |
shortdesc > Toggle button reflecting given boolean variable |
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 |
path name="value" accepts="HMI_BOOL" > Boolean variable |
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 |
|
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 |
|
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:
3219
diff
changeset
|
18 |
widget_class("ToggleButton") { |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
19 |
|| |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
20 |
frequency = 5; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
21 |
state = 0; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
22 |
active_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
23 |
inactive_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
24 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
25 |
dispatch(value) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
26 |
this.state = value; |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
27 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
28 |
this.request_animate(); |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
29 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
30 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
31 |
on_click(evt) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
32 |
//toggle state and apply |
3219 | 33 |
this.state = this.state ? false : true; |
3018 | 34 |
this.apply_hmi_value(0, this.state); |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
35 |
|
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
36 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
37 |
this.request_animate(); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
38 |
} |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
39 |
|
3219 | 40 |
activate(val) { |
41 |
let [active, inactive] = val ? ["none",""] : ["", "none"]; |
|
42 |
if (this.active_elt) |
|
43 |
this.active_elt.style.display = active; |
|
44 |
if (this.inactive_elt) |
|
45 |
this.inactive_elt.style.display = inactive; |
|
46 |
} |
|
47 |
||
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
48 |
animate(){ |
3219 | 49 |
// redraw toggle button on screen refresh |
50 |
this.activate(this.state); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
51 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
52 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
53 |
init() { |
3219 | 54 |
this.activate(false); |
55 |
this.element.onclick = (evt) => this.on_click(evt); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
56 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
57 |
|| |
3024 | 58 |
} |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
59 |
|
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:
3219
diff
changeset
|
60 |
widget_defs("ToggleButton") { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
61 |
optional_labels("active inactive"); |
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:
2977
diff
changeset
|
62 |
} |