1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
package gui
// Common actions for widgets like 'Enable' or 'Hide'
import (
"regexp"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
// functions for handling text related GUI elements
func (n *Node) Show() *Node {
if ! n.hidden {
a := newAction(n, widget.Show)
sendAction(a)
}
return n
}
func (n *Node) Hide() *Node {
if ! n.hidden {
a := newAction(n, widget.Hide)
sendAction(a)
}
return n
}
func (n *Node) Enable() *Node {
if ! n.hidden {
a := newAction(n, widget.Enable)
sendAction(a)
}
return n
}
func (n *Node) Disable() *Node {
if ! n.hidden {
a := newAction(n, widget.Disable)
sendAction(a)
}
return n
}
func (n *Node) Add(str string) {
log.Log(GUI, "gui.Add() value =", str)
n.value = str
if ! n.hidden {
a := newAction(n, widget.Add)
sendAction(a)
}
}
func (n *Node) AddText(str string) {
log.Log(CHANGE, "AddText() value =", str)
n.value = str
if ! n.hidden {
a := newAction(n, widget.AddText)
sendAction(a)
}
}
func (n *Node) SetNext(w int, h int) {
n.NextW = w
n.NextH = h
log.Info("SetNext() w,h =", n.NextW, n.NextH)
}
func (n *Node) AppendText(str string) {
tmp := widget.GetString(n.value) + str
n.value = tmp
if ! n.hidden {
a := newAction(n, widget.SetText)
sendAction(a)
}
}
// THESE TWO FUNCTIONS ARE TERRIBLY NAMED AND NEED TO BE FIXED
// 5 seconds worth of ideas:
// Value() ?
// Progname() Reference() ?
// get a string from the widget
func (n *Node) GetText() string {
if ! n.Ready() { return "" }
return widget.GetString(n.value)
}
// get a string from the widget
func (n *Node) GetInt() int {
if ! n.Ready() { return -1 }
return widget.GetInt(n.value)
}
// get a string from the widget
func (n *Node) GetBool() bool {
if ! n.Ready() { return false}
return widget.GetBool(n.value)
}
// should get the reference name used for programming and debugging
// myButton = myGroup.NewButton("hit ball", nil).SetName("HIT")
// myButton.GetName() should return "HIT"
// n = Find("HIT") should return myButton
func (n *Node) GetName() string {
if ! n.Ready() { return "" }
return n.progname
}
/*
// string handling examples that might be helpful for normalizeInt()
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
for _, username := range []string{"userone", "user2", "user-three"} {
if !isAlpha(username) {
log.Log(GUI, "%q is not valid\n", username)
}
}
const alpha = "abcdefghijklmnopqrstuvwxyz"
func alphaOnly(s string) bool {
for _, char := range s {
if !strings.Contains(alpha, strings.ToLower(string(char))) {
return false
}
}
return true
}
*/
func normalizeInt(s string) string {
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
reg, err := regexp.Compile("[^0-9]+")
if err != nil {
log.Log(GUI, "normalizeInt() regexp.Compile() ERROR =", err)
return s
}
clean := reg.ReplaceAllString(s, "")
log.Log(GUI, "normalizeInt() s =", clean)
return clean
}
func commonCallback(n *Node) {
// TODO: make all of this common code to all the widgets
// This might be common everywhere finally (2023/03/01)
if (n.Custom == nil) {
log.Log(CHANGE, "Not Running n.Custom(n) == nil")
} else {
log.Log(CHANGE, "Running n.Custom(n)")
n.Custom()
}
}
func (n *Node) Margin() *Node {
n.margin = true
if ! n.hidden {
a := newAction(n, widget.Margin)
sendAction(a)
}
return n
}
func (n *Node) Unmargin() *Node {
n.margin = false
if ! n.hidden {
a := newAction(n, widget.Unmargin)
sendAction(a)
}
return n
}
func (n *Node) Pad() *Node {
n.pad = true
if ! n.hidden {
a := newAction(n, widget.Pad)
sendAction(a)
}
return n
}
func (n *Node) Unpad() *Node {
n.pad = false
if ! n.hidden {
a := newAction(n, widget.Unpad)
sendAction(a)
}
return n
}
func (n *Node) Expand() *Node {
n.expand = true
if ! n.hidden {
a := newAction(n, widget.Pad)
a.Expand = true
sendAction(a)
}
return n
}
// is this better?
// yes, this is better. it allows Internationalization very easily
// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
// myFunnyWindow = myGui.NewWindow("Hello").Standard().SetText("Hola")
/*
func (n *Node) Window(title string) *Node {
log.Warn("Window()", n)
return n.NewWindow(title)
}
*/
func (n *Node) ProgName() string {
if ! n.Ready() { return "" }
return n.progname
}
func (n *Node) Ready() bool {
if n == nil {
log.Warn("Ready() got node == nil")
// TODO: figure out if you can identify the code trace to help find the root cause
return false
}
return true
}
// This should not really do anything. as per the docs, the "Standard()" way
// should be the default way
/*
func (n *Node) Standard() *Node {
log.Warn("Standard() not implemented yet")
return n
}
func (n *Node) SetMargin() *Node {
log.Warn("DoMargin() not implemented yet")
return n
}
*/
|