From b9d10aed57184c005b71304c128de10c95541d48 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 22 May 2019 09:05:23 -0700 Subject: [PATCH] crashes randomly but sometimes works. Strange. Signed-off-by: Jeff Carr --- Makefile | 3 +++ splash/area.go | 8 +++---- splash/splash.go | 29 ++++++++++++++------------ test2/main.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 3ae8ef7..76321b6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ +GOVER = $(shell go version) + run: + @echo your version of go must be greater than 2.10. Your version is ${GOVER} go build ./cloud-control-panel diff --git a/splash/area.go b/splash/area.go index fe8473c..75559f7 100644 --- a/splash/area.go +++ b/splash/area.go @@ -87,8 +87,8 @@ func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { log.Println("GOT MOUSE UP") log.Println("GOT MOUSE UP") log.Println("GOT MOUSE UP") - splashWin.Destroy() - ui.Quit() + // splashWin.Destroy() + // ui.Quit() } } @@ -113,7 +113,7 @@ func (ah areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { log.Println("GOT ENTER") } spew.Dump(ke) - splashWin.Destroy() - ui.Quit() + // splashWin.Destroy() + // ui.Quit() return false } diff --git a/splash/splash.go b/splash/splash.go index 77ef400..f23d456 100644 --- a/splash/splash.go +++ b/splash/splash.go @@ -10,10 +10,11 @@ import "runtime" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -var splashWin *ui.Window +// var splashWin *ui.Window +var MyArea *ui.Area -func ShowSplash() { - splashWin = ui.NewWindow("", 640, 480, true) +func ShowSplash() *ui.Window { + splashWin := ui.NewWindow("", 640, 480, true) splashWin.SetBorderless(true) splashWin.OnClosing(func(*ui.Window) bool { ui.Quit() @@ -30,19 +31,21 @@ func ShowSplash() { splashWin.SetMargined(true) // This displays the window - splashWin.Show() + // splashWin.Show() ShowSplashBox(vbox, nil) + + return splashWin } -func ShowSplashBox(junk *ui.Box, atest chan int) *ui.Box { - vbox := ui.NewVerticalBox() +func ShowSplashBox(vbox *ui.Box, atest chan int) *ui.Box { + // vbox := ui.NewVerticalBox() vbox.SetPadded(true) makeAttributedString() - myArea := makeSplashArea() + MyArea = makeSplashArea() - vbox.Append(myArea, true) + vbox.Append(MyArea, true) if runtime.GOOS == "linux" { vbox.Append(ui.NewLabel("OS: Linux"), false) @@ -57,11 +60,11 @@ func ShowSplashBox(junk *ui.Box, atest chan int) *ui.Box { okButton := ui.NewButton("OK") okButton.OnClicked(func(*ui.Button) { - log.Println("OK. Closing window.") - test := 4 - atest <- test - splashWin.Destroy() - ui.Quit() + log.Println("OK. Should close window here") + // test := 4 + // atest <- test + // splashWin.Destroy() + // ui.Quit() }) vbox.Append(okButton, false) diff --git a/test2/main.go b/test2/main.go index f48e770..0e87438 100644 --- a/test2/main.go +++ b/test2/main.go @@ -1,5 +1,8 @@ package main +import "log" +import "time" + import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -7,10 +10,59 @@ 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" +var cloudWindow *ui.Window +var cloudBox *ui.Box +var state string + func main() { - ui.Main(splash.ShowSplash) + go watchGUI() + + ui.Main(makeCloudWindow) ui.Main(account1.AddAccountWindow) ui.Main(account2.AddAccountWindow) } + +func watchGUI() { + log.Println("Sleep()") + time.Sleep(2000 * time.Millisecond) + + for { + log.Println("Sleep()") + time.Sleep(200 * time.Millisecond) + + if (state == "splash") { + log.Println("Sleep()") + time.Sleep(200 * time.Millisecond) + log.Println("Display the splash box") + splash.ShowSplashBox(cloudBox, nil) + // 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) + + // splash.ShowSplashBox(cloudBox, nil) + + // This displays the window + cloudWindow.Show() + state = "splash" +}