2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-13 01:02:39 -05:00
|
|
|
var mainwin *ui.Window
|
|
|
|
var maintab *ui.Tab
|
|
|
|
var tabcount int
|
2019-05-08 15:04:18 -05:00
|
|
|
|
2019-05-13 01:02:39 -05:00
|
|
|
var Width int
|
|
|
|
var Height int
|
2019-05-08 15:04:18 -05:00
|
|
|
|
2019-05-12 20:05:17 -05:00
|
|
|
type InputData struct {
|
|
|
|
Index int
|
|
|
|
CellType string
|
|
|
|
Heading string
|
|
|
|
Color string
|
|
|
|
}
|
|
|
|
|
2019-05-08 15:04:18 -05:00
|
|
|
func setupUI() {
|
2019-05-13 01:02:39 -05:00
|
|
|
mainwin = ui.NewWindow("Cloud Control Panel", Width, Height, false)
|
2019-05-08 15:04:18 -05:00
|
|
|
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)
|
|
|
|
|
|
|
|
tabcount = 0
|
|
|
|
mainwin.Show()
|
|
|
|
}
|
|
|
|
|
2019-05-10 03:26:55 -05:00
|
|
|
func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
|
|
|
|
mytab.Append("Cloud Info", newbox)
|
|
|
|
mytab.SetMargined(tabOffset, true)
|
2019-05-10 01:25:55 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func initColumnNames(mh *TableData, cellJWC string, junk string) {
|
2019-05-08 18:50:52 -05:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) *TableData {
|
|
|
|
mh := new(TableData)
|
2019-05-12 14:54:11 -05:00
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.RowCount = rowcount
|
|
|
|
mh.Rows = make([]RowData, mh.RowCount)
|
2019-05-12 14:54:11 -05:00
|
|
|
|
|
|
|
tmpBTindex := 0
|
2019-05-13 02:30:38 -05:00
|
|
|
humanID := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
2019-05-13 02:30:38 -05:00
|
|
|
log.Println("key, foo =", key, foo)
|
|
|
|
// log.Println("mh.Cells =", mh.Cells)
|
|
|
|
// log.Println("mh.Human =", mh.Human)
|
2019-05-13 02:08:59 -05:00
|
|
|
|
2019-05-13 02:30:38 -05:00
|
|
|
initColumnNames(mh, foo.CellType, foo.Heading)
|
2019-05-13 02:08:59 -05:00
|
|
|
|
|
|
|
parts[key].Index = humanID
|
|
|
|
humanID += 1
|
|
|
|
|
|
|
|
if (foo.CellType == "BG") {
|
|
|
|
initRowBTcolor (mh, tmpBTindex, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
|
|
|
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
|
|
|
initRowTextColorColumn(mh, 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, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
2019-05-13 02:30:38 -05:00
|
|
|
tmpBTindex = 0
|
|
|
|
humanID = 0
|
2019-05-12 14:54:11 -05:00
|
|
|
|
|
|
|
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
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
|
|
|
|
&ui.TableTextColumnOptionalParams{
|
|
|
|
ColorModelColumn: tmpBTindex + 1,
|
|
|
|
});
|
2019-05-12 14:54:11 -05:00
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
|
|
|
tmpBTindex += 1
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
|
2019-05-12 14:54:11 -05:00
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mytab.Append(name, table)
|
|
|
|
mytab.SetMargined(mytabcount, true)
|
2019-05-12 17:11:32 -05:00
|
|
|
|
|
|
|
return mh
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-08 15:09:17 -05:00
|
|
|
func DoGUI() {
|
2019-05-13 01:02:39 -05:00
|
|
|
for {
|
|
|
|
ui.Main(setupUI)
|
|
|
|
log.Println("GUI exited. Not sure what to do here. os.Exit() ?")
|
|
|
|
}
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|