rearrange gui code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
936176010a
commit
8b1d68fd91
|
@ -3,8 +3,8 @@ package main
|
||||||
import "log"
|
import "log"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "time"
|
import "time"
|
||||||
import "runtime"
|
// import "runtime"
|
||||||
import "runtime/debug"
|
// import "runtime/debug"
|
||||||
|
|
||||||
import "git.wit.com/wit/gui"
|
import "git.wit.com/wit/gui"
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
@ -16,6 +16,25 @@ import pb "git.wit.com/wit/witProtobuf"
|
||||||
// Most mouse clicks are now moved to custom functions
|
// Most mouse clicks are now moved to custom functions
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// stores the fields we want to map into our private structure 'values'
|
||||||
|
func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
||||||
|
name string, action string, custom func(*gui.GuiButton)) *myButtonInfo {
|
||||||
|
val := &myButtonInfo{}
|
||||||
|
val.Account = a
|
||||||
|
val.Accounts = config.Accounts
|
||||||
|
val.VM = vm
|
||||||
|
val.Custom = custom
|
||||||
|
val.Name = "jcarr"
|
||||||
|
val.Action = action
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
||||||
|
name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton {
|
||||||
|
val := makeGuiButtonValues(box, a, vm, name, action, custom)
|
||||||
|
return gui.CreateButton(box, custom, name, val)
|
||||||
|
}
|
||||||
|
|
||||||
func mainMouseClick(b *gui.GuiButton) {
|
func mainMouseClick(b *gui.GuiButton) {
|
||||||
defer r() // a golang trick to try to not crash on certain errors
|
defer r() // a golang trick to try to not crash on certain errors
|
||||||
|
|
||||||
|
@ -49,57 +68,33 @@ func mainMouseClick(b *gui.GuiButton) {
|
||||||
onExit(nil)
|
onExit(nil)
|
||||||
} else if (values.Action == "CREATE") {
|
} else if (values.Action == "CREATE") {
|
||||||
log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE")
|
log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE")
|
||||||
/*
|
createVmClick(b)
|
||||||
log.Println("\tTRIGGER CREATE VM")
|
|
||||||
State = "CREATE"
|
|
||||||
event := pb.MakeAddVmEvent()
|
|
||||||
for key, entry := range gui.Data.AllEntries {
|
|
||||||
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, entry)
|
|
||||||
log.Println("\tdefaultEntryChange() Data.AllEntries[key].Name =", entry.Name)
|
|
||||||
if (entry.Name == "Hostname") {
|
|
||||||
event.Vms[0].Hostname = entry.UiEntry.Text()
|
|
||||||
}
|
|
||||||
if (entry.Name == "Memory") {
|
|
||||||
event.Vms[0].Memory = pint64(entry.UiEntry.Text())
|
|
||||||
}
|
|
||||||
log.Println("\tdefaultEntryChange() Data.AllEntries[key].E =", entry.UiEntry.Text())
|
|
||||||
log.Println("\tdefaultEntryChange() Data.AllEntries[key].B =", entry.B)
|
|
||||||
if entry.B == b {
|
|
||||||
log.Println("defaultEntryChange() FOUND. Entry assigned to Button", b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.Account = values.Account
|
|
||||||
log.Println("\tTRIGGERING CREATE event=", event)
|
|
||||||
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
|
||||||
websocketSendProtobuf(event)
|
|
||||||
*/
|
|
||||||
} else if (values.Action == "CONFIG") {
|
|
||||||
newConfig := loadDefaultConfig()
|
|
||||||
config.Accounts = newConfig.Accounts
|
|
||||||
State = "done"
|
|
||||||
} else if (values.Action == "DEBUG") {
|
|
||||||
log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)")
|
|
||||||
debug.PrintStack()
|
|
||||||
} else if (values.Action == "DEBUG FULL") {
|
|
||||||
log.Println("\tATTEMPT FULL STACK DUMP")
|
|
||||||
buf := make([]byte, 1<<16)
|
|
||||||
runtime.Stack(buf, true)
|
|
||||||
log.Printf("%s", buf)
|
|
||||||
log.Println("\tFINISHED FULL STACK DUMP")
|
|
||||||
/*
|
|
||||||
} else if (values.Action == "SHOW VM") {
|
|
||||||
if (gui.Data.Debug) {
|
|
||||||
log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw)
|
|
||||||
createVmBox(gw, b.VM)
|
|
||||||
} else {
|
|
||||||
log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw)
|
|
||||||
createVmBox(gw, b.VM)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} else if (values.Action == "SHOW") {
|
} else if (values.Action == "SHOW") {
|
||||||
|
showAccountClick(b)
|
||||||
|
}
|
||||||
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
||||||
|
log.Println("mainMouseClick() FAILED TO FIND values.Action =", values.Action)
|
||||||
|
log.Println("mainMouseClick() END")
|
||||||
|
}
|
||||||
|
|
||||||
|
func showAccountClick(b *gui.GuiButton) {
|
||||||
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
||||||
State = "SEND WEBSOCKET"
|
State = "SEND WEBSOCKET"
|
||||||
|
|
||||||
|
var values *myButtonInfo
|
||||||
|
|
||||||
|
if tmp, ok := b.Values.(*myButtonInfo); ! ok {
|
||||||
|
log.Println("\tmainMouseClick() values.Accounts error =", ok)
|
||||||
|
log.Println("\tmainMouseClick() values.Accounts tmp =", tmp)
|
||||||
|
} else {
|
||||||
|
values = tmp
|
||||||
|
}
|
||||||
|
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
||||||
|
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||||
|
|
||||||
|
var gw *gui.GuiWindow
|
||||||
|
gw = b.Box.Window
|
||||||
|
|
||||||
event := pb.MakeGetEvent()
|
event := pb.MakeGetEvent()
|
||||||
event.Account = values.Account
|
event.Account = values.Account
|
||||||
websocketSendProtobuf(event)
|
websocketSendProtobuf(event)
|
||||||
|
@ -137,27 +132,45 @@ func mainMouseClick(b *gui.GuiButton) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createVmClick(b *gui.GuiButton) {
|
||||||
|
log.Println("createVmClick()")
|
||||||
|
|
||||||
|
var values *myButtonInfo
|
||||||
|
|
||||||
|
if tmp, ok := b.Values.(*myButtonInfo); ! ok {
|
||||||
|
log.Println("\tmainMouseClick() values.Accounts error =", ok)
|
||||||
|
log.Println("\tmainMouseClick() values.Accounts tmp =", tmp)
|
||||||
|
} else {
|
||||||
|
values = tmp
|
||||||
}
|
}
|
||||||
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
||||||
log.Println("mainMouseClick() FAILED TO FIND values.Action =", values.Action)
|
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||||
log.Println("mainMouseClick() END")
|
|
||||||
}
|
|
||||||
|
|
||||||
// stores the fields we want to map into our private structure 'values'
|
// var gw *gui.GuiWindow
|
||||||
func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
// gw = b.Box.Window
|
||||||
name string, action string, custom func(*gui.GuiButton)) *myButtonInfo {
|
|
||||||
val := &myButtonInfo{}
|
|
||||||
val.Account = a
|
|
||||||
val.Accounts = config.Accounts
|
|
||||||
val.VM = vm
|
|
||||||
val.Custom = custom
|
|
||||||
val.Name = "jcarr"
|
|
||||||
val.Action = action
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
log.Println("\tTRIGGER CREATE VM")
|
||||||
name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton {
|
State = "CREATE"
|
||||||
val := makeGuiButtonValues(box, a, vm, name, action, custom)
|
event := pb.MakeAddVmEvent()
|
||||||
return gui.CreateButton(box, custom, name, val)
|
for key, entry := range gui.Data.AllEntries {
|
||||||
|
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, entry)
|
||||||
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].Name =", entry.Name)
|
||||||
|
if (entry.Name == "Hostname") {
|
||||||
|
event.Vms[0].Hostname = entry.UiEntry.Text()
|
||||||
|
}
|
||||||
|
if (entry.Name == "Memory") {
|
||||||
|
event.Vms[0].Memory = pint64(entry.UiEntry.Text())
|
||||||
|
}
|
||||||
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].E =", entry.UiEntry.Text())
|
||||||
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].B =", entry.B)
|
||||||
|
if entry.B == b {
|
||||||
|
log.Println("defaultEntryChange() FOUND. Entry assigned to Button", b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.Account = values.Account
|
||||||
|
log.Println("\tTRIGGERING CREATE event=", event)
|
||||||
|
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
||||||
|
websocketSendProtobuf(event)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue