commit 6b49c4139e0ec885d8790f6dba794f2c7272c074 Author: Jeff Carr Date: Wed Jan 3 11:18:56 2024 -0600 start moving this stuff out diff --git a/args.go b/args.go new file mode 100644 index 0000000..670262d --- /dev/null +++ b/args.go @@ -0,0 +1,34 @@ +package debugger + +// initializes logging and command line options + +import ( + arg "github.com/alexflint/go-arg" + log "go.wit.com/log" +) + +var INFO log.LogFlag +var POLL log.LogFlag +var BUG log.LogFlag +var argDebugger ArgsDebugger + +// This struct can be used with the go-arg package +type ArgsDebugger struct { + Debugger bool `arg:"--debugger" help:"open the debugger window"` +} + +func init() { + arg.Register(&argDebugger) + + INFO.B = false + INFO.Name = "INFO" + INFO.Subsystem = "bugger" + INFO.Desc = "simple debugging Info()" + INFO.Register() + + POLL.B = false + POLL.Name = "POLL" + POLL.Subsystem = "bugger" + POLL.Desc = "watch the debugger poll things" + POLL.Register() +} diff --git a/mainWindow.go b/mainWindow.go new file mode 100644 index 0000000..6d535cd --- /dev/null +++ b/mainWindow.go @@ -0,0 +1,183 @@ +package debugger + +import ( + "os" + + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +// main debugging window +var myGui *gui.Node +var bugWin *gui.Node +var bugTab *gui.Node + +var mapWindows map[string]*gui.Node // tracks all windows that exist + +/* + Creates a window helpful for debugging this package +*/ + +func DebugWindow(p *gui.Node) { + myGui = p + bugWin = myGui.NewWindow("go.wit.com/gui debug window") + bugWin.StandardClose() + bugTab = DebugWindow2(bugWin, "Debug Tab") + bugTab.StandardClose() + if gui.ArgDebug() { + log.SetTmp() + // myGui.DebugFlags() + } +} + +func DebugWindow2(n *gui.Node, title string) *gui.Node { + var newW, newB, gog, g1 *gui.Node + // var logSettings *gadgets.LogSettings + + // time.Sleep(1 * time.Second) + newW = n.NewWindow(title) + + newB = newW.NewBox("hBox", true) + +//////////////////////// main debug things ////////////////////////////////// + gog = newB.NewGroup("Debugging Windows:") + + // generally useful debugging + cb := gog.NewCheckbox("Seperate windows") + cb.Custom = func() { + log.Log(BUG, "Custom() n.widget =", cb.Name, cb.B) + n.SetTabs(cb.B) + } + cb.Set(false) + n.SetTabs(false) + + gog.NewButton("logging", func () { + bugWin.DebugFlags() + }) + gog.NewButton("Debug Widgets", func () { + gui.DebugWidgetWindow(myGui) + }) + gog.NewButton("GO Language Internals", func () { + bugWin.DebugGolangWindow() + }) + gog.NewButton("GO Channels debug", func () { + bugWin.DebugGoChannels() + }) + + gog.NewLabel("Force Quit:") + + gog.NewButton("os.Exit()", func () { + os.Exit(0) + }) + +//////////////////////// window debugging things ////////////////////////////////// + g1 = newB.NewGroup("list things") + + g1.NewButton("List toolkits", func () { + dropdownWindow(g1) + bugWin.ListToolkits() + }) + g1.NewButton("List Windows", func () { + dropdownWindow(g1) + }) + g1.NewButton("List Window Widgets", func () { + dropdownWindowWidgets(g1) + }) + + g2 := newB.NewGroup("more things") + + g2.NewButton("Node.ListChildren(true)", func () { + if (activeWidget == nil) { + activeWidget = bugWin + } + activeWidget.ListChildren(true) + }) + + g2.NewButton("test conc", func () { + log.Log(true, "TODO: fix me") + // makeConc() + }) + + g2.NewButton("List Plugins", func () { + log.Log(true, "TODO: fix me") + /* + for _, aplug := range allPlugins { + log.Log(true, "Loaded plugin:", aplug.name, aplug.filename) + } + */ + }) + + g2.NewButton("load toolkit 'gocui'", func () { + bugWin.LoadToolkit("gocui") + }) + + g2.NewButton("load toolkit 'andlabs'", func () { + bugWin.LoadToolkit("andlabs") + }) + + return newB +} + +func dropdownWindow(p *gui.Node) { + var mapWindows map[string]*gui.Node + mapWindows = make(map[string]*gui.Node) + + dd := p.NewDropdown("Window Dropdown") + dd.Custom = func() { + name := dd.S + activeWidget = mapWindows[name] + setActiveWidget(activeWidget) + log.Log(true, "The Window was set to", name) + } + 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.GetName()) + dd.AddDropdownName(child.GetName()) + // last = child.Name + mapWindows[child.GetName()] = child + 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("Window Widgets Dropdown") + dd.Custom = func() { + name := dd.S + 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.GetName() + dd.AddDropdownName(s) + mapWindows[s] = n + + for _, child := range n.Children() { + addDropdowns(child) + } + } + + // list everything in the binary tree + addDropdowns(bugWin) +} + +func setActiveWidget(w *gui.Node) { +} diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..c02a12c --- /dev/null +++ b/structs.go @@ -0,0 +1,32 @@ +package debugger + +import ( + "go.wit.com/gui/gui" + // "go.wit.com/gui/gui/toolkit" +) + + +// global var for checking to see if this +// window/tab for debugging a widget exists +// check the binary tree instead (?) for a window called "Widgets" (bad idea) +var bugWidget *gui.Node + +// the widget all these actions are run against +var activeWidget *gui.Node + +// for testing move, this is the node things are put on +var activeJunk *gui.Node + +// the label where the user can see which widget is active +var activeLabel *gui.Node +var activeLabelType *gui.Node +var activeLabelNewName *gui.Node +var activeLabelNewType *gui.Node +var activeLabelNewX *gui.Node +var activeLabelNewY *gui.Node +var activeLabelNewB *gui.Node + +// tmp junk +var debugGrid *gui.Node +var debugGridLabel *gui.Node +var debugWidgetBut1, debugWidgetBut2 *gui.Node