From d69a41a295aca9cd40449d4d4840265defb4e3de Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Jan 2024 22:02:12 -0600 Subject: [PATCH] switch log to BasicWindow() Signed-off-by: Jeff Carr --- basicWindow.go | 64 +++++++++++++++++++++++++++++++++++++++++ logsettings/draw.go | 40 +++++++++----------------- logsettings/settings.go | 10 +++---- logsettings/structs.go | 5 ++-- 4 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 basicWindow.go diff --git a/basicWindow.go b/basicWindow.go new file mode 100644 index 0000000..ba4f0bf --- /dev/null +++ b/basicWindow.go @@ -0,0 +1,64 @@ +/* + A Standard Window +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +type BasicWindow struct { + hidden bool + name string + + p *gui.Node // parent widget + win *gui.Node // window widget + box *gui.Node // box + + Custom func() +} + +func (w *BasicWindow) Hide() { + w.win.Hide() + w.hidden = true + return +} + +func (w *BasicWindow) Show() { + w.win.Show() + w.hidden = false + return +} + +func (w *BasicWindow) Toggle() { + if w.hidden { + w.Show() + w.hidden = false + } else { + w.Hide() + w.hidden = true + } + return +} + +func (w *BasicWindow) Box() *gui.Node { + return w.box +} + +func NewBasicWindow(parent *gui.Node, name string) *BasicWindow { + var w *BasicWindow + w = &BasicWindow { + p: parent, + name: name, + } + + // various timeout settings + w.win = w.p.NewWindow(name) + w.win.Custom = func() { + log.Println("BasicWindow.Custom() closed. TODO: handle this", w.name) + } + w.box = w.win.NewBox("hBox", true) + + return w +} diff --git a/logsettings/draw.go b/logsettings/draw.go index 2bbed64..5321adc 100644 --- a/logsettings/draw.go +++ b/logsettings/draw.go @@ -7,43 +7,29 @@ import ( ) 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 + if ! d.Ready() { return } + d.win.Show() } func (d *LogSettings) Hide() { - if ! d.Ready() { - log.Warn("LogSettings.Hide() window is not Ready()") - return - } - log.Warn("LogSettings.Hide() window") - d.window.Hide() - d.hidden = true + if ! d.Ready() { return } + d.win.Hide() +} + +// alternates between showing and hiding the window +func (d *LogSettings) Toggle() { + if ! d.Ready() { return } + d.win.Toggle() } // 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 g *gui.Node - d.window = d.parent.NewWindow("Debug Flags") - d.window.Custom = d.parent.StandardClose + d.win = gadgets.NewBasicWindow(d.parent, "Debug Flags") - d.box = d.window.NewBox("hBox", true) - g = d.box.NewGroup("Show").Pad() + g = d.win.Box().NewGroup("Show").Pad() d.buttonG = g g.NewButton("Redirect STDOUT to /tmp/", func () { @@ -85,7 +71,7 @@ func (d *LogSettings) draw() { } }) - d.flagG = d.box.NewGroup("Subsystem (aka package)") + d.flagG = d.win.Box().NewGroup("Subsystem (aka package)") g.NewButton("Add all Flags", func () { flags := log.ShowFlags() diff --git a/logsettings/settings.go b/logsettings/settings.go index 4e95b7a..2bc252a 100644 --- a/logsettings/settings.go +++ b/logsettings/settings.go @@ -11,21 +11,19 @@ func New(p *gui.Node) *LogSettings { if myLogGui != nil {return myLogGui} myLogGui = new(LogSettings) myLogGui.parent = p + myLogGui.groups = make(map[string]*flagGroup) myLogGui.ready = true myLogGui.hidden = true - myLogGui.groups = make(map[string]*flagGroup) return myLogGui } -func (ls *LogSettings) Set(b bool) { - // log.Set(ls.name, b) - log.Warn("log.Set() FIXME: not working here anymore") -} - // Returns true if the status is valid func (d *LogSettings) Ready() bool { if d == nil {return false} if ! d.parent.Ready() {return false} + if (d.win == nil) { + d.draw() + } return d.ready } diff --git a/logsettings/structs.go b/logsettings/structs.go index 35b24ca..0637ac4 100644 --- a/logsettings/structs.go +++ b/logsettings/structs.go @@ -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 @@ -15,8 +15,7 @@ type LogSettings struct { groups map[string]*flagGroup 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 + win *gadgets.BasicWindow // our window for displaying the log package settings buttonG *gui.Node // the group of buttons flagG *gui.Node // the group of all the flag checkbox widgets