restore defaults, all on, all off all work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-04 15:14:37 -06:00
parent 10001c7006
commit 32876a5bfb
4 changed files with 52 additions and 24 deletions

View File

@ -21,6 +21,7 @@ type LogFlag struct {
Name string
Subsystem string
Desc string
Default bool
b bool
Custom func()
@ -31,8 +32,15 @@ func (f *LogFlag) Get() bool {
}
func (f *LogFlag) Set(b bool) {
log.Println("LogFlag.Set() =", b)
log.Info("LogFlag.Set() =", b)
log.Set(f.Subsystem, f.Name, b)
f.c.Set(b)
}
func (f *LogFlag) SetDefault() {
log.Info("LogFlag.SetDefault() =", f.Default)
log.Set(f.Subsystem, f.Name, f.Default)
f.c.Set(f.Default)
}
func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
@ -40,6 +48,7 @@ func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
Name: lf.Name,
Subsystem: lf.Subsystem,
Desc: lf.Desc,
Default: lf.Default,
p: n,
}
@ -47,8 +56,9 @@ func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
f.c = n.NewCheckbox(f.Name + ": " + f.Desc)
f.c.Custom = func() {
log.Set(f.Subsystem, f.Name, f.c.B)
log.Println("LogFlag.Custom() user changed value to =", log.Get(f.Subsystem, f.Name))
log.Info("LogFlag.Custom() user changed value to =", log.Get(f.Subsystem, f.Name))
}
f.c.Set(lf.B)
return &f
}

View File

@ -25,13 +25,11 @@ func (d *LogSettings) Show() {
func (d *LogSettings) Hide() {
if ! d.Ready() {
log.Warn("LogSettings.Show() window is not Ready()")
log.Warn("LogSettings.Hide() window is not Ready()")
return
}
log.Warn("LogSettings.Hide() window")
if ! d.hidden {
d.window.Hide()
}
d.window.Hide()
d.hidden = true
}
@ -39,49 +37,72 @@ func (d *LogSettings) Hide() {
// These checkboxes should be in the same order as the are printed
func (d *LogSettings) draw() {
if ! d.Ready() {return}
var newW, newB, g *gui.Node
var g *gui.Node
newW = d.parent.NewWindow("Debug Flags")
newW.Custom = d.parent.StandardClose
d.window = d.parent.NewWindow("Debug Flags")
d.window.Custom = d.parent.StandardClose
newB = newW.NewBox("hBox", true)
g = newB.NewGroup("Show").Pad()
d.box = d.window.NewBox("hBox", true)
g = d.box.NewGroup("Show").Pad()
d.buttonG = g
g.NewButton("Redirect STDOUT to /tmp/", func () {
log.SetTmp()
})
g.NewButton("restore defaults", func () {
log.SetDefaults()
for _, wg := range myLogGui.groups {
for _, f := range wg.flags {
f.SetDefault()
}
}
})
g.NewButton("all on", func () {
log.SetAll(true)
for _, wg := range myLogGui.groups {
for _, f := range wg.flags {
f.Set(true)
}
}
})
g.NewButton("all off", func () {
log.SetAll(false)
for _, wg := range myLogGui.groups {
for _, f := range wg.flags {
f.Set(false)
}
}
})
g.NewButton("Dump Flags", func () {
// ShowDebugValues()
log.ShowFlags()
for s, wg := range myLogGui.groups {
log.Log(true, "Dump Flags", s)
for _, f := range wg.flags {
log.Log(true, "Dump Flags\t", f.Name, ":", f.Desc)
}
}
})
flagG := newB.NewGroup("Subsystem (aka package)")
d.flagG = d.box.NewGroup("Subsystem (aka package)")
g.NewButton("Add all Flags", func () {
flags := log.ShowFlags()
for _, f := range flags {
log.Log(true, "Get() ", "(" + f.Subsystem + ")", f.Name, "=", f.B, ":", f.Desc)
addFlag(flagG, f)
addFlag(d.flagG, f)
}
})
g.NewButton("Close", func () {
d.Hide()
})
flags := log.ShowFlags()
for _, f := range flags {
log.Log(true, "Get() ", "(" + f.Subsystem + ")", f.Name, "=", f.B, ":", f.Desc)
addFlag(flagG, f)
addFlag(d.flagG, f)
}
}

View File

@ -20,7 +20,6 @@ func New(p *gui.Node) *LogSettings {
func (ls *LogSettings) Set(b bool) {
// log.Set(ls.name, b)
log.Warn("log.Set() FIXME: not working here anymore")
ls.checkbox.Set(b)
}
// Returns true if the status is valid

View File

@ -2,7 +2,7 @@ package logsettings
import (
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
// "go.wit.com/gui/gadgets"
)
var myLogGui *LogSettings
@ -16,10 +16,8 @@ type LogSettings struct {
parent *gui.Node // where to draw our window
window *gui.Node // our window for displaying the log package settings
box *gui.Node // the first box in the window
// Primary Directives
status *gadgets.OneLiner
summary *gadgets.OneLiner
checkbox *gadgets.LogFlag
buttonG *gui.Node // the group of buttons
flagG *gui.Node // the group of all the flag checkbox widgets
}