more logging updates

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-21 11:30:12 -06:00
parent 4f3255c681
commit 40f819c3a2
11 changed files with 89 additions and 77 deletions

View File

@ -14,20 +14,26 @@ import (
// and that there already a widget created
func notNew(n *tree.Node) bool {
if n == nil {
log.Warn("ready() n = nil")
log.Log(ERROR, "notNew() n = nil")
return true
}
if n.TK != nil {
log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "notNew() n.TK = nil", n.WidgetId, n.GetProgName())
return true
}
if n.Parent == nil {
log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "notNew() n.Parent = nil", n.WidgetId, n.GetProgName())
return true
}
if n.Parent.TK == nil {
log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
if n.Parent.WidgetId == 0 {
// this is normal if the widget type is a window
if n.WidgetType == widget.Window {
return true
}
}
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
return true
}
// this means you can add a new widgets
@ -36,11 +42,11 @@ func notNew(n *tree.Node) bool {
func tkbad(n *tree.Node) bool {
if n == nil {
log.Warn("ready() n = nil")
log.Log(ERROR, "tkbad() n = nil")
return true
}
if n.TK == nil {
log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "tkbad() n.TK = nil", n.WidgetId, n.GetProgName())
return true
}
return false
@ -49,20 +55,26 @@ func tkbad(n *tree.Node) bool {
// this makes sure widget and it's parent exists
func ready(n *tree.Node) bool {
if n == nil {
log.Warn("ready() n = nil")
log.Log(ERROR, "ready() n = nil")
return false
}
if n.TK == nil {
log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "ready() n.TK = nil", n.WidgetId, n.GetProgName())
return false
}
if n.Parent == nil {
log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "ready() n.Parent = nil", n.WidgetId, n.GetProgName())
return false
}
if n.Parent.TK == nil {
log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
if n.Parent.WidgetId == 0 {
// this is normal if the widget type is a window
if n.WidgetType == widget.Window {
return false
}
}
log.Log(ERROR, "ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
return false
}
return true
@ -112,7 +124,7 @@ func pad(n *tree.Node, b bool) {
if tkbad(n) {
return
}
log.Warn("pad() on WidgetId =", n.WidgetId)
log.Log(ANDLABS, "pad() on WidgetId =", n.WidgetId)
t := n.TK.(*guiWidget)
if t == nil {
@ -138,23 +150,25 @@ func pad(n *tree.Node, b bool) {
}
func widgetDelete(n *tree.Node) {
log.Log(NOW, "widgetDelete()", n.WidgetId)
log.Log(ANDLABS, "widgetDelete()", n.WidgetId, n.WidgetType)
var tk *guiWidget
tk = n.TK.(*guiWidget)
if n.WidgetType == widget.Window {
log.Warn("DESTROY uiWindow here")
log.Warn("NEED TO REMOVE n from parent.Children")
log.Log(ANDLABS, "DESTROY uiWindow here")
log.Log(ANDLABS, "DESTROY NEED TO REMOVE n from parent.Children")
if tk.uiWindow != nil {
tk.uiWindow.Destroy()
tk.uiWindow = nil
}
n.DeleteNode()
} else {
log.Log(ANDLABS, "DESTROY can't destroy TODO:", n.WidgetId, n.WidgetType)
}
}
func processAction(a *widget.Action) {
log.Warn("processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
log.Log(ANDLABS, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
if a.ActionType == widget.ToolkitInit {
Init()
@ -166,13 +180,13 @@ func processAction(a *widget.Action) {
log.Log(INFO, "processAction() found the treeRoot")
me.treeRoot = me.myTree.AddNode(a)
} else {
log.Warn("processAction() Something terrible has happened")
log.Warn("processAction() treeNode was sent an action", a.ActionType, a)
log.Log(ERROR, "processAction() Something terrible has happened")
log.Log(ERROR, "processAction() treeNode was sent an action", a.ActionType, a)
}
return
}
log.Warn("andlabs processAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId, a.ActionType)
log.Log(ANDLABS, "andlabs processAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId, a.ActionType)
switch a.WidgetType {
case widget.Flag:
log.Log(ERROR, "processAction() RE-IMPLEMENT LOG FLAGS")
@ -197,6 +211,11 @@ func processAction(a *widget.Action) {
// this is normal. the widget is aleady deleted
return
}
if a.WidgetType == widget.Window {
// this could happen maybe someday
log.Log(ANDLABS, "processAction() trying on nonexistant window", a.WidgetId, a.ActionType)
return
}
log.Error(errors.New("andlabs processAction() ERROR findWidgetId found nil"), a.ActionType, a.WidgetType)
log.Log(NOW, "processAction() ERROR findWidgetId found nil for id =", a.WidgetId)
log.Log(NOW, "processAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
@ -221,7 +240,7 @@ func processAction(a *widget.Action) {
case widget.Enable:
enable(n, true)
case widget.Disable:
log.Warn("andlabs got disable for", n.WidgetId, n.State.ProgName)
log.Log(ANDLABS, "andlabs got disable for", n.WidgetId, n.State.ProgName)
enable(n, false)
case widget.Checked:
setChecked(n, a.State.Checked)
@ -235,7 +254,7 @@ func processAction(a *widget.Action) {
case widget.Set:
setText(n, a)
case widget.SetText:
log.Warn("andlabs SetText wid =", n.WidgetId, n.State.Value, a.State.Value)
log.Log(ANDLABS, "andlabs SetText wid =", n.WidgetId, n.State.Value, a.State.Value)
setText(n, a)
case widget.AddText:
addText(n, a)

4
add.go
View File

@ -7,7 +7,7 @@ import (
)
func add(a *widget.Action) *tree.Node {
log.Warn("andlabs add()", a.WidgetId, a.State.ProgName)
log.Log(ANDLABS, "add()", a.WidgetId, a.WidgetType, a.State.ProgName)
if a.WidgetType == widget.Root {
if me.treeRoot == nil {
me.treeRoot = me.myTree.AddNode(a)
@ -19,10 +19,8 @@ func add(a *widget.Action) *tree.Node {
p := n.Parent
switch n.WidgetType {
case widget.Window:
log.Warn("SPEEDY Add window", n.WidgetId, n.GetProgName())
newWindow(p, n)
case widget.Group:
log.Warn("SPEEDY Add Group", n.WidgetId, n.GetProgName())
newGroup(p, n)
case widget.Grid:
newGrid(n)

View File

@ -13,23 +13,23 @@ func compareStrings(n *tree.Node, ss []string) {
func addText(n *tree.Node, a *widget.Action) {
var tk *guiWidget
tk = n.TK.(*guiWidget)
log.Warn("andlabs addText() START with a.Value =", a.Value)
log.Log(ANDLABS, "addText() START with a.Value =", a.Value)
if tk == nil {
log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId)
return
}
log.Warn("andlabs addText() Attempt on", n.WidgetType, "with", a.Value)
log.Log(ANDLABS, "addText() Attempt on", n.WidgetType, "with", a.Value)
switch n.WidgetType {
case widget.Dropdown:
for i, s := range a.State.Strings {
log.Warn("andlabs a.State.Strings =", i, s)
log.Log(ANDLABS, "a.State.Strings =", i, s)
_, ok := n.Strings[s]
// If the key exists
if ok {
log.Warn("andlabs a.State.Strings is here", i, s)
log.Log(ANDLABS, "string is already in the dropdown", i, s)
} else {
log.Warn("andlabs is not here", i, s)
log.Log(ANDLABS, "adding new string to dropdown", i, s)
addDropdownName(n, s)
// TODO: make numbers
n.Strings[s] = 21
@ -40,5 +40,5 @@ func addText(n *tree.Node, a *widget.Action) {
default:
log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType)
}
log.Log(CHANGE, "addText() END with a.Value =", a.Value)
log.Log(ANDLABS, "addText() END with a.Value =", a.Value)
}

View File

@ -22,7 +22,7 @@ func newCheckbox(p *tree.Node, n *tree.Node) {
var b bool
b = newt.checked()
n.SetValue(b)
log.Warn("Checkbox is now =", b)
log.Log(ANDLABS, "Checkbox is now =", b)
me.myTree.SendUserEvent(n)
})

View File

@ -24,23 +24,21 @@ func newCombobox(p, n *tree.Node) {
cb.OnChanged(func(spin *ui.EditableCombobox) {
n.SetValue(spin.Text())
log.Warn("combobox changed =" + spin.Text() + ".")
log.Log(ANDLABS, "combobox changed ="+spin.Text()+".")
me.myTree.SendUserEvent(n)
})
n.TK = newt
place(p, n)
log.Warn("add combobox entries on create:", n.State.Strings)
log.Warn("add combobox entries on create:", n.State.Strings)
log.Warn("add combobox entries on create:", n.State.Strings)
log.Log(ANDLABS, "add combobox entries on create:", n.State.Strings)
// add the initial combobox entries
for i, s := range n.State.Strings {
log.Warn("add combobox entries on create", n.GetProgName(), i, s)
log.Log(ANDLABS, "add combobox entries on create", n.GetProgName(), i, s)
addComboboxName(n, s)
}
cur := n.String()
log.Warn("add combobox: TODO: set default value on create", n.GetProgName(), cur)
log.Log(ANDLABS, "add combobox: set default value on create to", n.GetProgName(), cur)
setComboboxName(n, cur)
}

View File

@ -37,19 +37,17 @@ func newDropdown(p, n *tree.Node) {
n.TK = newt
place(p, n)
log.Warn("add dropdown entries on create:", n.State.Strings)
log.Warn("add dropdown entries on create:", n.State.Strings)
log.Warn("add dropdown entries on create:", n.State.Strings)
log.Log(ANDLABS, "add dropdown entries on create:", n.State.Strings)
if n.State.Strings == nil {
return
}
// add the initial dropdown entries
for i, s := range n.State.Strings {
log.Warn("add dropdown: add entries on create", n.GetProgName(), i, s)
log.Log(ANDLABS, "add dropdown: add entries on create", n.GetProgName(), i, s)
addDropdownName(n, s)
}
cur := n.String()
log.Warn("add dropdown: set default value on create", n.GetProgName(), cur)
log.Log(ANDLABS, "add dropdown: set default value on create", n.GetProgName(), cur)
setDropdownName(n, cur)
}
@ -97,10 +95,10 @@ func setDropdownName(n *tree.Node, s string) bool {
if s == tmp {
n.SetValue(s)
setDropdownInt(n, i)
log.Warn("SetDropdownInt() worked", tmp, i)
log.Log(ANDLABS, "SetDropdownInt() worked", tmp, i)
return true
}
}
log.Warn("SetDropdownName() failed", s)
log.Warn("SetDropdownName() failed", s, n.WidgetId, n.GetProgName())
return false
}

View File

@ -16,7 +16,7 @@ var WARN *log.LogFlag
var ERROR *log.LogFlag
var CHANGE *log.LogFlag
var TOOLKIT *log.LogFlag
var ANDLABS *log.LogFlag
func init() {
full := "go.wit.com/toolkits/andlabs"
@ -28,7 +28,10 @@ func init() {
WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
ERROR = log.NewFlag("ERROR", false, full, short, "toolkit errors")
CHANGE = log.NewFlag("ERROR", false, full, short, "show when the user does things")
TOOLKIT = log.NewFlag("ERROR", false, full, short, "andlabs specific stuff")
CHANGE = log.NewFlag("CHANGE", false, full, short, "show when the user does things")
full = "go.wit.com/gui"
short = "andlabs"
ERROR = log.NewFlag("ERROR", false, full, short, "andlab toolkit errors")
ANDLABS = log.NewFlag("ANDLABS", false, full, short, "andlabs specific stuff")
}

View File

@ -36,7 +36,7 @@ func queueMain(currentA widget.Action) {
// it's easier to code it this way however
// also, if it dies here, it get's caught
// usually, this is where it dies
log.Warn("about to send action into the andlabs ui.QueueMain()")
log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()")
ui.QueueMain(func() {
processAction(&currentA)
})
@ -46,8 +46,8 @@ func guiMain() {
defer func() {
if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in guiMain application:", r)
log.Println("Recovered from panic:", r)
log.Println("Stack trace:")
log.Warn("Recovered from panic:", r)
log.Warn("Stack trace:")
debug.PrintStack()
me.myTree.SendToolkitPanic()
return

View File

@ -37,41 +37,40 @@ import (
// -----------------------------
func place(p *tree.Node, n *tree.Node) bool {
log.Warn("SPEEDY newplace() 1 START", n.WidgetId, n.GetProgName(), n.GetLabel(), n.String())
log.Warn("SPEEDY newplace() n.State.Strings =", n.State.Strings)
log.Log(INFO, "place() 1 START", n.WidgetType, n.GetProgName(), n.GetLabel())
if !ready(n) {
log.Warn("place() 1 START not ready()")
if n.WidgetType == widget.Window {
// TODO: figure out window in window placement
return true
}
log.Log(ERROR, "place() 1 START not ready()", n.WidgetType, n.GetProgName(), n.GetLabel())
return false
}
log.Log(INFO, "place() 1 START ready()")
var tk, ptk *guiWidget
tk = n.TK.(*guiWidget)
ptk = p.TK.(*guiWidget)
log.Warn("SPEEDY newplace() 2 START", n.WidgetId, n.GetProgName(), n.GetLabel())
if ptk == nil {
log.Log(ERROR, "ptk == nil", p.GetProgName(), p.ParentId, p.WidgetType, ptk)
log.Log(ERROR, "n = ", n.GetProgName(), n.ParentId, n.WidgetType, tk)
log.Warn("SPEEDY ptk == nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "SPEEDY ptk == nil", n.WidgetId, n.GetProgName())
log.Sleep(1)
panic("ptk == nil")
}
log.Log(INFO, "place() switch", p.WidgetType)
log.Warn("SPEEDY newplace() before switch", n.WidgetId, n.GetProgName())
log.Log(INFO, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName())
switch p.WidgetType {
case widget.Grid:
tk.gridX = n.State.GridOffset.X - 1
tk.gridY = n.State.GridOffset.Y - 1
log.Warn("place() on Grid at gridX,gridY", tk.gridX, tk.gridY)
log.Log(INFO, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY)
ptk.uiGrid.Append(tk.uiControl,
tk.gridX, tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case widget.Group:
if ptk.uiBox == nil {
log.Log(WARN, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType)
log.Log(ANDLABS, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType)
n.State.Direction = widget.Vertical
ptk.uiBox = rawBox(n)
ptk.uiGroup.SetChild(ptk.uiBox)
@ -99,7 +98,6 @@ func place(p *tree.Node, n *tree.Node) bool {
ptk.boxC += 1
return true
case widget.Box:
log.Warn("SPEEDY Add Something to Box", n.WidgetId, n.GetProgName())
log.Log(INFO, "place() uiBox =", ptk.uiBox)
log.Log(INFO, "place() uiControl =", tk.uiControl)
if n.WidgetType == widget.Textbox {
@ -110,12 +108,12 @@ func place(p *tree.Node, n *tree.Node) bool {
ptk.boxC += 1
return true
case widget.Window:
log.Warn("SPEEDY Add Something to Window", n.WidgetId, n.GetProgName())
log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName())
ptk.uiWindow.SetChild(tk.uiControl)
return true
default:
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
}
log.Warn("SPEEDY newplace() return", n.WidgetId, n.GetProgName())
log.Log(ERROR, "newplace() returned without doing anything", n.WidgetId, n.GetProgName())
return false
}

View File

@ -21,7 +21,7 @@ func setText(n *tree.Node, a *widget.Action) {
switch n.WidgetType {
case widget.Window:
log.Warn("setText() Attempt to set the title to", name)
log.Log(CHANGE, "setText() Attempt to set the title to", name)
tk.uiWindow.SetTitle(a.State.Label)
case widget.Tab:
case widget.Group:

20
tab.go
View File

@ -32,16 +32,16 @@ func (p *node) newTab(n *node) {
}
t := p.tk
log.Log(TOOLKIT, "newTab() START", n.WidgetId, n.ParentId)
log.Log(ANDLABS, "newTab() START", n.WidgetId, n.ParentId)
if t.uiTab == nil {
// this means you have to make a new tab
log.Log(TOOLKIT, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
log.Log(ANDLABS, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
newt = rawTab(t.uiWindow, widget.GetString(n.value))
t.uiTab = newt.uiTab
} else {
// this means you have to append a tab
log.Log(TOOLKIT, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
log.Log(ANDLABS, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
if n.WidgetType == widget.Tab {
// andlabs doesn't have multiple tab widgets so make a fake one?
// this makes a guiWidget internal structure with the parent values
@ -63,18 +63,16 @@ func (p *node) newTab(n *node) {
func tabSetMargined(tab *ui.Tab, b bool) {
c := tab.NumPages()
for i := 0; i < c; i++ {
log.Log(TOOLKIT, "SetMargined", i, b)
log.Log(ANDLABS, "SetMargined", i, b)
tab.SetMargined(i, b)
}
}
func rawTab(w *ui.Window, name string) *guiWidget {
var newt guiWidget
log.Log(TOOLKIT, "rawTab() START", name)
log.Log(ANDLABS, "rawTab() START", name)
if w == nil {
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
// sleep(1)
return nil
@ -84,20 +82,20 @@ func rawTab(w *ui.Window, name string) *guiWidget {
w.SetChild(tab)
newt.uiTab = tab
newt.uiControl = tab
log.Log(TOOLKIT, "rawTab() END", name)
log.Log(ANDLABS, "rawTab() END", name)
return &newt
}
/*
func (t *guiWidget) appendTab(name string) *guiWidget {
var newT guiWidget
log.Log(TOOLKIT, "appendTab() ADD", name)
log.Log(ANDLABS, "appendTab() ADD", name)
if t.uiTab == nil {
log.Log(TOOLKIT, "UiWindow == nil. I can't add a widget without a place to put it")
log.Log(ANDLABS, "UiWindow == nil. I can't add a widget without a place to put it")
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
}
log.Log(TOOLKIT, "appendTab() START name =", name)
log.Log(ANDLABS, "appendTab() START name =", name)
var hbox *ui.Box
if defaultBehavior {