From a7640472cb6c431d3db817974e9ef23e83d7dd62 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 30 Dec 2023 20:47:35 -0600 Subject: [PATCH] show/set flags from go.wit.com/log package Signed-off-by: Jeff Carr --- debugFlags.go | 104 +++++++++++++++++++++++++---------------- debugWindow.go | 7 +-- gadgets/logSettings.go | 72 ++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 46 deletions(-) create mode 100644 gadgets/logSettings.go diff --git a/debugFlags.go b/debugFlags.go index 6072008..39c26f2 100644 --- a/debugFlags.go +++ b/debugFlags.go @@ -1,10 +1,51 @@ 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(makeWindow bool) { var w, g *Node + logGadgets := make(map[string]*LogSettings) + // Either: // make a new window // make a new tab in the existing window @@ -17,6 +58,22 @@ func (n *Node) DebugFlags(makeWindow bool) { g = w.NewGroup("Show") + g.NewButton("log.SetTmp()", func () { + newlog.SetTmp() + }) + + g.NewButton("log.All(true)", func () { + for _, lf := range logGadgets { + lf.Set(true) + } + }) + + g.NewButton("log.All(false)", func () { + for _, lf := range logGadgets { + lf.Set(false) + } + }) + g.NewButton("Dump Flags", func () { ShowDebugValues() }) @@ -31,6 +88,12 @@ func (n *Node) DebugFlags(makeWindow bool) { 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") @@ -39,47 +102,6 @@ func (n *Node) DebugFlags(makeWindow bool) { log(debugGui, "Custom() n.widget =", cb1.Name, cb1.B) } - // errors. by default these always output somewhere - cbE := g.NewCheckbox("debug Error") - g.NewLabel("(bad things. default=true)") - cbE.Custom = func() { - SetFlag("Error", cbE.B) - } - - // debugging that will show you things like mouse clicks, user inputing text, etc - // also set toolkit.DebugChange - cb2 := g.NewCheckbox("debug Change") - g.NewLabel("keyboard and mouse events") - cb2.Custom = func() { - SetFlag("Change", cb2.B) - } - - // supposed to tell if you are going to dump full variable output - cb3 := g.NewCheckbox("debug Dump") - g.NewLabel("show lots of output") - cb3.Custom = func() { - SetFlag("Dump", cbE.B) - } - - cb4 := g.NewCheckbox("debug Tabs") - g.NewLabel("tabs and windows") - cb4.Custom = func() { - SetFlag("Tabs", cb4.B) - } - - cb6 := g.NewCheckbox("debug Node") - g.NewLabel("the binary tree)") - cb6.Custom = func() { - SetFlag("Node", cb6.B) - } - - // should show you when things go into or come back from the plugin - cb5 := g.NewCheckbox("debug Plugin") - g.NewLabel("plugin interaction)") - cb5.Custom = func() { - SetFlag("Plugin", cb5.B) - } - // turns on debugging inside the plugin toolkit cb7 := g.NewCheckbox("debug Toolkit") g.NewLabel("the plugin internals)") diff --git a/debugWindow.go b/debugWindow.go index ed1804e..c4d050b 100644 --- a/debugWindow.go +++ b/debugWindow.go @@ -1,9 +1,5 @@ package gui -import ( -// "go.wit.com/gui/toolkit" -) - // TODO: move all this shit into somewhere not global // main debugging window @@ -26,6 +22,7 @@ func DebugWindow() { 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) @@ -42,7 +39,7 @@ func (n *Node) DebugTab(title string) *Node { makeTabs = false cb.Set(false) - gog.NewButton("Debug Flags", func () { + gog.NewButton("logging", func () { bugWin.DebugFlags(makeTabs) }) gog.NewButton("Debug Widgets", func () { diff --git a/gadgets/logSettings.go b/gadgets/logSettings.go new file mode 100644 index 0000000..77c94a4 --- /dev/null +++ b/gadgets/logSettings.go @@ -0,0 +1,72 @@ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui" +) + +var myLogGui *LogSettings + +type LogSettings struct { + ready bool + hidden bool + err error + + parent *gui.Node // should be the root of the 'gui' package binary tree + window *gui.Node // our window for displaying the log package settings + group *gui.Node // + grid *gui.Node // + + // Primary Directives + status *OneLiner + summary *OneLiner +} + +// This is initializes the main DO object +// You can only have one of these +func NewLogSettings(p *gui.Node) *LogSettings { + if myLogGui != nil {return myLogGui} + myLogGui = new(LogSettings) + myLogGui.parent = p + + myLogGui.ready = false + + myLogGui.window = p.NewWindow("Log Settings") + + // make a group label and a grid + myLogGui.group = myLogGui.window.NewGroup("droplets:").Pad() + myLogGui.grid = myLogGui.group.NewGrid("grid", 2, 1).Pad() + + myLogGui.ready = true + myLogGui.Hide() + return myLogGui +} + +// Returns true if the status is valid +func (d *LogSettings) Ready() bool { + if d == nil {return false} + return d.ready +} + +func (d *LogSettings) Show() { + if ! d.Ready() {return} + log.Info("LogSettings.Show() window") + if d.hidden { + d.window.Show() + } + d.hidden = false +} + +func (d *LogSettings) Hide() { + if ! d.Ready() {return} + log.Info("LogSettings.Hide() window") + if ! d.hidden { + d.window.Hide() + } + d.hidden = true +} + +func (d *LogSettings) Update() bool { + if ! d.Ready() {return false} + return true +}