From 28e4b48a261ba2498db75b9d0b87e04c32b140fe Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 22 May 2019 20:16:16 -0700 Subject: [PATCH] start moving everything to git.wit.com/wit/gui Signed-off-by: Jeff Carr --- account1/addAccount.go | 66 -------------------- account2/addAccount.go | 138 ----------------------------------------- main.go | 4 +- splash/area.go | 122 ------------------------------------ splash/splash.go | 69 --------------------- test2/Makefile | 6 -- test2/main.go | 116 ---------------------------------- test3/main.go | 7 +-- test4/main.go | 21 +++---- 9 files changed, 14 insertions(+), 535 deletions(-) delete mode 100644 account1/addAccount.go delete mode 100644 account2/addAccount.go delete mode 100644 splash/area.go delete mode 100644 splash/splash.go delete mode 100644 test2/Makefile delete mode 100644 test2/main.go diff --git a/account1/addAccount.go b/account1/addAccount.go deleted file mode 100644 index bb9e891..0000000 --- a/account1/addAccount.go +++ /dev/null @@ -1,66 +0,0 @@ -package account1 - -import "log" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/gui" -// import "github.com/davecgh/go-spew/spew" - -func AddAccountWindow() { - accounthWin := ui.NewWindow("Add Account", 400, 300, false) - accounthWin.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - accounthWin.Destroy() - return true - }) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - accounthWin.SetChild(vbox) - accounthWin.SetMargined(true) - - // This displays the window - accounthWin.Show() - - // START create new account button - newAccountButton := ui.NewButton("Create New Account") - newAccountButton.OnClicked(func(*ui.Button) { - log.Println("OK. Closing window.") - accounthWin.Destroy() - ui.Quit() - }) - vbox.Append(newAccountButton, false) - // END create new account button - - vbox.Append(ui.NewHorizontalSeparator(), false) - - okButton := ui.NewButton("I Have an Account") - okButton.OnClicked(func(*ui.Button) { - log.Println("OK. Closing window.") - accounthWin.Destroy() - ui.Quit() - }) - vbox.Append(okButton, false) - // END add account hbox -} - -func AddAccountBox(junk *ui.Box, custom func(int, string)) *ui.Box { - newbox := ui.NewVerticalBox() - newbox.SetPadded(true) - - // create new account button - newButton := gui.CreateButton("Create New Account", "CLOSE", custom) - newbox.Append(newButton, false) - - newbox.Append(ui.NewHorizontalSeparator(), false) - - okButton := gui.CreateButton("I Have an Account", "CLOSE", custom) - newbox.Append(okButton, false) - - return newbox -} diff --git a/account2/addAccount.go b/account2/addAccount.go deleted file mode 100644 index 6676549..0000000 --- a/account2/addAccount.go +++ /dev/null @@ -1,138 +0,0 @@ -package account2 - -import "log" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -// import "github.com/davecgh/go-spew/spew" - -func AddAccountWindow() { - accounthWin := ui.NewWindow("Add Account", 400, 300, false) - accounthWin.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - accounthWin.Destroy() - return true - }) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - accounthWin.SetChild(vbox) - accounthWin.SetMargined(true) - - // This displays the window - accounthWin.Show() - - // START add account hbox - hboxAccount := ui.NewHorizontalBox() - hboxAccount.SetPadded(true) - vbox.Append(hboxAccount, false) - - // Start 'Provider' vertical box - vboxC := ui.NewVerticalBox() - vboxC.SetPadded(true) - vboxC.Append(ui.NewLabel("Cloud Provider:"), false) - - cbox := ui.NewCombobox() - cbox.Append("WIT") - cbox.Append("Evocative") - vboxC.Append(cbox, false) - cbox.SetSelected(0) - - cbox.OnSelected(func(*ui.Combobox) { - log.Println("OK. Selected Cloud Provider =", cbox.Selected()) - }) - hboxAccount.Append(vboxC, false) - // End 'Cloud Provider' vertical box - - // Start 'Region' vertical box - vboxR := ui.NewVerticalBox() - vboxR.SetPadded(true) - vboxR.Append(ui.NewLabel("Region:"), false) - - regbox := ui.NewCombobox() - regbox.Append("Any") - regbox.Append("SF") - vboxR.Append(regbox, false) - regbox.SetSelected(0) - - regbox.OnSelected(func(*ui.Combobox) { - log.Println("OK. Selected something =", regbox.Selected()) - }) - hboxAccount.Append(vboxR, false) - // End 'Region' vertical box - - // Start 'Nickname' vertical box - vboxN := ui.NewVerticalBox() - vboxN.SetPadded(true) - vboxN.Append(ui.NewLabel("Account Nickname:"), false) - - entryNick := ui.NewEntry() - entryNick.SetReadOnly(false) - - vboxN.Append(entryNick, false) - - entryNick.OnChanged(func(*ui.Entry) { - log.Println("OK. nickname =", entryNick.Text()) - }) - hboxAccount.Append(vboxN, false) - // End 'Nickname' vertical box - - // Start 'Username' vertical box - vboxU := ui.NewVerticalBox() - vboxU.SetPadded(true) - vboxU.Append(ui.NewLabel("Account Username:"), false) - - entryUser := ui.NewEntry() - entryUser.SetReadOnly(false) - - vboxU.Append(entryUser, false) - - entryUser.OnChanged(func(*ui.Entry) { - log.Println("OK. username =", entryUser.Text()) - }) - hboxAccount.Append(vboxU, false) - // End 'Username' vertical box - - // Start 'Password' vertical box - vboxP := ui.NewVerticalBox() - vboxP.SetPadded(true) - vboxP.Append(ui.NewLabel("Account Password:"), false) - - entryPass := ui.NewEntry() - entryPass.SetReadOnly(false) - - vboxP.Append(entryPass, false) - - entryPass.OnChanged(func(*ui.Entry) { - log.Println("OK. password =", entryPass.Text()) - }) - hboxAccount.Append(vboxP, false) - // End 'Password' vertical box - - vbox.Append(ui.NewHorizontalSeparator(), false) - - hboxButtons := ui.NewHorizontalBox() - hboxButtons.SetPadded(true) - vbox.Append(hboxButtons, false) - - okButton := ui.NewButton("Add Account") - okButton.OnClicked(func(*ui.Button) { - log.Println("OK. Closing window.") - accounthWin.Destroy() - ui.Quit() - }) - hboxButtons.Append(okButton, false) - - backButton := ui.NewButton("Back") - backButton.OnClicked(func(*ui.Button) { - log.Println("OK. Closing window.") - accounthWin.Destroy() - ui.Quit() - }) - hboxButtons.Append(backButton, false) - // END add account hbox -} diff --git a/main.go b/main.go index 0094248..4ed616c 100644 --- a/main.go +++ b/main.go @@ -64,8 +64,8 @@ func main() { go gorillaDial("v000185.testing.com.customers.wprod.wit.com:9000") - gui.Width = config.Int("width") - gui.Height = config.Int("height") + gui.Data.Width = config.Int("width") + gui.Data.Height = config.Int("height") // make this the main loop in an attempt to figure out the crashes // do not change this until the GUI is stable diff --git a/splash/area.go b/splash/area.go deleted file mode 100644 index 8164516..0000000 --- a/splash/area.go +++ /dev/null @@ -1,122 +0,0 @@ -package splash - -import "log" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/gui" - -import "github.com/davecgh/go-spew/spew" - -var fontButton *ui.FontButton -var attrstr *ui.AttributedString -var splashArea *ui.Area - -func areaClick(a int, b string) { - log.Println("GOT areaClick(a,b) =", a, b) -} - -func makeSplashArea(custom func(int, string)) *ui.Area { - // make this button just to get the default font (but don't display the button) - // There should be another way to do this (?) - fontButton = gui.CreateFontButton("SplashFont", "CLOSE", custom) - - makeAttributedString() - splashArea = ui.NewArea(myAH) - - spew.Dump(splashArea) - return splashArea -} - -func appendWithAttributes(what string, attrs ...ui.Attribute) { - start := len(attrstr.String()) - end := start + len(what) - attrstr.AppendUnattributed(what) - for _, a := range attrs { - attrstr.SetAttribute(a, start, end) - } -} - -func makeAttributedString() { - attrstr = ui.NewAttributedString("") - - appendWithAttributes("Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT" - - appendWithAttributes("(alpha)\n\n", ui.TextSize(10)) - - appendWithAttributes("This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold) - appendWithAttributes("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) - - attrstr.AppendUnattributed("\n") - attrstr.AppendUnattributed("\n") - appendWithAttributes("This control panel requires:\n") - attrstr.AppendUnattributed("\n") - appendWithAttributes("IPv6\n") - appendWithAttributes("Your hostname in DNS\n") - attrstr.AppendUnattributed("\n\n\n\n\n") - - appendWithAttributes("\n", ui.TextSize(10)) -} - -type areaHandler struct{ - buttonFunc func(int, int) - closeFunc func(int) -} - -var myAH areaHandler - -func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) { - tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{ - String: attrstr, - DefaultFont: fontButton.Font(), - Width: p.AreaWidth, - Align: ui.DrawTextAlign(1), - }) - p.Context.Text(tl, 0, 0) - defer tl.Free() -} - -func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { - log.Println("GOT MouseEvent()") - spew.Dump(me) - if (me.Down == 1) { - log.Println("GOT MOUSE DOWN") - log.Println("GOT MOUSE DOWN") - log.Println("GOT MOUSE DOWN") - } - if (me.Up == 1) { - log.Println("GOT MOUSE UP") - log.Println("GOT MOUSE UP") - log.Println("GOT MOUSE UP") - // splashWin.Destroy() - // ui.Quit() - } - areaClick(1, "done") -} - -func (ah areaHandler) MouseCrossed(a *ui.Area, left bool) { - log.Println("GOT MouseCrossed()") -} - -func (ah areaHandler) DragBroken(a *ui.Area) { - log.Println("GOT DragBroken()") -} - -func (ah areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { - log.Println("GOT KeyEvent()") - if (ke.Key == 10) { - log.Println("GOT ENTER") - log.Println("GOT ENTER") - log.Println("GOT ENTER") - } - if (ke.Key == 32) { - log.Println("GOT ENTER") - log.Println("GOT ENTER") - log.Println("GOT ENTER") - } - spew.Dump(ke) - // splashWin.Destroy() - // ui.Quit() - return false -} diff --git a/splash/splash.go b/splash/splash.go deleted file mode 100644 index 2e9e1ee..0000000 --- a/splash/splash.go +++ /dev/null @@ -1,69 +0,0 @@ -package splash - -// import "github.com/davecgh/go-spew/spew" -// import "time" -// import "fmt" - -// import "log" -import "runtime" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/gui" - -// var splashWin *ui.Window -var MyArea *ui.Area - -func ShowSplash() *ui.Window { - splashWin := ui.NewWindow("", 640, 480, true) - splashWin.SetBorderless(true) - splashWin.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - splashWin.Destroy() - return true - }) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - splashWin.SetChild(vbox) - splashWin.SetMargined(true) - - // This displays the window - // splashWin.Show() - - ShowSplashBox(vbox, nil, nil) - - return splashWin -} - -func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(int, string)) *ui.Box { - newbox := ui.NewVerticalBox() - newbox.SetPadded(true) - - makeAttributedString() - MyArea = makeSplashArea(custom) - - newbox.Append(MyArea, true) - - if runtime.GOOS == "linux" { - newbox.Append(ui.NewLabel("OS: Linux"), false) - } else if runtime.GOOS == "windows" { - newbox.Append(ui.NewLabel("OS: Windows"), false) - } else { - newbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false) - } - - newbox.Append(ui.NewLabel("Version: v0.3"), false) - okButton := gui.CreateButton("OK", "CLOSE", custom) - newbox.Append(okButton, false) - - if (vbox != nil) { - vbox.Append(newbox, true) - } - - return newbox -} diff --git a/test2/Makefile b/test2/Makefile deleted file mode 100644 index d81691a..0000000 --- a/test2/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -build: - go build - ./test2 - -run: - go run *.go diff --git a/test2/main.go b/test2/main.go deleted file mode 100644 index 27e4ada..0000000 --- a/test2/main.go +++ /dev/null @@ -1,116 +0,0 @@ -package main - -import "log" -import "time" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/cloud-control-panel/splash" -import "git.wit.com/wit/cloud-control-panel/account1" -// import "git.wit.com/wit/cloud-control-panel/account2" - -// import "github.com/davecgh/go-spew/spew" - -var cloudWindow *ui.Window -var cloudTab *ui.Tab -var cloudBox *ui.Box -var smallBox *ui.Box -var state string - -func splashClose(a int, b string) { - log.Println("GOT splashClose(a,b) =", a, b) - - log.Println("cloudBox Delete(0) START") - cloudBox.Delete(0) - log.Println("smallBox.Hide() START") - smallBox.Hide() - - state = "kill" -} - -func main() { - go watchGUI() - - ui.Main(makeCloudWindow) - -// ui.Main(account1.AddAccountWindow) -// ui.Main(account2.AddAccountWindow) -} - -func buttonClick(i int, s string) { - log.Println("test2 buttonClick() i, s =", i, s) - cloudTab.Delete(0) - - log.Println("Sleep(2000)") - time.Sleep(2000 * time.Millisecond) - - smallBox = account1.AddAccountBox(nil, splashClose) - cloudTab.InsertAt("Intro", 0, smallBox) - cloudTab.SetMargined(0, true) -} - -func watchGUI() { - log.Println("Sleep(2000)") - time.Sleep(2000 * time.Millisecond) - - for { - log.Println("Sleep()") - time.Sleep(200 * time.Millisecond) - - if (state == "splash") { - log.Println("Display the splash box") - smallBox = account1.AddAccountBox(nil, splashClose) - cloudTab.InsertAt("Intro", 1, smallBox) - cloudTab.SetMargined(0, true) - // newbox.SetPadded(true) - state = "done" - } - if (state == "kill") { - log.Println("state = kill") - log.Println("state = kill") - log.Println("state = kill") - smallBox.Destroy() - state = "account1" - smallBox = nil - } - if (state == "account1") { - log.Println("Display the splash box") - smallBox = splash.ShowSplashBox(nil, nil, splashClose) - cloudTab.Append("WIT Account", smallBox) - cloudTab.SetMargined(0, true) - // newbox.SetPadded(true) - state = "done" - } - } -} - -func makeCloudWindow() { - cloudWindow := ui.NewWindow("", 640, 480, true) - // cloudWindow.SetBorderless(true) - cloudWindow.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - cloudWindow.Destroy() - return true - }) - -// cloudBox = ui.NewVerticalBox() -// cloudBox.SetPadded(true) -// cloudWindow.SetChild(cloudBox) -// cloudWindow.SetMargined(true) - - cloudTab = ui.NewTab() - cloudWindow.SetChild(cloudTab) - cloudWindow.SetMargined(true) - - cloudBox = splash.ShowSplashBox(nil, nil, buttonClick) - - cloudTab.Append("WIT Splash", cloudBox) - cloudTab.SetMargined(0, true) - - cloudWindow.Show() - // state = "done" -} diff --git a/test3/main.go b/test3/main.go index d4529dd..eff3cce 100644 --- a/test3/main.go +++ b/test3/main.go @@ -5,7 +5,7 @@ import "os" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -import "git.wit.com/wit/cloud-control-panel/splash" +import "git.wit.com/wit/gui" func main() { ui.Main(setupUI) @@ -27,10 +27,7 @@ func setupUI() { mainwin.SetChild(tab) mainwin.SetMargined(true) - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - - splash.ShowSplashBox(vbox, nil, nil) + vbox := gui.ShowSplashBox(nil, nil, nil) tab.Append("WIT Splash", vbox) tab.SetMargined(0, true) diff --git a/test4/main.go b/test4/main.go index 106d5ef..c09abd4 100644 --- a/test4/main.go +++ b/test4/main.go @@ -2,6 +2,7 @@ package main import "log" import "time" +import "os" import "git.wit.com/wit/gui" @@ -15,8 +16,14 @@ func main() { func buttonClick(i int, s string) { log.Println("test4 buttonClick() i, s =", i, s) - gui.ShowAccountTab() - gui.Data.State = "account1 done" + if (gui.Data.State == "splash") { + gui.ShowAccountQuestionTab() + gui.Data.State = "account1" + return + } else if (gui.Data.State == "account1") { + gui.ShowAccountTab() + gui.Data.State = "account2" + } } func watchGUI() { @@ -27,19 +34,11 @@ func watchGUI() { log.Println("Sleep()", gui.Data.State) time.Sleep(200 * time.Millisecond) - if (gui.Data.State == "splash") { - log.Println("Display the splash box") - gui.Data.State = "done" - } if (gui.Data.State == "kill") { log.Println("gui.State = kill") log.Println("gui.State = kill") log.Println("gui.State = kill") - gui.Data.State = "account1" - } - if (gui.Data.State == "account1") { - log.Println("Display the splash box") - gui.Data.State = "done" + os.Exit(0) } } }