author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 16 Oct 2024 12:18:14 +0200 | |
changeset 4030 | 45532de22b75 |
parent 3596 | 9c725829d8f0 |
permissions | -rw-r--r-- |
2908 | 1 |
// widget_keypad.ysl2 |
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("Keypad") { |
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 |
Keypad - to be written |
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 |
|| |
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 |
shortdesc > Keypad |
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 |
arg name="supported_types" accepts="string" > keypad can input those types |
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 |
|
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 |
|
2943
304e88bae115
SVGHMI: added more meaningful namespaces to emit javascript code from.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
15 |
emit "declarations:keypad" { |
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
16 |
| |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
17 |
| var keypads = { |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
18 |
foreach "$keypads_descs"{ |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
19 |
const "keypad_id","@id"; |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
20 |
foreach "arg"{ |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
21 |
const "g", "$geometry[@Id = $keypad_id]"; |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
22 |
| "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»], |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
23 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
24 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
25 |
| } |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
26 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
27 |
|
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:
3125
diff
changeset
|
28 |
widget_class("Keypad") |
3010 | 29 |
|| |
30 |
on_key_click(symbols) { |
|
31 |
var syms = symbols.split(" "); |
|
32 |
this.shift |= this.caps; |
|
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
33 |
if(this.virgin) |
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
34 |
this.editstr = ""; |
3010 | 35 |
this.editstr += syms[this.shift?syms.length-1:0]; |
36 |
this.shift = false; |
|
37 |
this.update(); |
|
38 |
} |
|
39 |
||
40 |
on_Esc_click() { |
|
41 |
end_modal.call(this); |
|
42 |
} |
|
43 |
||
44 |
on_Enter_click() { |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
45 |
let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr; |
3042
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
46 |
if(typeof coercedval == 'number' && isNaN(coercedval)){ |
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
47 |
// revert to initial so it explicitely shows input was ignored |
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
48 |
this.editstr = String(this.initial); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
49 |
this.update(); |
3042
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
50 |
} else { |
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
51 |
let callback_obj = this.result_callback_obj; |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
52 |
end_modal.call(this); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
53 |
callback_obj.edit_callback(coercedval); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
54 |
} |
3010 | 55 |
} |
56 |
||
57 |
on_BackSpace_click() { |
|
58 |
this.editstr = this.editstr.slice(0,this.editstr.length-1); |
|
59 |
this.update(); |
|
60 |
} |
|
61 |
||
62 |
on_Sign_click() { |
|
63 |
if(this.editstr[0] == "-") |
|
64 |
this.editstr = this.editstr.slice(1,this.editstr.length); |
|
65 |
else |
|
66 |
this.editstr = "-" + this.editstr; |
|
67 |
this.update(); |
|
68 |
} |
|
69 |
||
70 |
on_NumDot_click() { |
|
71 |
if(this.editstr.indexOf(".") == "-1"){ |
|
72 |
this.editstr += "."; |
|
73 |
this.update(); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
on_Space_click() { |
|
78 |
this.editstr += " "; |
|
79 |
this.update(); |
|
80 |
} |
|
81 |
||
82 |
caps = false; |
|
83 |
_caps = undefined; |
|
84 |
on_CapsLock_click() { |
|
85 |
this.caps = !this.caps; |
|
86 |
this.update(); |
|
87 |
} |
|
88 |
||
89 |
shift = false; |
|
90 |
_shift = undefined; |
|
91 |
on_Shift_click() { |
|
92 |
this.shift = !this.shift; |
|
93 |
this.caps = false; |
|
94 |
this.update(); |
|
95 |
} |
|
96 |
editstr = ""; |
|
97 |
_editstr = undefined; |
|
98 |
result_callback_obj = undefined; |
|
99 |
start_edit(info, valuetype, callback_obj, initial,size) { |
|
100 |
show_modal.call(this,size); |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
101 |
this.editstr = String(initial); |
3010 | 102 |
this.result_callback_obj = callback_obj; |
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
103 |
if(this.Info_elt) |
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
104 |
this.Info_elt.textContent = info; |
3010 | 105 |
this.shift = false; |
106 |
this.caps = false; |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
107 |
this.initial = initial; |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
108 |
|
3010 | 109 |
this.update(); |
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
110 |
this.virgin = true; |
3010 | 111 |
} |
112 |
||
113 |
update() { |
|
114 |
if(this.editstr != this._editstr){ |
|
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
115 |
this.virgin = false; |
3010 | 116 |
this._editstr = this.editstr; |
117 |
this.Value_elt.textContent = this.editstr; |
|
118 |
} |
|
3102
abb487b56911
SVGHMI: Fix bug in keypad leading to error messages in browser console when keypas has no Shift or CapsLock keys
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3047
diff
changeset
|
119 |
if(this.Shift_sub && this.shift != this._shift){ |
3010 | 120 |
this._shift = this.shift; |
3596
9c725829d8f0
SVGHMI: continue rework of Jump widget to cope with Enable Expressions.
Edouard Tisserant
parents:
3520
diff
changeset
|
121 |
set_activity_state(this.Shift_sub, this.shift); |
3010 | 122 |
} |
3102
abb487b56911
SVGHMI: Fix bug in keypad leading to error messages in browser console when keypas has no Shift or CapsLock keys
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3047
diff
changeset
|
123 |
if(this.CapsLock_sub && this.caps != this._caps){ |
3010 | 124 |
this._caps = this.caps; |
3596
9c725829d8f0
SVGHMI: continue rework of Jump widget to cope with Enable Expressions.
Edouard Tisserant
parents:
3520
diff
changeset
|
125 |
set_activity_state(this.CapsLock_sub, this.caps); |
3010 | 126 |
} |
127 |
} |
|
128 |
|| |
|
129 |
||
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:
3125
diff
changeset
|
130 |
widget_defs("Keypad") { |
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
131 |
labels("Esc Enter BackSpace Keys Value"); |
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
132 |
optional_labels("Sign Space NumDot Info"); |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2919
diff
changeset
|
133 |
activable_labels("CapsLock Shift"); |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2908
diff
changeset
|
134 |
| init: function() { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
135 |
foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" { |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
136 |
| id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')"); |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
137 |
} |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2919
diff
changeset
|
138 |
foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
139 |
| if(this.«.»_elt) |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
140 |
| this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()"); |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
141 |
} |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
142 |
| }, |
3010 | 143 |
| |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
144 |
const "g", "$geometry[@Id = $hmi_element/@id]"; |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
145 |
| coordinates: [«$g/@x», «$g/@y»], |
3508
14d696d7d54e
SVHMI: Keyboard: Replace untouched value when typing directly after open. Make info string (HMI variable name) optional.
Edouard Tisserant
parents:
3241
diff
changeset
|
146 |
| virgin: false, |
2908 | 147 |
} |