From 682fc29bab24c5f8aaf0360022efac9b18a753cb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 12:56:33 -0700 Subject: [PATCH 1/5] better display and debugging Signed-off-by: Jeff Carr --- area.go | 4 ++-- debug.go | 42 ++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/area.go b/area.go index 732b241..3c41f62 100644 --- a/area.go +++ b/area.go @@ -107,7 +107,7 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString, custom func(*GuiButton)) *GuiBox { +func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString, custom func(*GuiButton), name string) *GuiBox { log.Println("ShowTextBox() START") if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") @@ -118,7 +118,7 @@ func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString, custom func(*GuiBu var newbox *GuiBox newbox = new(GuiBox) newbox.Window = gw - newbox.Name = "Hbox1" + newbox.Name = name hbox := ui.NewVerticalBox() newbox.UiBox = hbox diff --git a/debug.go b/debug.go index 42937d1..9d862bc 100644 --- a/debug.go +++ b/debug.go @@ -20,24 +20,8 @@ func WatchGUI() { for { if (count > 20) { log.Println("Sleep() in watchGUI()") - for i, window := range Data.Windows { - log.Println("watchGUI() Data.Windows", i, "Name =", window.Name) - for name, abox := range window.BoxMap { - log.Printf("\twatchGUI() BOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - /* - if (name == "DEBUG") { - log.Println("\t\twatchGUI() BOX abox =", reflect.TypeOf(abox)) - win := abox.Window - log.Println("\t\twatchGUI() BOX win =", reflect.TypeOf(win)) - area := win.Area - log.Println("\t\twatchGUI() BOX area =", reflect.TypeOf(area), area.UiArea) - // spew.Dump(area.UiArea) - // area.UiArea.Show() - // time.Sleep(2000 * time.Millisecond) - // os.Exit(0) - } - */ - } + if (Config.Debug) { + DumpBoxes() } count = 0 } @@ -46,6 +30,28 @@ func WatchGUI() { } } +func DumpBoxes() { + for i, window := range Data.Windows { + log.Println("watchGUI() Data.Windows", i, "Name =", window.Name) + for name, abox := range window.BoxMap { + log.Printf("\twatchGUI() BOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + /* + if (name == "DEBUG") { + log.Println("\t\twatchGUI() BOX abox =", reflect.TypeOf(abox)) + win := abox.Window + log.Println("\t\twatchGUI() BOX win =", reflect.TypeOf(win)) + area := win.Area + log.Println("\t\twatchGUI() BOX area =", reflect.TypeOf(area), area.UiArea) + // spew.Dump(area.UiArea) + // area.UiArea.Show() + // time.Sleep(2000 * time.Millisecond) + // os.Exit(0) + } + */ + } + } +} + func addTableTab() { var parts []TableColumnData From adfc58a6c9c986bcebbee3dbf4ef119914c3b186 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 13:03:00 -0700 Subject: [PATCH 2/5] log output here Signed-off-by: Jeff Carr --- gui.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gui.go b/gui.go index 0bb6310..d27d8c2 100644 --- a/gui.go +++ b/gui.go @@ -120,9 +120,13 @@ func normalizeInt(s string) string { } func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { + log.Println("gui.MessageWindow() msg1 =", msg1) + log.Println("gui.MessageWindow() msg2 =", msg2) ui.MsgBox(gw.UiWindow, msg1, msg2) } func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { + log.Println("gui.ErrorWindow() msg1 =", msg1) + log.Println("gui.ErrorWindow() msg2 =", msg2) ui.MsgBoxError(gw.UiWindow, msg1, msg2) } From 7ec7fd15c06a31f98e586b62ea96172ddc47954e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 14:17:29 -0700 Subject: [PATCH 3/5] fix window name Signed-off-by: Jeff Carr --- gui.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gui.go b/gui.go index d27d8c2..e54517c 100644 --- a/gui.go +++ b/gui.go @@ -18,12 +18,12 @@ func GuiInit() { }) } -func InitGuiWindow(action string, gw *GuiWindow) *GuiWindow { +func InitGuiWindow(name string, gw *GuiWindow) *GuiWindow { log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow newGuiWindow.Width = Config.Width newGuiWindow.Height = Config.Height -// newGuiWindow.Action = action + newGuiWindow.Name = name newGuiWindow.MakeWindow = gw.MakeWindow newGuiWindow.UiWindow = gw.UiWindow newGuiWindow.UiTab = gw.UiTab @@ -40,12 +40,11 @@ func InitGuiWindow(action string, gw *GuiWindow) *GuiWindow { } -func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) { +func StartNewWindow(bg bool, name string, callback func(*GuiWindow) *GuiBox) { log.Println("StartNewWindow() Create a new window") var junk GuiWindow junk.MakeWindow = callback -// junk.Action = action - window := InitGuiWindow(action, &junk) + window := InitGuiWindow(name, &junk) if (bg) { log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") go ui.Main(func() { @@ -65,7 +64,7 @@ func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) { func InitTabWindow(gw *GuiWindow) { log.Println("InitTabWindow() START. THIS WINDOW IS NOT YET SHOWN") - gw.UiWindow = ui.NewWindow("InitTabWindow()", int(gw.Width), int(gw.Height), true) + gw.UiWindow = ui.NewWindow(gw.Name, int(gw.Width), int(gw.Height), true) gw.UiWindow.SetBorderless(false) gw.UiWindow.OnClosing(func(*ui.Window) bool { From 8d9f0b6a34134dc7e35bd4b5d4c8c73c1895bbe5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 15:45:40 -0700 Subject: [PATCH 4/5] make a WindowMap to track which windows exist Signed-off-by: Jeff Carr --- debug.go | 7 +++++-- gui.go | 14 ++++++++++++-- structs.go | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/debug.go b/debug.go index 9d862bc..89ac686 100644 --- a/debug.go +++ b/debug.go @@ -31,10 +31,13 @@ func WatchGUI() { } func DumpBoxes() { + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() Data.WindowMap name =", name, "Window.Name =", window.Name) + } for i, window := range Data.Windows { - log.Println("watchGUI() Data.Windows", i, "Name =", window.Name) + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name) for name, abox := range window.BoxMap { - log.Printf("\twatchGUI() BOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) /* if (name == "DEBUG") { log.Println("\t\twatchGUI() BOX abox =", reflect.TypeOf(abox)) diff --git a/gui.go b/gui.go index e54517c..ef1ff49 100644 --- a/gui.go +++ b/gui.go @@ -12,6 +12,8 @@ const Yaxis = 1 // box that is vertical func GuiInit() { Data.buttonMap = make(map[*ui.Button]*GuiButton) + Data.WindowMap = make(map[string]*GuiWindow) + ui.OnShouldQuit(func() bool { ui.Quit() return true @@ -29,8 +31,16 @@ func InitGuiWindow(name string, gw *GuiWindow) *GuiWindow { newGuiWindow.UiTab = gw.UiTab newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) - newGuiWindow.EntryMap["test"] = nil - Data.Windows = append(Data.Windows, &newGuiWindow) + Data.Windows = append(Data.Windows, &newGuiWindow) + + if (Data.WindowMap == nil) { + log.Println("gui.InitGuiWindow() making the Data.WindowMap here") + Data.WindowMap = make(map[string]*GuiWindow) + } + Data.WindowMap[name] = &newGuiWindow + + // make a blank entry for testing + // newGuiWindow.EntryMap["test"] = nil if (Data.buttonMap == nil) { GuiInit() diff --git a/structs.go b/structs.go index a074e56..aae0b7f 100644 --- a/structs.go +++ b/structs.go @@ -29,6 +29,7 @@ type GuiData struct { // A map of all the entry boxes AllEntries []*GuiEntry Windows []*GuiWindow + WindowMap map[string]*GuiWindow // A map of all buttons everywhere on all // windows, all tabs, across all goroutines From 8faa174170a22d80ca7b76648cff1831614959ce Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 17:05:50 -0700 Subject: [PATCH 5/5] fixes for debugging Signed-off-by: Jeff Carr --- debug.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/debug.go b/debug.go index 89ac686..1a20532 100644 --- a/debug.go +++ b/debug.go @@ -3,11 +3,11 @@ package gui import "log" import "time" import "fmt" -// import "reflect" +import "reflect" // import "github.com/andlabs/ui" // import _ "github.com/andlabs/ui/winmanifest" -// import "github.com/davecgh/go-spew/spew" +import "github.com/davecgh/go-spew/spew" // import pb "git.wit.com/wit/witProtobuf" // @@ -32,7 +32,16 @@ func WatchGUI() { func DumpBoxes() { for name, window := range Data.WindowMap { - log.Println("gui.DumpBoxes() Data.WindowMap name =", name, "Window.Name =", window.Name) + log.Println("gui.DumpBoxes()", name) + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + if (window.UiTab != nil) { + log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", window.UiTab.NumPages()) + spew.Dump(window.UiTab) + } } for i, window := range Data.Windows { log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name)