all debug stuff moved to 'go.wit.com/gui/debugger'

I finally was able to clean out all the debugging
    code and make a clean, new GO debugger. It's quite
    nice I think. Well, it's useful to me at any rate.

    2024 New Years wish: someone contributes code to improve it

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-03 13:37:03 -06:00
parent 253e850c12
commit 25ebe0a2ee
9 changed files with 20 additions and 904 deletions

View File

@ -10,7 +10,6 @@ var argGui ArgsGui
// This struct can be used with the go-arg package
type ArgsGui struct {
GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"`
GuiPlugin string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"`
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
}
@ -29,8 +28,3 @@ func init() {
func ArgToolkit() string {
return argGui.GuiPlugin
}
// returns true if --gui-debug was passed from the command line
func ArgDebug() bool {
return argGui.GuiDebug
}

View File

@ -98,6 +98,12 @@ func (n *Node) AppendText(str string) {
sendAction(a)
}
// THESE TWO FUNCTIONS ARE TERRIBLY NAMED AND NEED TO BE FIXED
// 5 seconds worth of ideas:
// Value() ?
// Progname() Reference() ?
// should get the value of the node
func (n *Node) GetText() string {
if (n.S != n.Text) {
newlog.Warn("GetText() is screwed up. TODO: fix this dumb crap")
@ -110,6 +116,14 @@ func (n *Node) GetText() string {
return n.Text
}
// should get the value of the node
// myButton = myGroup.NewButton("hit ball", nil).SetName("HIT")
// myButton.GetName() should return "HIT"
// n = Find("HIT") should return myButton
func (n *Node) GetName() string {
return n.Name
}
/*
// string handling examples that might be helpful for normalizeInt()
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString

View File

@ -144,6 +144,10 @@ func (n *Node) dumpWidget(b bool) string {
return tabs + d
}
func (n *Node) Children() []*Node {
return n.children
}
// func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (n *Node) ListChildren(dump bool) {
if (n == nil) {

View File

@ -1,118 +0,0 @@
package gui
import (
newlog "go.wit.com/log"
)
type LogSettings struct {
ready bool
hidden bool
err error
name string
parent *Node // should be the root of the 'gui' package binary tree
window *Node // our window for displaying the log package settings
group *Node //
grid *Node //
checkbox *Node
label *Node
}
func (ls *LogSettings) Set(b bool) {
newlog.Set(ls.name, b)
ls.checkbox.Set(b)
}
func (p *Node) NewLogFlag(name string) *LogSettings {
ls := new(LogSettings)
ls.parent = p
ls.ready = false
ls.name = name
ls.checkbox = p.NewCheckbox(name)
ls.label = p.NewLabel("Enable log." + name)
ls.checkbox.Set(newlog.Get(name))
ls.checkbox.Custom = func() {
newlog.Set(name, ls.checkbox.B)
}
return ls
}
// Let's you toggle on and off the various types of debugging output
// These checkboxes should be in the same order as the are printed
func (n *Node) DebugFlags() {
var w, g *Node
logGadgets := make(map[string]*LogSettings)
// Either:
// make a new window
// make a new tab in the existing window
if (n.UseTabs()) {
w = me.rootNode.NewWindow("Debug Flags")
w.Custom = w.StandardClose
w = w.NewBox("hBox", true)
} else {
w = n.NewTab("Flags")
}
g = w.NewGroup("Show").Pad()
g.NewButton("log.SetTmp()", func () {
newlog.SetTmp()
})
g.NewButton("log.All(true)", func () {
for _, lf := range logGadgets {
lf.Set(true)
}
newlog.All(true)
})
g.NewButton("log.All(false)", func () {
for _, lf := range logGadgets {
lf.Set(false)
}
newlog.All(false)
})
g.NewButton("Dump Flags", func () {
// ShowDebugValues()
newlog.ListFlags()
})
/*
g.NewButton("All On", func () {
SetDebug(true)
})
g.NewButton("All Off", func () {
SetDebug(false)
})
*/
g = w.NewGroup("List")
g = g.NewGrid("flags grid", 2, 2)
logGadgets["INFO"] = g.NewLogFlag("INFO")
logGadgets["WARN"] = g.NewLogFlag("WARN")
logGadgets["SPEW"] = g.NewLogFlag("SPEW")
logGadgets["ERROR"] = g.NewLogFlag("ERROR")
// generally useful debugging
cb1 := g.NewCheckbox("debug Gui")
g.NewLabel("like verbose=1")
cb1.Custom = func() {
debugGui = cb1.B
log(debugGui, "Custom() n.widget =", cb1.Name, cb1.B)
}
// turns on debugging inside the plugin toolkit
cb7 := g.NewCheckbox("debug Toolkit")
g.NewLabel("the plugin internals)")
cb7.Custom = func() {
// SetDebugToolkit(cb7.B)
SetFlag("Toolkit", cb7.B)
}
}

View File

@ -1,97 +0,0 @@
// https://www.digitalocean.com/community/tutorials/how-to-run-multiple-functions-concurrently-in-go
// who came up with the idea of making community tutorials. that was a good idea!
package gui
import (
"fmt"
"sync"
)
var debugWG *sync.WaitGroup
var debugNumberChan chan int
func (n *Node) DebugGoChannels() {
var w, g *Node
w = n.NewWindow("Debug GO Channels")
w.Custom = w.StandardClose
g = w.NewGroup("Channel stuff")
// var debugWG sync.WaitGroup
g.NewButton("init()", func () {
if (debugNumberChan == nil) {
log(true, "making debugNumberChan channel")
debugNumberChan = make(chan int)
} else {
log(true, "debugNumberChan already made")
}
debugWG = new(sync.WaitGroup)
})
g.NewButton("go printInt(x) (read x values off the channel)", func () {
debugWG.Add(1)
go printInt(2, "routine1")
debugWG.Add(1)
go printInt(2, "routine2")
})
g.NewButton("sendNumber(2) (chan <- 2, 4)", func () {
debugWG.Add(1)
debugWG.Add(1)
go sendNumber(2)
go sendNumber(4)
})
g.NewButton("sendNumber(1) (chan <- 7)", func () {
debugWG.Add(1)
go sendNumber(7)
})
g.NewButton("send 4 numbers (chan <- int)", func () {
log(true, "generateNumbers(4)")
go generateNumbers(4)
})
g.NewButton("debugWG.Done()", func () {
log(true, "ran debugWG.Done()")
debugWG.Done()
})
g.NewButton("close chan", func () {
log(true, "close() on", debugNumberChan)
close(debugNumberChan)
})
g.NewButton("print", func () {
log(true, "waitgroup counter is ?")
})
}
func sendNumber(i int) {
log(true, "START debugNumberChan <-", i, " (sending", i, "to channel)")
debugNumberChan <- i
debugWG.Wait()
log(true, "END debugNumberChan sendNumber() done", i)
}
func generateNumbers(total int) {
fmt.Printf("START generateNumbers()\n")
for idx := 1; idx <= total; idx++ {
log(true, "ran debugNumberChan <= idx where idx =", idx)
fmt.Printf("S generateNumbers() sending %d to channel\n", idx)
debugNumberChan <- idx
// res, err := (<-r)()
fmt.Printf("E generateNumbers() sending %d to channel\n", idx)
}
debugWG.Wait()
fmt.Printf("END generateNumbers()\n")
}
// i equals the number of times to read values from the channel
func printInt(i int, name string) {
tmp := 1
log(true, "START printInt", name, "read debugNumberChan()")
for num := range debugNumberChan {
log(true, "printInt()",name, "read", num, "from channel")
debugWG.Done()
if (tmp == i) {
return
}
tmp += 1
}
fmt.Printf("END printInt()", name, "read debugNumberChan\n")
}

View File

@ -1,171 +0,0 @@
package gui
import (
"fmt"
"bytes"
// "os"
"runtime"
"runtime/debug"
"runtime/pprof"
)
func (n *Node) DebugGolangWindow() {
var w, g, og, outputTextbox *Node
w = n.NewWindow("GO")
w.Custom = w.StandardClose
g = w.NewGroup("Language Internals")
g.NewButton("ReadModuleInfo()", func () {
tmp, _ := debug.ReadBuildInfo()
outputTextbox.SetText(tmp.String())
})
g.NewButton("runtime.NumGoroutine()", func () {
buf := new(bytes.Buffer)
pprof.Lookup("goroutine").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
outputTextbox.AppendText(fmt.Sprintln("runtime.NumGoroutine() = ", runtime.NumGoroutine()))
})
g.NewButton("pprof.Lookup(heap)", func () {
buf := new(bytes.Buffer)
pprof.Lookup("heap").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
})
g.NewButton("debug.PrintStack(current)", func () {
outputTextbox.SetText(string(debug.Stack()))
})
g.NewButton("pprof.Lookup(goroutine)", func () {
buf := new(bytes.Buffer)
pprof.Lookup("goroutine").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
})
g.NewButton("pprof.Lookup(block)", func () {
buf := new(bytes.Buffer)
pprof.Lookup("block").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
})
g.NewButton("pprof.Lookup threadcreate", func () {
buf := new(bytes.Buffer)
pprof.Lookup("threadcreate").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
})
g.NewButton("runtime.ReadMemStats()", func () {
outputTextbox.SetText(runtimeReadMemStats())
})
g.NewButton("debug.FreeOSMemory()", func () {
var out string = "Before debug.FreeOSMemory():\n\n"
out += runtimeReadMemStats()
debug.FreeOSMemory()
out += "\n\nAfter debug.FreeOSMemory():\n\n"
out += runtimeReadMemStats()
outputTextbox.SetText(out)
})
g.NewButton("debug.ReadGCStats()", func () {
var tmp debug.GCStats
var out string
debug.ReadGCStats(&tmp)
log(true, tmp)
out += fmt.Sprintln("LastGC:", tmp.LastGC, "// time.Time time of last collection")
out += fmt.Sprintln("NumGC:", tmp.NumGC, "// number of garbage collections")
out += fmt.Sprintln("PauseTotal:", tmp.PauseTotal, "// total pause for all collections")
out += fmt.Sprintln("Pause:", tmp.Pause, "// []time.Duration pause history, most recent first")
out += fmt.Sprintln("PauseEnd:", tmp.Pause, "// []time.Time pause history, most recent first")
out += fmt.Sprintln("PauseQuantiles:", tmp.PauseQuantiles, "// []time.Duration")
outputTextbox.SetText(out)
})
g.NewButton("debug.SetTraceback('all')", func () {
debug.SetTraceback("all")
})
g.NewButton("panic()", func () {
panic("test")
})
g = w.NewGroup("TODO: finish these")
// g.NewLabel("TODO:")
g.NewButton("runtime.Stack(true)", func () {
// TODO: https://stackoverflow.com/questions/61127053/how-to-list-all-the-running-goroutines-in-a-go-program
// func Stack(buf []byte, all bool) int
})
g.NewButton("debug.SetMemoryLimit(int)", func () {
// TODO:
//debug.SetMemoryLimit(1024 * 1024 * 100)
})
g.NewButton("debug.SetMaxStack(int bytes)", func () {
// default is apparently 1GB
})
g.NewButton("debug.SetMaxThreads(int)", func () {
// default is apparently 10,000
})
g.NewButton("debug.SetTraceback('all')", func () {
debug.SetTraceback("all")
})
// deprecated (probably) by String() implementation within golang
g.NewButton("dumpModuleInfo() (deprecate)", func () {
outputTextbox.SetText(dumpModuleInfo())
})
og = w.NewGroup("output")
outputTextbox = og.NewTextbox("outputBox")
outputTextbox.Custom = func () {
log(true, "custom TextBox() for golang output a =", outputTextbox.S, outputTextbox.id)
}
}
func runtimeReadMemStats() string {
var s runtime.MemStats
var out string
runtime.ReadMemStats(&s)
out += fmt.Sprintln("alloc:", s.Alloc, "bytes")
out += fmt.Sprintln("total-alloc:", s.TotalAlloc, "bytes")
out += fmt.Sprintln("sys:", s.Sys, "bytes")
out += fmt.Sprintln("lookups:", s.Lookups)
out += fmt.Sprintln("mallocs:", s.Mallocs)
out += fmt.Sprintln("frees:", s.Frees)
out += fmt.Sprintln("heap-alloc:", s.HeapAlloc, "bytes")
out += fmt.Sprintln("heap-sys:", s.HeapSys, "bytes")
out += fmt.Sprintln("heap-idle:", s.HeapIdle,"bytes")
out += fmt.Sprintln("heap-in-use:", s.HeapInuse, "bytes")
out += fmt.Sprintln("heap-released:", s.HeapReleased, "bytes")
out += fmt.Sprintln("heap-objects:", s.HeapObjects)
out += fmt.Sprintln("stack-in-use:", s.StackInuse, "bytes")
out += fmt.Sprintln("stack-sys", s.StackSys, "bytes")
out += fmt.Sprintln("next-gc: when heap-alloc >=", s.NextGC, "bytes")
out += fmt.Sprintln("last-gc:", s.LastGC, "ns")
out += fmt.Sprintln("gc-pause:", s.PauseTotalNs, "ns")
out += fmt.Sprintln("num-gc:", s.NumGC)
out += fmt.Sprintln("enable-gc:", s.EnableGC)
out += fmt.Sprintln("debug-gc:", s.DebugGC)
return out
}
func dumpModuleInfo() string {
var out string
tmp, _ := debug.ReadBuildInfo()
if tmp == nil {
out += fmt.Sprintln("This wasn't compiled with go module support")
return ""
}
out += fmt.Sprintln("mod.Path = ", tmp.Path)
out += fmt.Sprintln("mod.Main.Path = ", tmp.Main.Path)
out += fmt.Sprintln("mod.Main.Version = ", tmp.Main.Version)
out += fmt.Sprintln("mod.Main.Sum = ", tmp.Main.Sum)
for _, value := range tmp.Deps {
out += fmt.Sprintln("\tmod.Path = ", value.Path)
out += fmt.Sprintln("\tmod.Version = ", value.Version)
}
return out
}

View File

@ -1,302 +0,0 @@
package gui
import (
"strconv"
"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 *Node
// the widget all these actions are run against
var activeWidget *Node
// for testing move, this is the node things are put on
var activeJunk *Node
// the label where the user can see which widget is active
var activeLabel *Node
var activeLabelType *Node
var activeLabelNewName *Node
var activeLabelNewType *Node
var activeLabelNewX *Node
var activeLabelNewY *Node
var activeLabelNewB *Node
// tmp junk
var debugGrid *Node
var debugGridLabel *Node
var debugWidgetBut1, debugWidgetBut2 *Node
func setActiveWidget(w *Node) {
if (w == nil) {
log(debugError, "setActiveWidget() was sent nil !!!")
return
}
activeWidget = w
log(true, "The Widget is set to", w.id, w.Name)
if (activeLabel == nil) {
// the debug window doesn't exist yet so you can't display the change
// TODO: make a fake binary tree for this(?)
return
}
title := "ID =" + strconv.Itoa(w.id) + " " + w.Name
activeLabel.SetText(title)
activeLabelType.SetText("widget.Type = " + w.WidgetType.String())
return
}
func DebugWidgetWindow(w *Node) {
if (bugWidget != nil) {
// this window was already created. Just change the widget we are working against
setActiveWidget(w)
return
}
// Either:
// make a new window
// make a new tab in the existing window
if (me.rootNode.UseTabs()) {
bugWidget = me.rootNode.NewWindow("Widgets")
bugWidget.Custom = bugWidget.StandardClose
} else {
bugWidget = bugWin.NewTab("Widgets")
}
g := bugWidget.NewGroup("widget:")
g2 := g.NewGroup("widget:")
activeLabel = g2.NewLabel("undef")
g2 = g.NewGroup("type:")
activeLabelType = g2.NewLabel("undef")
g2 = g.NewGroup("New name:")
activeLabelNewName = g2.NewCombobox("newthing")
activeLabelNewName.AddText("penguin")
activeLabelNewName.AddText("snow")
activeLabelNewName.AddText("GO")
activeLabelNewName.AddText("debian")
activeLabelNewName.AddText("RiscV")
g2 = g.NewGroup("At X:")
activeLabelNewX = g2.NewSpinner("tmp spinner", -1, 100)
g2 = g.NewGroup("At Y:")
activeLabelNewY = g2.NewSpinner("tmp spinner", -1, 100)
g2 = g.NewGroup("bool B:")
activeLabelNewB = g2.NewCheckbox("tmp bool")
// common things that should work against each widget
g = bugWidget.NewGroup("common things")
g.NewButton("Enable()", func () {
activeWidget.Enable()
})
g.NewButton("Disable()", func () {
activeWidget.Disable()
})
g.NewButton("Show()", func () {
activeWidget.Show()
})
g.NewButton("Hide()", func () {
activeWidget.Hide()
})
g.NewButton("Dump()", func () {
activeWidget.Dump()
})
g = bugWidget.NewGroup("add things")
g.debugAddWidgetButton()
g.NewLabel("experiments:")
g.debugAddWidgetButtons()
g = bugWidget.NewGroup("change things")
g.NewButton("AddText()", func () {
activeWidget.S = activeLabelNewName.S
a := newAction(activeWidget, toolkit.AddText)
sendAction(a)
})
g.NewButton("SetText()", func () {
activeWidget.S = activeLabelNewName.S
a := newAction(activeWidget, toolkit.SetText)
sendAction(a)
})
g.NewButton("Margin()", func () {
a := newAction(activeWidget, toolkit.Margin)
sendAction(a)
})
g.NewButton("Unmargin()", func () {
a := newAction(activeWidget, toolkit.Unmargin)
sendAction(a)
})
g.NewButton("Pad()", func () {
a := newAction(activeWidget, toolkit.Pad)
sendAction(a)
})
g.NewButton("Unpad()", func () {
a := newAction(activeWidget, toolkit.Unpad)
sendAction(a)
})
g.NewButton("Move(junk)", func () {
a := newAction(activeWidget, toolkit.Move)
sendAction(a)
})
g.NewButton("Delete()", func () {
a := newAction(activeWidget, toolkit.Delete)
sendAction(a)
})
g = bugWidget.NewGroup("not working?")
activeJunk = bugWidget.NewGroup("junk:")
activeJunk.NewLabel("test junk")
if (activeWidget == nil) {
setActiveWidget(me.rootNode)
}
}
func (n *Node) debugAddWidgetButtons() {
n.NewButton("Dropdown", func () {
a := activeWidget.NewDropdown("tmp dropdown")
a.AddText("this is better than tcl/tk")
a.AddText("make something for tim for qflow")
a.AddText("and for riscv")
a.Custom = func () {
log(true, "custom dropdown() a =", a.Name, a.S, "id=", a.id)
}
})
n.NewButton("Combobox", func () {
a := activeWidget.NewCombobox("tmp combobox")
a.AddText("mirrors.wit.com")
a.AddText("go.wit.com")
a.Custom = func () {
log(true, "custom combobox() a =", a.Name, a.S, "id=", a.id)
}
})
n.NewButton("Grid", func () {
// Grid numbering by (X,Y)
// -----------------------------
// -- (1,1) -- (2,1) -- (3,1) --
// -- (1,2) -- (2,1) -- (3,1) --
// -----------------------------
// SetDebug(true)
debugGrid = activeWidget.NewGrid("tmp grid", 2, 3)
debugGridLabel = debugGrid.NewLabel("mirrors.wit.com")
/*
debugGrid.SetNext(0,1)
debugGrid.NewLabel("foo (0,1)")
debugGrid.SetNext(1,1)
debugGrid.NewLabel("foo (1,1)")
debugGrid.SetNext(2,1)
debugGrid.NewLabel("foo (2,1)")
*/
// SetDebug(false)
DebugWidgetWindow(debugGrid)
})
n.NewButton("Image", func () {
activeWidget.NewImage("image")
})
n.NewButton("Box(horizontal)", func () {
a := activeWidget.NewBox("hBox", true)
a.NewLabel("hBox")
a.NewLabel("hBox 2")
})
n.NewButton("Box(vertical)", func () {
a := activeWidget.NewBox("vBox", false)
a.NewLabel("vBox")
a.NewLabel("vBox 2")
})
}
func (n *Node) debugAddWidgetButton() {
activeLabelNewType = n.NewDropdown("tmp dropdown")
activeLabelNewType.AddText("Window")
activeLabelNewType.AddText("Tab")
activeLabelNewType.AddText("Frame")
activeLabelNewType.AddText("Grid")
activeLabelNewType.AddText("Group")
activeLabelNewType.AddText("Box")
activeLabelNewType.AddText("Button")
activeLabelNewType.AddText("Checkbox")
activeLabelNewType.AddText("Dropdown")
activeLabelNewType.AddText("Combobox")
activeLabelNewType.AddText("Label")
activeLabelNewType.AddText("Textbox")
activeLabelNewType.AddText("Slider")
activeLabelNewType.AddText("Spinner")
activeLabelNewType.AddText("Image")
activeLabelNewType.AddText("Area")
activeLabelNewType.AddText("Form")
activeLabelNewType.AddText("Font")
activeLabelNewType.AddText("Color")
activeLabelNewType.AddText("Dialog")
n.NewButton("Add", func () {
name := activeLabelNewName.S
newX := activeLabelNewX.I
newY := activeLabelNewY.I
newB := activeLabelNewB.B
if (newY == -1) {
name = name + " (" + strconv.Itoa(activeWidget.NextW) + "," + strconv.Itoa(activeWidget.NextH) + ")"
} else {
activeWidget.SetNext(newX, newY)
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
}
log(true, "New Name =", name)
log(true, "New Type =", activeLabelNewType.S)
log(true, "New X =", newX)
log(true, "New Y =", newY)
log(true, "activeWidget.NextW =", activeWidget.NextW)
log(true, "activeWidget.NextH =", activeWidget.NextH)
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (W,H) =", activeWidget.NextW, activeWidget.NextH)
activeWidget.Dump()
// activeWidget.X = newX
// activeWidget.Y = newY
switch activeLabelNewType.S {
case "Grid":
activeWidget.NewGrid(name, newX, newY)
case "Group":
activeWidget.NewGroup(name)
case "Box":
activeWidget.NewBox(name, newB)
case "Button":
var n *Node
n = activeWidget.NewButton(name, func () {
log(true, "got to button", name, n.id)
})
case "Checkbox":
a := activeWidget.NewCheckbox(name)
a.Custom = func () {
log(true, "custom checkox func a=", a.B, "id=", a.id)
}
case "Dropdown":
a := activeWidget.NewDropdown(name)
a.AddText(name + " yay")
a.AddText(name + " haha")
a.Custom = func () {
log(true, "WTF a=", a.B, "id=", a.id)
}
case "Combobox":
a := activeWidget.NewCombobox(name)
a.AddText(name + " foo")
a.AddText(name + " bar")
case "Label":
activeWidget.NewLabel(name)
case "Textbox":
activeWidget.NewTextbox(name)
case "Slider":
activeWidget.NewSlider(name, newX, newY)
case "Spinner":
activeWidget.NewSpinner(name, newX, newY)
default:
log(debugError, "make what type?")
}
})
}

View File

@ -1,185 +0,0 @@
package gui
import (
newlog "go.wit.com/log"
)
// TODO: move all this shit into somewhere not global
// main debugging window
var bugWin *Node
var mapWindows map[string]*Node
var checkd, checkdn, checkdt, checkdtk, lb1, lb2 *Node
var myButton *Node
/*
Creates a window helpful for debugging this package
*/
func (n *Node) DebugWindow() {
newlog.Warn("Don't use DebugWindow() directly anymore")
DebugWindow() // todo, remove the non-binary tree access
}
func DebugWindow() {
bugWin = me.rootNode.NewWindow("go.wit.com/gui debug window").DebugTab("Debug Tab")
bugWin.Custom = bugWin.StandardClose
if ArgDebug() {
newlog.SetTmp()
bugWin.DebugFlags()
}
}
// should the debugging windows be new windows or tabs
// var makeTabs bool = true
func (n *Node) UseTabs() bool {
return me.makeTabs
}
func (n *Node) SetTabs(b bool) {
me.makeTabs = b
}
func (n *Node) DebugTab(title string) *Node {
var newN, gog, g1 *Node
// var logSettings *gadgets.LogSettings
// time.Sleep(1 * time.Second)
newN = n.NewTab(title)
//////////////////////// main debug things //////////////////////////////////
gog = newN.NewGroup("Debugging Windows:")
// generally useful debugging
cb := gog.NewCheckbox("Seperate windows")
cb.Custom = func() {
log(debugGui, "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 () {
DebugWidgetWindow(newN)
})
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 () {
exit()
})
//////////////////////// window debugging things //////////////////////////////////
g1 = newN.NewGroup("list things")
g1.NewButton("List toolkits", func () {
dropdownWindow(g1)
me.rootNode.ListToolkits()
})
g1.NewButton("List Windows", func () {
dropdownWindow(g1)
})
g1.NewButton("List Window Widgets", func () {
dropdownWindowWidgets(g1)
})
g2 := newN.NewGroup("more things")
g2.NewButton("Node.ListChildren(true)", func () {
if (activeWidget == nil) {
activeWidget = me.rootNode
}
activeWidget.ListChildren(true)
})
g2.NewButton("test conc", func () {
makeConc()
})
g2.NewButton("List Plugins", func () {
for _, aplug := range allPlugins {
log(true, "Loaded plugin:", aplug.name, aplug.filename)
}
})
g2.NewButton("load toolkit 'gocui'", func () {
me.rootNode.LoadToolkit("gocui")
})
g2.NewButton("load toolkit 'andlabs'", func () {
me.rootNode.LoadToolkit("andlabs")
})
return newN
}
func dropdownWindow(p *Node) {
var mapWindows map[string]*Node
mapWindows = make(map[string]*Node)
dd := p.NewDropdown("Window Dropdown")
dd.Custom = func() {
name := dd.S
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
log(true, "The Window was set to", name)
}
log(debugGui, "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 me.rootNode.children {
log(logInfo, "\t\t", child.id, child.Name)
dd.AddDropdownName(child.Name)
// last = child.Name
mapWindows[child.Name] = child
if (activeWidget == nil) {
activeWidget = child
}
}
// dd.SetDropdownName(last)
}
func dropdownWindowWidgets(p *Node) {
var mapWindows map[string]*Node
mapWindows = make(map[string]*Node)
dd := p.NewDropdown("Window Widgets Dropdown")
dd.Custom = func() {
name := dd.S
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
}
log(debugGui, "dd =", dd)
// log("dumpWidget() ", b, listChildrenDepth, defaultPadding, n.id, info)
var addDropdowns func (*Node)
addDropdowns = func (n *Node) {
s := n.dumpWidget(true)
dd.AddDropdownName(s)
mapWindows[s] = n
for _, child := range n.children {
listChildrenDepth += 1
addDropdowns(child)
listChildrenDepth -= 1
}
}
// list everything in the binary tree
addDropdowns(me.rootNode)
}

27
main.go
View File

@ -2,7 +2,7 @@ package gui
import (
"os"
"time"
"go.wit.com/gui/gui/toolkit"
)
@ -49,7 +49,7 @@ func watchCallback() {
}
if (a.ActionType == toolkit.EnableDebug) {
log(logInfo, "doUserEvent() Enable Debugging Window")
DebugWindow()
// DebugWindow()
break
}
@ -124,9 +124,6 @@ func New() *Node {
// try to load andlabs, if that doesn't work, fall back to the console
func (n *Node) Default() *Node {
// start the GUI debugger if --gui-debug is true
checkDebug()
if (argGui.GuiPlugin != "") {
log(logError, "New.Default() try toolkit =", argGui.GuiPlugin)
return n.LoadToolkit(argGui.GuiPlugin)
@ -146,26 +143,6 @@ func (n *Node) Default() *Node {
return n
}
func checkDebug() {
if ! ArgDebug() {
return
}
f := func() {
log(debugGui, "wit/gui START DEBUG")
log(debugGui, "wit/gui START DEBUG")
log(debugGui, "wit/gui START DEBUG")
time.Sleep(2 * time.Second)
log(debugGui, "wit/gui START DEBUG")
log(debugGui, "wit/gui START DEBUG")
log(debugGui, "wit/gui START DEBUG")
DebugWindow()
log(debugGui, "wit/gui END DEBUG")
log(debugGui, "wit/gui END DEBUG")
log(debugGui, "wit/gui END DEBUG")
}
go f()
}
// The window is destroyed but the application does not quit
func (n *Node) StandardClose() {
log(debugGui, "wit/gui Standard Window Close. name =", n.Name)