From c6343150465ef4ccc2f8d1d7e865a16569ca2c81 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 30 May 2019 00:51:59 -0700 Subject: [PATCH] more work on stability Signed-off-by: Jeff Carr --- area.go | 10 +++---- mainCloudBox.go | 79 +++++++++++++++++++++---------------------------- splash.go | 12 ++++---- structs.go | 4 +-- 4 files changed, 47 insertions(+), 58 deletions(-) diff --git a/area.go b/area.go index 7ea70e3..9c1e5b9 100644 --- a/area.go +++ b/area.go @@ -20,17 +20,17 @@ func findFB(button *ButtonMap) *ButtonMap { return a } -func makeSplashArea(ah *AreaHandler) { +func makeSplashArea(wm *WindowMap, ah *AreaHandler) { // make this button just to get the default font (but don't display the button) // There should be another way to do this (?) - wm := ah.WM - newB := CreateFontButton(wm, "AREA") + newB := CreateFontButton(wm, "AREA") // ah.Attrstr = makeAttributedString() ah.Area = ui.NewArea(ah) newB.A = ah.Area - Data.AllButtons[1].A = ah.Area - ah.Button = &Data.AllButtons[1] + // Data.AllButtons[1].A = ah.Area + // ah.Button = &Data.AllButtons[1] + ah.Button = newB if (Data.Debug) { spew.Dump(ah.Area) diff --git a/mainCloudBox.go b/mainCloudBox.go index 2863396..670ae7b 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -3,7 +3,7 @@ package gui import "log" import "time" import "regexp" -import "reflect" +// import "reflect" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -224,79 +224,68 @@ func StartNewWindow(c *pb.Config, bg bool, action string) { return true }) - for i, aWM := range(Data.Windows) { - log.Println(aWM) - if (aWM.W == nil) { - log.Println("ShowWindow() THIS WINDOW IS NOT YET SHOWN i=", i) - log.Println("ShowWindow() THIS WINDOW IS NOT YET SHOWN aWM=", reflect.TypeOf(aWM)) - // Data.NewWindow = &aWM - // Data.NewWindow = i - // ui.Main(InitWindow) - time.Sleep(200 * time.Millisecond) - if (bg) { - ui.Main(func() { - InitWindow(Data.Windows[i], i) - }) - } else { - ui.Main(func() { - InitWindow(Data.Windows[i], i) - }) - } - return - } + 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) + }) } } -func getSplashText() *ui.AttributedString { +func getSplashText(a string) *ui.AttributedString { var aText *ui.AttributedString - aText = ui.NewAttributedString("Click to continue") + aText = ui.NewAttributedString(a) return aText } -func InitWindow(wm *WindowMap, i int) { +func InitWindow(wm *WindowMap) { log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN") - // i := Data.NewWindow - log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN i=", i) - c := Data.Windows[i].C - Data.Windows[i].W = ui.NewWindow("", int(c.Width), int(c.Height), true) - Data.Windows[i].W.SetBorderless(false) + c := wm.C + wm.W = ui.NewWindow("", int(c.Width), int(c.Height), true) + wm.W.SetBorderless(false) // create a 'fake' button entry for the mouse clicks var newBM ButtonMap newBM.Action = "QUIT" - newBM.W = Data.Windows[i].W - newBM.WM = Data.Windows[i] + newBM.W = wm.W + newBM.WM = wm Data.AllButtons = append(Data.AllButtons, newBM) - Data.Windows[i].W.OnClosing(func(*ui.Window) bool { - log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING i=", i) + wm.W.OnClosing(func(*ui.Window) bool { + log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING wm=", wm) // mouseClick(&newBM) ui.Quit() return true }) - Data.Windows[i].T = ui.NewTab() - Data.Windows[i].W.SetChild(Data.Windows[i].T) - Data.Windows[i].W.SetMargined(true) + wm.T = ui.NewTab() + wm.W.SetChild(wm.T) + wm.W.SetMargined(true) - log.Println("InitWindow() i =", i) - log.Println("InitWindow() Data.Windows[i] =", Data.Windows[i]) - log.Println("InitWindow() Data.Windows[i].Action =", Data.Windows[i].Action) + log.Println("InitWindow() wm =", wm) + log.Println("InitWindow() wm.Action =", wm.Action) - if (Data.Windows[i].Action == "SPLASH") { + if (wm.Action == "SPLASH") { log.Println("InitWindow() TRYING SPLASH") - tmp := getSplashText() + damnit := "click" + string(c.Hostname) + tmp := getSplashText(damnit) log.Println("InitWindow() TRYING SPLASH tmp =", tmp) - Data.Windows[i].Box1 = ShowSplashBox(Data.Windows[i], i, tmp) + wm.Box1 = ShowSplashBox(wm, tmp) - Data.Windows[i].T.Append("WIT Splash", Data.Windows[i].Box1) - Data.Windows[i].T.SetMargined(0, true) + wm.T.Append("WIT Splash", wm.Box1) + wm.T.SetMargined(0, true) } - Data.Windows[i].W.Show() Data.State = "splash" + wm.W.Show() } // makeEntryBox(box, "hostname:", "blah.foo.org") { diff --git a/splash.go b/splash.go index 168286a..18796df 100644 --- a/splash.go +++ b/splash.go @@ -11,7 +11,7 @@ import "runtime" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -func ShowSplashBox(wm *WindowMap, i int, newText *ui.AttributedString) *ui.Box { +func ShowSplashBox(wm *WindowMap, newText *ui.AttributedString) *ui.Box { log.Println("ShowSplashBox() START") log.Println("ShowSplashBox() START wm =", wm) if (wm == nil) { @@ -23,12 +23,12 @@ func ShowSplashBox(wm *WindowMap, i int, newText *ui.AttributedString) *ui.Box { newbox.SetPadded(true) // initialize the AreaHandler{} - Data.Windows[i].AH = new(AreaHandler) - Data.Windows[i].AH.WM = wm - Data.Windows[i].AH.Attrstr = newText - makeSplashArea(Data.Windows[i].AH) + wm.AH = new(AreaHandler) + wm.AH.WM = wm + wm.AH.Attrstr = newText + makeSplashArea(wm, wm.AH) - newbox.Append(Data.Windows[i].AH.Area, true) + newbox.Append(wm.AH.Area, true) if runtime.GOOS == "linux" { newbox.Append(ui.NewLabel("OS: Linux"), false) diff --git a/structs.go b/structs.go index f094a55..a5cb3ae 100644 --- a/structs.go +++ b/structs.go @@ -17,8 +17,8 @@ var Data GuiData type GuiData struct { State string - Width int - Height int + // Width int + // Height int // a fallback default function to handle mouse events // if nothing else is defined to handle them