From 1abf8279f2c1fd81c68a732b8e1c42ec9fc27f12 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 2 Jun 2019 21:56:15 -0700 Subject: [PATCH] focus on cleaning up the flow of the code Signed-off-by: Jeff Carr --- Makefile | 4 +- example-multiple-windows/main.go | 42 ++++----- gui-buttonClicks.go | 8 +- gui-splashPage.go | 3 +- test4/Makefile | 3 - test4/main.go | 144 ------------------------------- 6 files changed, 30 insertions(+), 174 deletions(-) delete mode 100644 test4/Makefile delete mode 100644 test4/main.go diff --git a/Makefile b/Makefile index 46406a6..8acd079 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,8 @@ push: git push --all tag-version: - echo git tag v${VERSION} - echo git push --tags + git tag v${VERSION} + git push --tags # should update every go dependancy (?) update: diff --git a/example-multiple-windows/main.go b/example-multiple-windows/main.go index d5e5117..6df5787 100644 --- a/example-multiple-windows/main.go +++ b/example-multiple-windows/main.go @@ -14,42 +14,42 @@ import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" var first *gui.GuiWindow +var config *pb.Config // This sometimes crashes on the most recent window // under linux. but it doesn't always crash func main() { - var c *pb.Config - c = pb.MakeDefaultConfig() - gui.Data.Config = c + config = pb.MakeDefaultConfig() + // gui.Data.Config = c i := 1 - c.Width = int32(400 + 50 * i) - c.Height = int32(400 + 50 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - first = StartNewWindow(c, true, "SPLASH") + config.Width = int32(400 + 50 * i) + config.Height = int32(400 + 50 * i) + config.Hostname = fmt.Sprintf("splash %d", i) + first = StartNewWindow(config, true, "SPLASH") i += 1 - c.Width = int32(400 + 50 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - StartNewWindow(c, true, "BLAH") + config.Width = int32(400 + 50 * i) + config.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(config, true, "BLAH") i += 1 - c.Width = int32(400 + 50 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - StartNewWindow(c, false, "BLAH") + config.Width = int32(400 + 50 * i) + config.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(config, false, "BLAH") for { i += 1 - c.Width = int32(400 + 50 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - StartNewWindow(c, false, "SPLASH") + config.Width = int32(400 + 50 * i) + config.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(config, false, "SPLASH") i += 1 - c.Width = int32(400 + 50 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - StartNewWindow(c, false, "BLAH") + config.Width = int32(400 + 50 * i) + config.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(config, false, "BLAH") } } @@ -88,7 +88,7 @@ func StartNewWindow(c *pb.Config, bg bool, action string) *gui.GuiWindow { func InitWindow(gw *gui.GuiWindow) { log.Println("InitWindow() NEW WINDOW gw =", gw) - c := gui.Data.Config + c := config gw.UiWindow = ui.NewWindow("", int(c.Width), int(c.Height), true) // gw.UiWindow.SetBorderless(false) @@ -118,6 +118,6 @@ func InitWindow(gw *gui.GuiWindow) { // gw.UiWindow.SetChild(gw.T) // gw.UiWindow.SetMargined(true) - log.Println("InitWindow() Show() gw.Action =", gw.Action) + log.Println("InitWindow() Show() gw.Name =", gw.Name) gw.UiWindow.Show() } diff --git a/gui-buttonClicks.go b/gui-buttonClicks.go index 0e39012..e3fa1bb 100644 --- a/gui-buttonClicks.go +++ b/gui-buttonClicks.go @@ -49,16 +49,17 @@ func mainMouseClick(b *gui.GuiButton) { onExit(nil) } else if (values.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") { + log.Println("\tdefaultEntryChange() Data.AllEntries[key].Name =", entry.Name) + if (entry.Name == "Hostname") { event.Vms[0].Hostname = entry.UiEntry.Text() } - if (entry.Action == "Memory") { + if (entry.Name == "Memory") { event.Vms[0].Memory = pint64(entry.UiEntry.Text()) } log.Println("\tdefaultEntryChange() Data.AllEntries[key].E =", entry.UiEntry.Text()) @@ -71,6 +72,7 @@ func mainMouseClick(b *gui.GuiButton) { 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 diff --git a/gui-splashPage.go b/gui-splashPage.go index b17392f..5353a9f 100644 --- a/gui-splashPage.go +++ b/gui-splashPage.go @@ -70,7 +70,8 @@ func splashClick(b *gui.GuiButton) { } // if there is not an account, then go to 'make account' gw = gui.InitGuiWindow("splashClick() Box22", gw) - gw.UiTab.Delete(0) + // gw.UiTab.Hide() // Hide or Delete ? + gw.UiTab.Delete(0) // does this make things more or less stable or neither? log.Println("splashClick() AddGenericBox() START") box := gui.AddGenericBox(gw, "addSubdomainQuestion") diff --git a/test4/Makefile b/test4/Makefile deleted file mode 100644 index 52515aa..0000000 --- a/test4/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -run: - go build - ./test4 diff --git a/test4/main.go b/test4/main.go deleted file mode 100644 index 52e9938..0000000 --- a/test4/main.go +++ /dev/null @@ -1,144 +0,0 @@ -package main - -import "log" -// import "os" -// import "time" -// import "os/user" -// import "reflect" -import "runtime" - -import "git.wit.com/wit/gui" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import pb "git.wit.com/wit/witProtobuf" - -// import "github.com/davecgh/go-spew/spew" - -var config *pb.Config - -func main() { - go gui.WatchGUI() - config = pb.MakeDefaultConfig() - gui.StartNewWindow(config, false, "SPLASH", showSplashBox) -} - -func splashClick(b *gui.GuiButton) { - gw := b.Box.Window - // if there is already an account, skip straight to the main screen - for key, _ := range config.Accounts { - log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Account = ", config.Accounts[key]) - // makeCloudInfoBox(gw) - return - } - // if there is not an account, then go to 'make account' - // gw.MakeWindow = addSubdomainQuestionBox - gw = gui.ShowTab(gw, "Box2", "New Account?") -} - -func showSplashBox(gw *gui.GuiWindow) *gui.GuiBox { - log.Println("ShowSplashBox() START") - text := getNEWTEXT() - box := gui.ShowTextBox(gw, text) - - if runtime.GOOS == "linux" { - gui.NewLabel(box,"OS: Linux") - } else if runtime.GOOS == "windows" { - gui.NewLabel(box,"OS: Windows") - } else { - gui.NewLabel(box,"OS: " + runtime.GOOS) - } - - gui.NewLabel(box, "Version: " + "test") - - okButton := gui.CreateButton(box, nil, nil, "OK", "AREA", splashClick) - gui.AddButtonToBox(box, okButton) - - log.Println("ShowSplashBox() END box =", box) - return box -} - -func getNEWTEXT() *ui.AttributedString { - var aText *ui.AttributedString - aText = ui.NewAttributedString("") - - gui.AreaAppendText(aText, "Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) - gui.AreaAppendText(aText, "(alpha)\n\n", ui.TextSize(10)) - - gui.AreaAppendText(aText, "This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold) - gui.AreaAppendText(aText, "The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold) - - aText.AppendUnattributed("\n") - aText.AppendUnattributed("\n") - gui.AreaAppendText(aText, "This control panel requires:\n") - aText.AppendUnattributed("\n") - gui.AreaAppendText(aText, "IPv6\n") - gui.AreaAppendText(aText, "Your hostname in DNS\n") - aText.AppendUnattributed("\n\n\n\n\n") - - gui.AreaAppendText(aText, "\n", ui.TextSize(10)) - - return aText -} - -/* -func addSubdomainQuestionBox(gw *gui.GuiWindow) *gui.GuiBox { - log.Println("addSubdomainQuestionBox() START") - box := gui.AddGenericBox(gw) - - gui.NewLabel(box, "Enter your Subdomain or") - - button := gui.CreateButton(box, nil, nil, "Generate", "SUBDOMAIN", generateSubdomain) - gui.AddButtonToBox(box, button) - - gui.AddEntry(box, "SUBDOMAIN") - - gui.HorizontalBreak(box) - - button2 := gui.CreateButton(box, nil, nil, "Create Subdomain Account", "ADD", addSubdomainButton) - gui.AddButtonToBox(box, button2) - - log.Println("addSubdomainQuestionBox() END box =", box) - return box -} - -// curl -vv -X POST -H "X-Wit-Auth: $TOKEN" 'http://stackapi-api1.stackapi.customers.wit.com:4000/vms/toby?count=1&cpu=2&ram=512&disk=25' - - -func addSubdomainButton(b *gui.GuiButton) { - log.Println("addSubdomainButton() START") - subdomain := gui.GetText(b.Box, "SUBDOMAIN") - if (subdomain == "") { - gui.ErrorWindow(b.GW, "Blank Name", "You must have a valid subdomain") - return - } - log.Println("\tsubdomain =", subdomain) - - acc := new(pb.Account) - acc.Nick = subdomain - acc.Domain = subdomain - acc.Username = "jcarr@wit.com" - acc.Email = "jcarr@wit.com" - acc.Password = "badpass" - acc.URL = "http://stackapi-api1.stackapi.customers.dev.wit.com:4000/" - config.Accounts = append(config.Accounts, acc) - - makeCloudInfoBox(b.GW) - gui.Data.State = "done" - log.Println("addSubdomainButton() END") -} - -func generateSubdomain(b *gui.GuiButton) { - log.Println("generateSubdomain START") - if (b == nil) { - log.Println("generateSubdomain ERROR b == nil") - return - } - // subdomain.SetText("cust00013.wit.dev") - - txt := gui.SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wprod.wit.com") - log.Println("generateSubdomain subdomain = ", txt) - log.Println("generateSubdomain END") -} -*/