2024-01-03 11:18:56 -06:00
|
|
|
package debugger
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
import (
|
2024-01-03 11:18:56 -06:00
|
|
|
"os"
|
|
|
|
|
2024-01-18 22:36:35 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 01:34:32 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/lib/gui/logsettings"
|
|
|
|
"go.wit.com/log"
|
2024-01-03 11:18:56 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
Creates a window helpful for debugging this package
|
|
|
|
*/
|
|
|
|
|
2024-01-20 20:24:58 -06:00
|
|
|
func DebugWindow() {
|
2024-01-18 01:34:32 -06:00
|
|
|
if me != nil {
|
2024-01-05 14:50:14 -06:00
|
|
|
log.Warn("Draw then Toggle() debuging window here")
|
2024-01-04 23:28:55 -06:00
|
|
|
me.bugWin.Toggle()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
me = new(debuggerSettings)
|
2024-01-20 20:24:58 -06:00
|
|
|
me.treeRoot = gui.TreeRoot()
|
2024-01-04 23:28:55 -06:00
|
|
|
|
2024-01-20 20:24:58 -06:00
|
|
|
me.bugWin = gadgets.NewBasicWindow(me.treeRoot, "go.wit.com/gui debug window")
|
|
|
|
me.bugWin.Make()
|
2024-01-05 16:56:03 -06:00
|
|
|
me.bugWin.Draw()
|
2024-01-04 23:28:55 -06:00
|
|
|
DebugWindow2(me.bugWin.Box(), "Debug Tab")
|
|
|
|
|
2024-01-03 13:25:47 -06:00
|
|
|
if ArgDebug() {
|
2024-01-03 11:18:56 -06:00
|
|
|
log.SetTmp()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-04 23:28:55 -06:00
|
|
|
func DebugWindow2(newB *gui.Node, title string) *gui.Node {
|
|
|
|
var gr *gui.Node
|
2024-01-03 11:18:56 -06:00
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
//////////////////////// main debug things //////////////////////////////////
|
2024-01-03 22:10:13 -06:00
|
|
|
gr = newB.NewGroup("Debugging Windows:")
|
2024-01-03 11:18:56 -06:00
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("logging", func() {
|
2024-01-20 20:24:58 -06:00
|
|
|
logsettings.LogWindow()
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("Widgets Window", func() {
|
2024-01-04 23:28:55 -06:00
|
|
|
if me.widgets == nil {
|
2024-01-20 20:24:58 -06:00
|
|
|
me.widgets = DebugWidgetWindow()
|
2024-01-04 23:28:55 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
me.widgets.Toggle()
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
|
|
|
|
2024-01-03 22:10:13 -06:00
|
|
|
gr.NewLabel("Force Quit:")
|
2024-01-03 11:18:56 -06:00
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("os.Exit()", func() {
|
2024-01-03 11:18:56 -06:00
|
|
|
os.Exit(0)
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
//////////////////////// window debugging things //////////////////////////////////
|
2024-01-03 22:10:13 -06:00
|
|
|
gr = newB.NewGroup("list things")
|
2024-01-03 11:18:56 -06:00
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("List Windows", func() {
|
2024-01-03 22:10:13 -06:00
|
|
|
dropdownWindow(gr)
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("List Window Widgets", func() {
|
2024-01-03 22:10:13 -06:00
|
|
|
dropdownWindowWidgets(gr)
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("Node.ListChildren(true)", func() {
|
|
|
|
if activeWidget == nil {
|
2024-01-03 11:18:56 -06:00
|
|
|
activeWidget = bugWin
|
|
|
|
}
|
|
|
|
activeWidget.ListChildren(true)
|
|
|
|
})
|
|
|
|
|
2024-01-27 09:04:00 -06:00
|
|
|
gr = newB.NewGroup("plugins")
|
|
|
|
|
|
|
|
gr.NewButton("List Toolkits", func() {
|
|
|
|
me.treeRoot.ListToolkits()
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
|
|
|
|
2024-01-27 09:04:00 -06:00
|
|
|
gr.NewButton("load toolkit 'nocui'", func() {
|
|
|
|
bugWin.LoadToolkit("nocui")
|
2024-01-03 11:18:56 -06:00
|
|
|
})
|
|
|
|
|
2024-01-30 11:07:35 -06:00
|
|
|
gr.NewButton("unload toolkit 'nocui'", func() {
|
|
|
|
bugWin.CloseToolkit("nocui")
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("load toolkit 'gocui'", func() {
|
2024-01-03 11:18:56 -06:00
|
|
|
bugWin.LoadToolkit("gocui")
|
|
|
|
})
|
|
|
|
|
2024-01-30 11:07:35 -06:00
|
|
|
gr.NewButton("unload toolkit 'gocui'", func() {
|
|
|
|
bugWin.CloseToolkit("gocui")
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("load toolkit 'andlabs'", func() {
|
2024-01-03 11:18:56 -06:00
|
|
|
bugWin.LoadToolkit("andlabs")
|
|
|
|
})
|
|
|
|
|
2024-01-30 11:07:35 -06:00
|
|
|
gr.NewButton("unload toolkit 'andlabs'", func() {
|
|
|
|
bugWin.CloseToolkit("andlabs")
|
|
|
|
})
|
|
|
|
|
2024-01-03 22:10:13 -06:00
|
|
|
gr = newB.NewGroup("Learn GO")
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("GO Language Internals", func() {
|
2024-01-04 23:28:55 -06:00
|
|
|
if me.golang == nil {
|
2024-01-20 20:24:58 -06:00
|
|
|
me.golang = DebugGolangWindow()
|
2024-01-04 23:28:55 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-05 16:56:03 -06:00
|
|
|
log.Warn("going to toggle golang window")
|
2024-01-04 23:28:55 -06:00
|
|
|
if me.golang.Ready() {
|
|
|
|
me.golang.Toggle()
|
|
|
|
}
|
2024-01-03 22:10:13 -06:00
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
gr.NewButton("GO Channels debug", func() {
|
2024-01-04 23:28:55 -06:00
|
|
|
if me.gochan == nil {
|
2024-01-20 20:24:58 -06:00
|
|
|
me.gochan = DebugGoChannels()
|
2024-01-04 23:28:55 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-05 16:56:03 -06:00
|
|
|
log.Warn("going to toggle go channels window")
|
2024-01-04 23:28:55 -06:00
|
|
|
if me.gochan.Ready() {
|
|
|
|
me.gochan.Toggle()
|
|
|
|
}
|
2024-01-03 22:10:13 -06:00
|
|
|
})
|
2024-01-27 09:04:00 -06:00
|
|
|
gr.NewButton("test conc", func() {
|
|
|
|
log.Log(WARN, "TODO: fix me")
|
|
|
|
// makeConc()
|
|
|
|
})
|
2024-01-03 22:10:13 -06:00
|
|
|
|
2024-01-03 11:18:56 -06:00
|
|
|
return newB
|
|
|
|
}
|
|
|
|
|
|
|
|
func dropdownWindow(p *gui.Node) {
|
|
|
|
var mapWindows map[string]*gui.Node
|
|
|
|
mapWindows = make(map[string]*gui.Node)
|
|
|
|
|
2024-01-17 22:43:57 -06:00
|
|
|
dd := p.NewDropdown()
|
2024-01-03 11:18:56 -06:00
|
|
|
dd.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
name := dd.String()
|
2024-01-03 11:18:56 -06:00
|
|
|
activeWidget = mapWindows[name]
|
|
|
|
setActiveWidget(activeWidget)
|
2024-01-08 22:33:18 -06:00
|
|
|
log.Log(INFO, "The Window was set to", name)
|
2024-01-03 11:18:56 -06:00
|
|
|
}
|
|
|
|
log.Log(INFO, "dd =", dd)
|
2024-01-18 01:34:32 -06:00
|
|
|
if activeWidget == nil {
|
2024-01-03 11:18:56 -06:00
|
|
|
// the debug window doesn't exist yet so you can't display the change
|
|
|
|
// TODO: make a fake binary tree for this(?)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// var last = ""
|
|
|
|
for _, child := range p.Children() {
|
2024-01-13 21:29:40 -06:00
|
|
|
log.Log(INFO, "\t\t", child.GetProgName())
|
2024-01-17 22:43:57 -06:00
|
|
|
dd.AddText(child.GetProgName())
|
2024-01-03 11:18:56 -06:00
|
|
|
// last = child.Name
|
2024-01-13 21:29:40 -06:00
|
|
|
mapWindows[child.GetProgName()] = child
|
2024-01-18 01:34:32 -06:00
|
|
|
if activeWidget == nil {
|
2024-01-03 11:18:56 -06:00
|
|
|
activeWidget = child
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dd.SetDropdownName(last)
|
|
|
|
}
|
|
|
|
|
|
|
|
func dropdownWindowWidgets(p *gui.Node) {
|
|
|
|
var mapWindows map[string]*gui.Node
|
|
|
|
mapWindows = make(map[string]*gui.Node)
|
|
|
|
|
2024-01-17 22:43:57 -06:00
|
|
|
dd := p.NewDropdown()
|
2024-01-03 11:18:56 -06:00
|
|
|
dd.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
name := dd.String()
|
2024-01-03 11:18:56 -06:00
|
|
|
activeWidget = mapWindows[name]
|
|
|
|
setActiveWidget(activeWidget)
|
|
|
|
}
|
|
|
|
log.Log(INFO, "dd =", dd)
|
|
|
|
|
|
|
|
// log.Log("dumpWidget() ", b, listChildrenDepth, defaultPadding, n.id, info)
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
var addDropdowns func(*gui.Node)
|
|
|
|
addDropdowns = func(n *gui.Node) {
|
2024-01-03 11:18:56 -06:00
|
|
|
// s := n.dumpWidget(true)
|
2024-01-13 21:29:40 -06:00
|
|
|
s := n.GetProgName()
|
2024-01-17 22:43:57 -06:00
|
|
|
dd.AddText(s)
|
2024-01-03 11:18:56 -06:00
|
|
|
mapWindows[s] = n
|
|
|
|
|
|
|
|
for _, child := range n.Children() {
|
|
|
|
addDropdowns(child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// list everything in the binary tree
|
|
|
|
addDropdowns(bugWin)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setActiveWidget(w *gui.Node) {
|
2024-01-04 23:28:55 -06:00
|
|
|
log.Warn("TODO: setActiveWidget()")
|
2024-01-03 11:18:56 -06:00
|
|
|
}
|