From 26bcac9b85ad095ae58f2b516e74d2a9b47300b4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 2 Jun 2019 22:22:23 -0700 Subject: [PATCH] make a buttonMap Signed-off-by: Jeff Carr --- eventChannel.go | 2 +- gui-buttonClicks.go | 18 +++++++++--------- gui-splashPage.go | 2 +- login.go | 12 ++++++------ main.go | 2 ++ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/eventChannel.go b/eventChannel.go index 993c714..960a187 100644 --- a/eventChannel.go +++ b/eventChannel.go @@ -39,7 +39,7 @@ func processEvents() { log.Println("processEvents() do Event DEMO") } else { log.Println("processEvents() NEW PROTOBUF") - gui.Data.State = "NEW PROTOBUF" + State = "NEW PROTOBUF" } log.Println("processEvents() END on channel") } diff --git a/gui-buttonClicks.go b/gui-buttonClicks.go index e3fa1bb..d80befe 100644 --- a/gui-buttonClicks.go +++ b/gui-buttonClicks.go @@ -51,7 +51,7 @@ func mainMouseClick(b *gui.GuiButton) { log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE") /* log.Println("\tTRIGGER CREATE VM") - gui.Data.State = "CREATE" + State = "CREATE" event := pb.MakeAddVmEvent() for key, entry := range gui.Data.AllEntries { log.Println("\tdefaultEntryChange() Data.AllEntries =", key, entry) @@ -76,7 +76,7 @@ func mainMouseClick(b *gui.GuiButton) { } else if (values.Action == "CONFIG") { newConfig := loadDefaultConfig() config.Accounts = newConfig.Accounts - gui.Data.State = "done" + State = "done" } else if (values.Action == "DEBUG") { log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)") debug.PrintStack() @@ -98,7 +98,7 @@ func mainMouseClick(b *gui.GuiButton) { */ } else if (values.Action == "SHOW") { log.Println("\tTRIGGER DISPLAY ACCOUNT") - gui.Data.State = "SEND WEBSOCKET" + State = "SEND WEBSOCKET" event := pb.MakeGetEvent() event.Account = values.Account @@ -106,14 +106,14 @@ func mainMouseClick(b *gui.GuiButton) { count := 0 for { - log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State) + log.Println("\tSleep() in buttonClick() State =", State) time.Sleep(200 * time.Millisecond) - if (gui.Data.State == "NEW PROTOBUF") { + if (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" + State = "done" } else { count := countVMS(currentMessage) log.Println("\tSHOW VMS currentMessage =", currentMessage) @@ -125,7 +125,7 @@ func mainMouseClick(b *gui.GuiButton) { ReadReceivedData(currentMessage, mh, b.Box) // } currentMessage = nil - gui.Data.State = "done" + State = "done" } return } @@ -133,7 +133,7 @@ func mainMouseClick(b *gui.GuiButton) { if (count > 10) { log.Println("\tERROR: waited too long for a resposne") currentMessage = nil - gui.Data.State = "done" + State = "done" return } } @@ -159,5 +159,5 @@ func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM, 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.NewCreateButton(box, custom, name, val) + return gui.CreateButton(box, custom, name, val) } diff --git a/gui-splashPage.go b/gui-splashPage.go index 5353a9f..1cc9f33 100644 --- a/gui-splashPage.go +++ b/gui-splashPage.go @@ -107,7 +107,7 @@ func addSubdomainButton(b *gui.GuiButton) { config.Accounts = append(config.Accounts, acc) makeCloudInfoBox(b.Box.Window) - gui.Data.State = "done" + State = "done" log.Println("addSubdomainButton() END") } diff --git a/login.go b/login.go index fd9a433..9d0e8db 100644 --- a/login.go +++ b/login.go @@ -13,7 +13,7 @@ import pb "git.wit.com/wit/witProtobuf" func login(b *gui.GuiButton) { log.Println("login() START") - gui.Data.State = "SEND LOGIN" + State = "SEND LOGIN" // TODO: move this into a seperate goroutine // note: this may never be possible because of cross platform @@ -28,14 +28,14 @@ func login(b *gui.GuiButton) { count := 0 for { - log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State) + log.Println("\tSleep() in buttonClick() State =", State) time.Sleep(200 * time.Millisecond) - if (gui.Data.State == "NEW PROTOBUF") { + if (State == "NEW PROTOBUF") { if (currentMessage == nil) { gui.ErrorWindow(b.Box.Window, "There was a socket error", "More detailed information can be shown here.") - gui.Data.State = "done" + State = "done" } else { log.Println("LOGIN currentMessage =", currentMessage) if (currentMessage.Type == pb.Event_OK) { @@ -64,7 +64,7 @@ func login(b *gui.GuiButton) { gui.ErrorWindow(b.Box.Window, "Login Failed", msg) } currentMessage = nil - gui.Data.State = "done" + State = "done" } return } @@ -73,7 +73,7 @@ func login(b *gui.GuiButton) { if (count > 10) { log.Println("\tERROR: waited too long for a resposne") currentMessage = nil - gui.Data.State = "done" + State = "done" return } } diff --git a/main.go b/main.go index 410e3b7..36d28cd 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,8 @@ var GOVERSION string // this is passed in as an ldflag var BUILDTIME string // this is passed in as an ldflag var VERSION string // this is passed in as an ldflag +var State string // used as a State machine + type myButtonInfo struct { Account *pb.Account // associated with what account? Accounts []*pb.Account // associated with what account?