2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "log"
|
2019-05-31 11:01:46 -05:00
|
|
|
import "fmt"
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 21:29:08 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-01 01:45:53 -05:00
|
|
|
// THIS IS CLEAN (all that is left is the 'createAddVmBox')
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func InitColumns(mh *TableData, parts []TableColumnData) {
|
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)
|
2019-05-13 02:08:59 -05:00
|
|
|
|
|
|
|
parts[key].Index = humanID
|
|
|
|
humanID += 1
|
|
|
|
|
|
|
|
if (foo.CellType == "BG") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowBTcolor (mh, tmpBTindex, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
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") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
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:46:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 22:14:15 -05:00
|
|
|
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData, account *pb.Account) *TableData {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh := new(TableData)
|
|
|
|
|
|
|
|
mh.RowCount = rowcount
|
|
|
|
mh.Rows = make([]RowData, mh.RowCount)
|
|
|
|
|
|
|
|
InitColumns(mh, parts)
|
2019-05-12 14:54:11 -05:00
|
|
|
|
|
|
|
model := ui.NewTableModel(mh)
|
|
|
|
table := ui.NewTable(
|
|
|
|
&ui.TableParams{
|
|
|
|
Model: model,
|
2019-05-13 02:46:11 -05:00
|
|
|
RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
|
2019-05-12 14:54:11 -05:00
|
|
|
})
|
|
|
|
|
2019-05-13 02:46:11 -05:00
|
|
|
tmpBTindex := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
|
|
|
log.Println(key, foo)
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
var gb *GuiBox
|
|
|
|
gb = new(GuiBox)
|
|
|
|
|
|
|
|
gb.EntryMap = make(map[string]*GuiEntry)
|
|
|
|
gb.EntryMap["test"] = nil
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
2019-05-31 19:37:53 -05:00
|
|
|
gb.UiBox = vbox
|
|
|
|
gb.W = gw
|
|
|
|
gw.BoxMap[name] = gb
|
2019-05-31 22:14:15 -05:00
|
|
|
mh.Box = gb
|
2019-05-21 16:39:46 -05:00
|
|
|
|
|
|
|
vbox.Append(table, true)
|
2019-05-31 19:37:53 -05:00
|
|
|
gw.UiTab.Append(name, vbox)
|
2019-05-29 15:11:08 -05:00
|
|
|
// mytab.SetMargined(mytabcount, true)
|
2019-05-12 17:11:32 -05:00
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox.Append(ui.NewVerticalSeparator(), false)
|
|
|
|
|
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hbox.Append(a.B, false)
|
2019-05-21 16:39:46 -05:00
|
|
|
|
|
|
|
vbox.Append(hbox, false)
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
return mh
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 11:01:46 -05:00
|
|
|
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
2019-05-31 19:37:53 -05:00
|
|
|
ui.MsgBox(gw.UiWindow, msg1, msg2)
|
2019-05-24 18:19:22 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 11:01:46 -05:00
|
|
|
func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
2019-05-31 19:37:53 -05:00
|
|
|
ui.MsgBoxError(gw.UiWindow, msg1, msg2)
|
2019-05-24 18:19:22 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 11:02:35 -05:00
|
|
|
// This is the default mouse click handler
|
|
|
|
// Every mouse click that hasn't been assigned to
|
|
|
|
// something specific will fall into this routine
|
|
|
|
// By default, all it runs is the call back to
|
|
|
|
// the main program that is using this library
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
// This is one of the routines that is called from the
|
|
|
|
// defaultButtonClick() below when the button is found
|
|
|
|
// in the AllButtons %map
|
|
|
|
// TODO: clean up the text above
|
2019-05-26 04:19:09 -05:00
|
|
|
// TODO: remove this all together going only to main()
|
2019-05-30 10:55:54 -05:00
|
|
|
func mouseClick(b *GuiButton) {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("gui.mouseClick() START")
|
2019-05-26 04:19:09 -05:00
|
|
|
if (b == nil) {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tgui.mouseClick() START b = nil")
|
2019-05-26 04:19:09 -05:00
|
|
|
} else {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tgui.mouseClick() START b.Action =", b.Action)
|
2019-05-24 21:45:03 -05:00
|
|
|
if (b.Action == "createAddVmBox") {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tgui.mouseClick() createAddVmBox for b =", b)
|
2019-05-31 22:14:15 -05:00
|
|
|
createAddVmBox(b.GW, b)
|
2019-05-24 18:19:22 -05:00
|
|
|
return
|
|
|
|
}
|
2019-06-01 00:28:02 -05:00
|
|
|
/*
|
2019-05-26 17:03:20 -05:00
|
|
|
if (b.Action == "WINDOW CLOSE") {
|
|
|
|
b.W.Hide()
|
|
|
|
// TODO: fix this (seems to crash? maybe because we are in the button here?)
|
|
|
|
// b.W.Destroy()
|
|
|
|
return
|
|
|
|
}
|
2019-05-26 16:03:20 -05:00
|
|
|
if (b.Action == "ADD") {
|
|
|
|
log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?")
|
|
|
|
}
|
2019-06-01 00:28:02 -05:00
|
|
|
*/
|
2019-05-24 18:19:22 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
if (Data.MouseClick == nil) {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING")
|
2019-06-01 00:28:02 -05:00
|
|
|
log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function")
|
2019-05-24 15:23:50 -05:00
|
|
|
} else {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tgui.mouseClick() Data.MouseClick() START")
|
2019-05-24 11:02:35 -05:00
|
|
|
Data.MouseClick(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 13:54:33 -05:00
|
|
|
//
|
|
|
|
// This routine MUST be here as this is how the andlabs/ui works
|
2019-05-24 14:51:04 -05:00
|
|
|
// This is the raw routine passed to every button in andlabs libui / ui
|
2019-05-26 13:54:33 -05:00
|
|
|
//
|
2019-05-30 10:55:54 -05:00
|
|
|
// There is a []GuiButton which has all the buttons. We search
|
2019-05-26 13:54:33 -05:00
|
|
|
// for the button and then call the function below
|
|
|
|
//
|
2019-05-22 12:39:56 -05:00
|
|
|
func defaultButtonClick(button *ui.Button) {
|
2019-05-26 13:54:33 -05:00
|
|
|
log.Println("defaultButtonClick() LOOK FOR BUTTON button =", button)
|
2019-05-24 11:02:35 -05:00
|
|
|
for key, foo := range Data.AllButtons {
|
2019-05-26 13:54:33 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("defaultButtonClick() Data.AllButtons =", key, foo)
|
2019-05-30 03:58:05 -05:00
|
|
|
spew.Dump(foo)
|
2019-05-26 13:54:33 -05:00
|
|
|
}
|
2019-05-24 11:02:35 -05:00
|
|
|
if Data.AllButtons[key].B == button {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tdefaultButtonClick() BUTTON MATCHED")
|
2019-05-24 21:45:03 -05:00
|
|
|
// log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name)
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action)
|
2019-05-24 11:02:35 -05:00
|
|
|
if Data.AllButtons[key].custom != nil {
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION")
|
2019-05-30 13:56:34 -05:00
|
|
|
var tmp *GuiButton
|
2019-05-24 15:23:50 -05:00
|
|
|
tmp = Data.AllButtons[key]
|
2019-05-30 03:58:05 -05:00
|
|
|
// spew.Dump(tmp)
|
2019-05-30 13:56:34 -05:00
|
|
|
Data.AllButtons[key].custom(tmp)
|
2019-05-24 11:02:35 -05:00
|
|
|
return
|
|
|
|
}
|
2019-05-30 13:56:34 -05:00
|
|
|
mouseClick(Data.AllButtons[key])
|
2019-05-23 19:44:00 -05:00
|
|
|
return
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
}
|
2019-05-26 15:53:54 -05:00
|
|
|
log.Println("\tdefaultButtonClick() BUTTON NOT FOUND")
|
2019-05-26 13:54:33 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-26 15:53:54 -05:00
|
|
|
panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS")
|
2019-05-24 11:02:35 -05:00
|
|
|
}
|
2019-05-26 15:53:54 -05:00
|
|
|
mouseClick(nil)
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:55:54 -05:00
|
|
|
func AddButton(b *GuiButton, name string) *ui.Button {
|
2019-05-27 19:23:19 -05:00
|
|
|
newB := ui.NewButton(name)
|
|
|
|
newB.OnClicked(defaultButtonClick)
|
|
|
|
|
|
|
|
b.B = newB
|
2019-05-30 13:56:34 -05:00
|
|
|
Data.AllButtons = append(Data.AllButtons, b)
|
2019-05-27 19:23:19 -05:00
|
|
|
return newB
|
|
|
|
}
|
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*GuiButton)) *GuiButton {
|
2019-05-30 10:52:28 -05:00
|
|
|
newUiB := ui.NewButton(name)
|
|
|
|
newUiB.OnClicked(defaultButtonClick)
|
|
|
|
|
2019-05-30 13:41:23 -05:00
|
|
|
var newB *GuiButton
|
2019-05-31 15:15:38 -05:00
|
|
|
newB = new(GuiButton)
|
|
|
|
newB.B = newUiB
|
2019-05-31 19:37:53 -05:00
|
|
|
if (box.W == nil) {
|
|
|
|
log.Println("CreateButton() box.W == nil")
|
|
|
|
panic("crap")
|
|
|
|
}
|
|
|
|
newB.GW = box.W
|
2019-05-30 10:52:28 -05:00
|
|
|
newB.Account = a
|
2019-05-31 15:15:38 -05:00
|
|
|
newB.VM = vm
|
2019-05-31 19:37:53 -05:00
|
|
|
newB.Box = box
|
2019-05-30 10:52:28 -05:00
|
|
|
newB.Action = action
|
|
|
|
newB.custom = custom
|
2019-05-30 13:56:34 -05:00
|
|
|
Data.AllButtons = append(Data.AllButtons, newB)
|
2019-05-30 10:52:28 -05:00
|
|
|
|
2019-05-30 13:41:23 -05:00
|
|
|
return newB
|
2019-05-24 02:04:14 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
func CreateFontButton(box *GuiBox, action string) *GuiButton {
|
2019-05-22 12:39:56 -05:00
|
|
|
|
2019-05-26 13:54:33 -05:00
|
|
|
// create a 'fake' button entry for the mouse clicks
|
2019-05-31 19:37:53 -05:00
|
|
|
var newGB GuiButton
|
|
|
|
newGB.Action = action
|
|
|
|
newGB.FB = ui.NewFontButton()
|
|
|
|
newGB.Box = box
|
|
|
|
newGB.Area = box.Area
|
|
|
|
Data.AllButtons = append(Data.AllButtons, &newGB)
|
|
|
|
|
|
|
|
newGB.FB.OnChanged(func (*ui.FontButton) {
|
|
|
|
log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB)
|
|
|
|
mouseClick(&newGB)
|
2019-05-26 13:54:33 -05:00
|
|
|
})
|
2019-05-31 19:37:53 -05:00
|
|
|
return &newGB
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
2019-05-31 11:01:46 -05:00
|
|
|
|
|
|
|
func GetText(box *GuiBox, name string) string {
|
|
|
|
if (box == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR box == nil")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if (box.EntryMap == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR b.Box.EntryMap == nil")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
spew.Dump(box.EntryMap)
|
|
|
|
if (box.EntryMap[name] == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR box.EntryMap[", name, "] == nil ")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
e := box.EntryMap[name]
|
2019-06-01 00:28:02 -05:00
|
|
|
log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
|
2019-05-31 11:01:46 -05:00
|
|
|
log.Println("gui.GetText() END")
|
2019-06-01 00:28:02 -05:00
|
|
|
return e.UiEntry.Text()
|
2019-05-31 11:01:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func SetText(box *GuiBox, name string, value string) error {
|
|
|
|
if (box == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR box == nil")
|
|
|
|
}
|
|
|
|
if (box.EntryMap == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR b.Box.EntryMap == nil")
|
|
|
|
}
|
|
|
|
spew.Dump(box.EntryMap)
|
|
|
|
if (box.EntryMap[name] == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ")
|
|
|
|
}
|
|
|
|
e := box.EntryMap[name]
|
2019-06-01 00:28:02 -05:00
|
|
|
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
|
|
|
|
e.UiEntry.SetText(value)
|
|
|
|
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
|
2019-05-31 11:01:46 -05:00
|
|
|
log.Println("gui.SetText() END")
|
|
|
|
return nil
|
|
|
|
}
|
2019-06-01 01:45:53 -05:00
|
|
|
|
|
|
|
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
|
|
|
func MakeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
|
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
vboxN := ui.NewVerticalBox()
|
|
|
|
vboxN.SetPadded(true)
|
|
|
|
vboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
|
|
|
|
|
|
|
vboxN.Append(e.UiEntry, false)
|
|
|
|
box.UiBox.Append(vboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
|
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
hboxN := ui.NewHorizontalBox()
|
|
|
|
hboxN.SetPadded(true)
|
|
|
|
hboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
|
|
|
hboxN.Append(e.UiEntry, false)
|
|
|
|
|
|
|
|
box.UiBox.Append(hboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|