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
|
package gui
import "log"
import "time"
// import "fmt"
import "github.com/gookit/config"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"
var mainwin *ui.Window
var maintab *ui.Tab
var tabcount int
var jcarrButton *ui.Button
var jcarrEntry *ui.MultilineEntry
type InputData struct {
Index int
CellType string
Heading string
Color string
}
func setupUI() {
mainwin = ui.NewWindow("Cloud Control Panel", config.Int("width"), config.Int("height"), false)
mainwin.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
ui.OnShouldQuit(func() bool {
mainwin.Destroy()
return true
})
maintab = ui.NewTab()
mainwin.SetChild(maintab)
mainwin.SetMargined(true)
// maintab.Append("List examples", makeNumbersPage())
tabcount = 0
// maintab.SetMargined(tabcount, true)
/*
maintab.Append("Choosers examples", makeDataChoosersPage())
tabcount += 1
maintab.SetMargined(tabcount, true)
maintab.Append("Group examples", makeGroupEntries())
tabcount += 1
maintab.SetMargined(tabcount, true)
*/
mainwin.Show()
}
func AddChoosersDemo() {
maintab.Append("Choosers examples", makeDataChoosersPage())
maintab.SetMargined(tabcount, true)
tabcount += 1
}
func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
mytab.Append("Cloud Info", newbox)
mytab.SetMargined(tabOffset, true)
}
// This hangs on GTK
func AddEntriesDemo() {
maintab.Append("Group examples", makeGroupEntries())
tabcount += 1
maintab.SetMargined(tabcount, true)
}
func initColumnNames(mh *TableData, cellJWC string, junk string) {
if (cellJWC == "BG") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
} else if (cellJWC == "BUTTON") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
} else if (cellJWC == "TEXTCOLOR") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
} else if (cellJWC == "TEXT") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
} else {
panic("I don't know what this is in initColumnNames")
}
}
func initRow(mh *TableData, row int, parts []InputData) {
tmpBTindex := 0
for key, foo := range parts {
log.Println(key, foo)
if (foo.CellType == "BG") {
initRowBTcolor (mh, row, tmpBTindex, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "BUTTON") {
initRowButtonColumn (mh, row, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "TEXTCOLOR") {
initRowTextColorColumn(mh, row, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
tmpBTindex += 2
} else if (foo.CellType == "TEXT") {
initRowTextColumn (mh, row, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else {
panic("I don't know what this is in initColumnNames")
}
}
}
func AddSampleTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) {
mh := new(TableData)
mh.RowCount = rowcount
mh.Rows = make([]RowData, mh.RowCount)
// This is the standard callback function from libUI when the user does something
mh.libUIevent = defaultSetCellValue
tmpBTindex := 0
for key, foo := range parts {
log.Println(key, foo)
initColumnNames(mh, foo.CellType, foo.Heading)
}
time.Sleep(1 * 1000 * 1000 * 1000)
for row := 0; row < mh.RowCount; row++ {
initRow(mh, row, parts)
}
log.Println(mh)
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: tmpBTindex,
})
for key, foo := range parts {
log.Println(key, foo)
initColumnNames(mh, foo.CellType, foo.Heading)
if (foo.CellType == "BG") {
} else if (foo.CellType == "BUTTON") {
tmpBTindex += 1
table.AppendButtonColumn("button3", tmpBTindex, ui.TableModelColumnAlwaysEditable)
} else if (foo.CellType == "TEXTCOLOR") {
tmpBTindex += 1
appendTextColorColumn (mh, table, tmpBTindex, tmpBTindex + 1, "testcolor")
tmpBTindex += 1
} else if (foo.CellType == "TEXT") {
tmpBTindex += 1
appendTextColumn (mh, table, tmpBTindex, "jwc1col")
} else {
panic("I don't know what this is in initColumnNames")
}
}
mytab.Append(name, table)
mytab.SetMargined(mytabcount, true)
}
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) *TableData {
mh := new(TableData)
mh.RowCount = rowcount
mh.Rows = make([]RowData, mh.RowCount)
// This is the standard callback function from libUI when the user does something
mh.libUIevent = defaultSetCellValue
tmpBTindex := 0
for key, foo := range parts {
log.Println(key, foo)
initColumnNames(mh, foo.CellType, foo.Heading)
}
for row := 0; row < mh.RowCount; row++ {
initRow(mh, row, parts)
}
log.Println(mh)
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: tmpBTindex,
})
for key, foo := range parts {
log.Println(key, foo)
initColumnNames(mh, foo.CellType, foo.Heading)
if (foo.CellType == "BG") {
} else if (foo.CellType == "BUTTON") {
tmpBTindex += 1
table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
} else if (foo.CellType == "TEXTCOLOR") {
tmpBTindex += 1
appendTextColorColumn (mh, table, tmpBTindex, tmpBTindex + 1, foo.Heading)
tmpBTindex += 1
} else if (foo.CellType == "TEXT") {
tmpBTindex += 1
appendTextColumn (mh, table, tmpBTindex, foo.Heading)
} else {
panic("I don't know what this is in initColumnNames")
}
}
mytab.Append(name, table)
mytab.SetMargined(mytabcount, true)
return mh
}
func DoGUI() {
ui.Main(setupUI)
log.Println("GUI exited. Not sure what to do here. os.Exit() ?")
// not sure how to pass this back to the main program
// onExit()
}
|