package main import "log" import "fmt" import "time" import "runtime" import "runtime/debug" import "git.wit.com/wit/gui" import pb "git.wit.com/wit/witProtobuf" // import "github.com/davecgh/go-spew/spew" // // This was the default handler for all mouse clicks (buttons, areas, etc)) // // Most mouse clicks are now moved to custom functions // func mainMouseClick(b *gui.GuiButton) { defer r() // a golang trick to try to not crash on certain errors if (b == nil) { log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") log.Println("THIS IS PROBABLY A BUG IN git.wit.com/gui") onExit(fmt.Errorf("mainMouseClick() got b = nil")) } log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE b.Action =", b.Action) var gw *gui.GuiWindow gw = b.Box.Window if (gw == nil) { log.Println("THIS BUTTON IS BROKEN gw = nil") panic("something") } if (b.Action == "QUIT") { onExit(nil) } else if (b.Action == "CREATE") { log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE") log.Println("\tTRIGGER CREATE VM") gui.Data.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].Action =", entry.Action) if (entry.Action == "Hostname") { event.Vms[0].Hostname = entry.UiEntry.Text() } if (entry.Action == "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 = b.Account log.Println("\tTRIGGERING CREATE event=", event) log.Println("\tTRIGGERING CREATE event.Account=", event.Account) websocketSendProtobuf(event) } else if (b.Action == "CONFIG") { newConfig := loadDefaultConfig() config.Accounts = newConfig.Accounts gui.Data.State = "done" } else if (b.Action == "DEBUG") { log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)") debug.PrintStack() } else if (b.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 (b.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 (b.Action == "SHOW") { log.Println("\tTRIGGER DISPLAY ACCOUNT") gui.Data.State = "SEND WEBSOCKET" event := pb.MakeGetEvent() event.Account = b.Account websocketSendProtobuf(event) count := 0 for { log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State) time.Sleep(200 * time.Millisecond) if (gui.Data.State == "NEW PROTOBUF") { if (currentMessage == nil) { gui.ErrorWindow(gw, "There was a socket error", "More detailed information can be shown here.") gui.Data.State = "done" } else { count := countVMS(currentMessage) log.Println("\tSHOW VMS currentMessage =", currentMessage) log.Println("\tSHOW VMS count =", count) // TODO: make sure login worked & the account really has zero VMs // if (count != 0) { name := "Virtual Machines (" + b.Account.Nick + ")" mh := addVmsTab(gw, name, count, b.Account) ReadReceivedData(currentMessage, mh, b.Box) // } currentMessage = nil gui.Data.State = "done" } return } count += 1 if (count > 10) { log.Println("\tERROR: waited too long for a resposne") currentMessage = nil gui.Data.State = "done" return } } } log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE") log.Println("mainMouseClick() FAILED TO FIND b.Action =", b.Action) log.Println("mainMouseClick() END") } func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton { val := &myButtonInfo{} val.Account = a val.Accounts = config.Accounts val.VM = vm val.Custom = custom val.Name = "jcarr" return gui.NewCreateButton(box, custom, name, val) }