debugger/main.go

195 lines
4.1 KiB
Go
Raw Normal View History

2024-01-03 11:18:56 -06:00
package debugger
import (
"os"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
"go.wit.com/gui/lib/logsettings"
2024-01-03 11:18:56 -06:00
)
/*
Creates a window helpful for debugging this package
*/
func DebugWindow(p *gui.Node) {
if (me != nil) {
log.Warn("Draw then Toggle() debuging window here")
me.bugWin.Toggle()
return
}
me = new(debuggerSettings)
me.myGui = p
me.bugWin = gadgets.NewBasicWindow(p,"go.wit.com/gui debug window")
me.bugWin.Draw()
DebugWindow2(me.bugWin.Box(), "Debug Tab")
// initialize the log settings window (does not display it)
me.myLS = logsettings.New(me.myGui)
if ArgDebug() {
2024-01-03 11:18:56 -06:00
log.SetTmp()
}
}
func DebugWindow2(newB *gui.Node, title string) *gui.Node {
var gr *gui.Node
2024-01-03 11:18:56 -06:00
//////////////////////// main debug things //////////////////////////////////
gr = newB.NewGroup("Debugging Windows:")
2024-01-03 11:18:56 -06:00
gr.NewButton("logging", func () {
me.myLS.Toggle()
2024-01-03 11:18:56 -06:00
})
gr.NewButton("Widgets Window", func () {
if me.widgets == nil {
me.widgets = DebugWidgetWindow(me.myGui)
return
}
me.widgets.Toggle()
2024-01-03 11:18:56 -06:00
})
gr.NewLabel("Force Quit:")
2024-01-03 11:18:56 -06:00
gr.NewButton("os.Exit()", func () {
2024-01-03 11:18:56 -06:00
os.Exit(0)
})
//////////////////////// window debugging things //////////////////////////////////
gr = newB.NewGroup("list things")
2024-01-03 11:18:56 -06:00
gr.NewButton("List toolkits", func () {
dropdownWindow(gr)
2024-01-03 11:18:56 -06:00
bugWin.ListToolkits()
})
gr.NewButton("List Windows", func () {
dropdownWindow(gr)
2024-01-03 11:18:56 -06:00
})
gr.NewButton("List Window Widgets", func () {
dropdownWindowWidgets(gr)
2024-01-03 11:18:56 -06:00
})
gr = newB.NewGroup("more things")
2024-01-03 11:18:56 -06:00
gr.NewButton("Node.ListChildren(true)", func () {
2024-01-03 11:18:56 -06:00
if (activeWidget == nil) {
activeWidget = bugWin
}
activeWidget.ListChildren(true)
})
gr.NewButton("test conc", func () {
log.Log(WARN, "TODO: fix me")
2024-01-03 11:18:56 -06:00
// makeConc()
})
gr.NewButton("List Plugins", func () {
log.Log(WARN, "TODO: fix me")
2024-01-03 11:18:56 -06:00
/*
for _, aplug := range allPlugins {
log.Log(true, "Loaded plugin:", aplug.name, aplug.filename)
}
*/
})
gr.NewButton("load toolkit 'gocui'", func () {
2024-01-03 11:18:56 -06:00
bugWin.LoadToolkit("gocui")
})
gr.NewButton("load toolkit 'andlabs'", func () {
2024-01-03 11:18:56 -06:00
bugWin.LoadToolkit("andlabs")
})
gr = newB.NewGroup("Learn GO")
gr.NewButton("GO Language Internals", func () {
if me.golang == nil {
me.golang = DebugGolangWindow(me.myGui)
return
}
log.Warn("going to toggle golang window")
if me.golang.Ready() {
me.golang.Toggle()
}
})
gr.NewButton("GO Channels debug", func () {
if me.gochan == nil {
me.gochan = DebugGoChannels(me.myGui)
return
}
log.Warn("going to toggle go channels window")
if me.gochan.Ready() {
me.gochan.Toggle()
}
})
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)
dd := p.NewDropdown()
2024-01-03 11:18:56 -06:00
dd.Custom = func() {
name := dd.String()
2024-01-03 11:18:56 -06:00
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
log.Log(INFO, "The Window was set to", name)
2024-01-03 11:18:56 -06:00
}
log.Log(INFO, "dd =", dd)
if (activeWidget == nil) {
// 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() {
log.Log(INFO, "\t\t", child.GetProgName())
dd.AddText(child.GetProgName())
2024-01-03 11:18:56 -06:00
// last = child.Name
mapWindows[child.GetProgName()] = child
2024-01-03 11:18:56 -06:00
if (activeWidget == nil) {
activeWidget = child
}
}
// dd.SetDropdownName(last)
}
func dropdownWindowWidgets(p *gui.Node) {
var mapWindows map[string]*gui.Node
mapWindows = make(map[string]*gui.Node)
dd := p.NewDropdown()
2024-01-03 11:18:56 -06:00
dd.Custom = func() {
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)
var addDropdowns func (*gui.Node)
addDropdowns = func (n *gui.Node) {
// s := n.dumpWidget(true)
s := n.GetProgName()
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) {
log.Warn("TODO: setActiveWidget()")
2024-01-03 11:18:56 -06:00
}