diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85a4024 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.swp + +# ignore compiled plugins +*.so diff --git a/logFlag.go b/logFlag.go new file mode 100644 index 0000000..1471a7e --- /dev/null +++ b/logFlag.go @@ -0,0 +1,54 @@ +/* + A log.Flag + + ----------------------------------------------- + | | | + | [ X ] | INFO (controls log.Info() | + | | | + ----------------------------------------------- +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +type LogFlag struct { + p *gui.Node // parent widget + c *gui.Node // checkbox widget + + name string + subsystem string + desc string + b bool + + Custom func() +} + +func (f *LogFlag) Get() bool { + return log.Get(f.subsystem, f.name) +} + +func (f *LogFlag) Set(b bool) { + log.Println("LogFlag.Set() =", b) + log.Set(f.subsystem, f.name, b) +} + +func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag { + f := LogFlag { + name: lf.Name, + subsystem: lf.Subsystem, + desc: lf.Desc, + p: n, + } + + // various timeout settings + 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)) + } + + return &f +} diff --git a/logSettings.go b/logSettings.go deleted file mode 100644 index a496ca5..0000000 --- a/logSettings.go +++ /dev/null @@ -1,72 +0,0 @@ -package gadgets - -import ( - "go.wit.com/log" - "go.wit.com/gui/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 -} diff --git a/logsettings/draw.go b/logsettings/draw.go new file mode 100644 index 0000000..f125f1b --- /dev/null +++ b/logsettings/draw.go @@ -0,0 +1,74 @@ +package logsettings + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) + +func (d *LogSettings) Show() { + if ! d.Ready() { + log.Warn("LogSettings.Show() window is not Ready()") + return + } + log.Warn("LogSettings.Show() window") + if d.hidden { + log.Warn("LogSettings.Show() window HERE window =", d.window) + if d.window == nil { + log.Warn("LogSettings.Show() create the window") + d.draw() + } + d.window.Show() + } + d.hidden = false +} + +func (d *LogSettings) Hide() { + if ! d.Ready() { + log.Warn("LogSettings.Show() window is not Ready()") + return + } + log.Warn("LogSettings.Hide() window") + if ! d.hidden { + d.window.Hide() + } + d.hidden = true +} + +// 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 (d *LogSettings) draw() { + if ! d.Ready() {return} + var newW, newB, g *gui.Node + + newW = d.parent.NewWindow("Debug Flags") + newW.Custom = d.parent.StandardClose + + newB = newW.NewBox("hBox", true) + g = newB.NewGroup("Show").Pad() + + g.NewButton("log.SetTmp()", func () { + log.SetTmp() + }) + + g.NewButton("log.SetAll(true)", func () { + log.SetAll(true) + }) + + g.NewButton("log.SetAll(false)", func () { + log.SetAll(false) + }) + + g.NewButton("Dump Flags", func () { + // ShowDebugValues() + log.ShowFlags() + }) + + g = newB.NewGroup("List") + g = g.NewGrid("flags grid", 5, 2) + flags := log.ShowFlags() + for _, f := range flags { + log.Log(true, "Get() ", "(" + f.Subsystem + ")", f.Name, "=", f.B, ":", f.Desc) + gadgets.NewLogFlag(g, f) + } +} diff --git a/logsettings/settings.go b/logsettings/settings.go new file mode 100644 index 0000000..417673d --- /dev/null +++ b/logsettings/settings.go @@ -0,0 +1,45 @@ +package logsettings + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +// This initializes the main object +// You can only have one of these +func New(p *gui.Node) *LogSettings { + if myLogGui != nil {return myLogGui} + myLogGui = new(LogSettings) + myLogGui.parent = p + myLogGui.ready = true + myLogGui.hidden = false + return myLogGui +} + +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 +func (d *LogSettings) Ready() bool { + if d == nil {return false} + if ! d.parent.Ready() {return false} + return d.ready +} + +func (d *LogSettings) Update() bool { + if ! d.Ready() {return false} + return true +} + +func (d *LogSettings) ShowFlags() { + log.ShowFlags() + return +} + +func (d *LogSettings) SetAll(b bool) { + log.SetAll(b) + return +} diff --git a/logsettings/structs.go b/logsettings/structs.go new file mode 100644 index 0000000..3df504b --- /dev/null +++ b/logsettings/structs.go @@ -0,0 +1,23 @@ +package logsettings + +import ( + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) + +var myLogGui *LogSettings + +type LogSettings struct { + ready bool + hidden bool + err error + + parent *gui.Node // where to draw our window + window *gui.Node // our window for displaying the log package settings + + // Primary Directives + status *gadgets.OneLiner + summary *gadgets.OneLiner + + checkbox *gadgets.LogFlag +}