From d96a94e9771329da0bfc6fc688c6fb7934a83e53 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 30 May 2019 00:50:57 -0700 Subject: [PATCH] more experiments on stability Signed-off-by: Jeff Carr --- .gitignore | 1 + example-multiple-windows/Makefile | 3 + example-multiple-windows/main.go | 117 ++++++++++++++++++++++++++++++ main.go | 10 +-- splash.go | 1 - test4/main.go | 15 ++-- 6 files changed, 133 insertions(+), 14 deletions(-) create mode 100644 example-multiple-windows/Makefile create mode 100644 example-multiple-windows/main.go diff --git a/.gitignore b/.gitignore index 540d4a3..74bffcc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ example-UI-table/example-UI-table example-dnssecsocket/example-dnssecsocket example-table/example-table example-aminal/example-aminal +example-multiple-windows/example-multiple-windows test1/test1 test2/test2 diff --git a/example-multiple-windows/Makefile b/example-multiple-windows/Makefile new file mode 100644 index 0000000..c9da29f --- /dev/null +++ b/example-multiple-windows/Makefile @@ -0,0 +1,3 @@ +run: + go build + ./example-multiple-windows diff --git a/example-multiple-windows/main.go b/example-multiple-windows/main.go new file mode 100644 index 0000000..5c91188 --- /dev/null +++ b/example-multiple-windows/main.go @@ -0,0 +1,117 @@ +package main + +// import "os" +import "log" +import "fmt" +import "time" + +import "github.com/davecgh/go-spew/spew" + +import "git.wit.com/wit/gui" +import pb "git.wit.com/wit/witProtobuf" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +var first *gui.WindowMap + +func main() { + var c *pb.Config + c = pb.MakeDefaultConfig() + + i := 1 + + c.Width = int32(400 + 50 * i) + c.Hostname = fmt.Sprintf("splash %d", i) + first = StartNewWindow(c, true, "SPLASH") + + i += 1 + c.Width = int32(400 + 50 * i) + c.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(c, false, "BLAH") + + i += 1 + c.Width = int32(400 + 50 * i) + c.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(c, false, "BLAH") + + for { + i += 1 + c.Width = int32(400 + 50 * i) + c.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(c, false, "SPLASH") + + i += 1 + c.Width = int32(400 + 50 * i) + c.Hostname = fmt.Sprintf("splash %d", i) + StartNewWindow(c, false, "BLAH") + } +} + +func StartNewWindow(c *pb.Config, bg bool, action string) *gui.WindowMap { + log.Println("InitNewWindow() Create a new window") + var newWindowMap *gui.WindowMap + newWindowMap = new(gui.WindowMap) + newWindowMap.C = c + + /* + ui.OnShouldQuit(func() bool { + // mouseClick(&newBM) + ui.Quit() + return true + }) + */ + + time.Sleep(1000 * time.Millisecond) + if (bg) { + log.Println("ShowWindow() IN NEW GOROUTINE") + go ui.Main(func() { + InitWindow(newWindowMap) + }) + time.Sleep(2000 * time.Millisecond) + } else { + log.Println("ShowWindow() WAITING for ui.Main()") + ui.Main(func() { + InitWindow(newWindowMap) + }) + } + return newWindowMap +} + +func InitWindow(wm *gui.WindowMap) { + log.Println("InitWindow() NEW WINDOW wm =", wm) + + c := wm.C + wm.W = ui.NewWindow("", int(c.Width), int(c.Height), true) + // wm.W.SetBorderless(false) + + blah := wm + wm.W.OnClosing(func(*ui.Window) bool { + log.Println("InitWindow() OnClosing() blah") + log.Println("InitWindow() OnClosing() blah") + log.Println("InitWindow() OnClosing() blah") + log.Println("InitWindow() OnClosing() blah") + spew.Dump(blah) + spew.Dump(wm) + wm.C = nil + log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING wm=", wm) + spew.Dump(wm) + spew.Dump(wm.W) + // mouseClick(&newBM) + if (wm.W != nil) { + wm.W.Hide() + } + time.Sleep(1000 * time.Millisecond) + spew.Dump(wm) + // wm.W.Destroy() + ui.Quit() + time.Sleep(1000 * time.Millisecond) + return true + }) + + // wm.W.SetChild(wm.T) + // wm.W.SetMargined(true) + + log.Println("InitWindow() Show() wm.Action =", wm.Action) + wm.W.Show() +} diff --git a/main.go b/main.go index 54f6410..76e7a9f 100644 --- a/main.go +++ b/main.go @@ -105,8 +105,8 @@ func main() { onExit(err) } - gui.Data.Width = int(config.Width) - gui.Data.Height = int(config.Height) +// gui.Data.Width = int(config.Width) +// gui.Data.Height = int(config.Height) // use this to discover what the OS thinks it's hostname is // seems to be cross platform (?) @@ -145,12 +145,6 @@ func main() { // make this the main loop in an attempt to figure out the crashes // do not change this until the GUI is stable gui.StartNewWindow(config, false, "SPLASH") - -// gui.Data.Window1 = new(gui.WindowMap) -// gui.Data.Window1.AreaText = getSplashText() - // this crashes here. crazy! - // gui.Data.Window1.AreaText = getNEWTEXT() - // gui.GoMainWindow() } // This is the handler for all mosue clicks (buttons, areas, etc)) diff --git a/splash.go b/splash.go index 6a1aa1c..b57e3e5 100644 --- a/splash.go +++ b/splash.go @@ -5,7 +5,6 @@ import "git.wit.com/wit/gui" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" - func getSplashText() *ui.AttributedString { var aText *ui.AttributedString aText = ui.NewAttributedString("Click to continue") diff --git a/test4/main.go b/test4/main.go index 7a29bba..0c95ec6 100644 --- a/test4/main.go +++ b/test4/main.go @@ -2,6 +2,7 @@ package main import "os" import "log" +import "fmt" import "github.com/davecgh/go-spew/spew" @@ -17,22 +18,26 @@ func main() { gui.Data.MouseClick = mainMouseClick - i := 0 + i := 1 - gui.Data.Hostname = "splash " + string(i) + c.Width += int32(100 * i) + c.Hostname = fmt.Sprintf("splash %d", i) gui.StartNewWindow(c, true, "SPLASH") i += 1 - gui.Data.Hostname = "splash " + string(i) + c.Width += int32(100 * i) + c.Hostname = fmt.Sprintf("splash %d", i) gui.StartNewWindow(c, true, "BLAH") for { i += 1 - gui.Data.Hostname = "splash " + string(i) + c.Width += int32(100 * i) + c.Hostname = fmt.Sprintf("splash %d", i) gui.StartNewWindow(c, false, "SPLASH") i += 1 - gui.Data.Hostname = "splash " + string(i) + c.Width += int32(100 * i) + c.Hostname = fmt.Sprintf("splash %d", i) gui.StartNewWindow(c, false, "BLAH") } }