lots of cleanups for the gui and toolkit packages

log flags gui again
    fix panic()
    SetVisible() false on create
    update go mod

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-20 19:53:23 -06:00
parent e21b61fa96
commit 57843518b2
6 changed files with 108 additions and 55 deletions

View File

@ -11,6 +11,9 @@ all:
@echo in that sense, they are intended to be useful wrappers
@echo
goimports:
goimports -w *.go
redomod:
rm -f go.*
GO111MODULE= go mod init

View File

@ -20,7 +20,6 @@ type BasicCombobox struct {
ready bool
progname string
parent *gui.Node // parent widget
l *gui.Node // label widget
d *gui.Node // dropdown widget
@ -89,7 +88,6 @@ func (d *BasicCombobox) AddText(s string) {
func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
d := BasicCombobox{
parent: p,
progname: label,
ready: false,
}
@ -98,7 +96,7 @@ func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
d.l = p.NewLabel(label)
d.d = p.NewCombobox()
d.d.Custom = func() {
log.Warn("BasicCombobox.Custom() user changed value to =", d.d.String())
log.Warn("BasicCombobox.Custom() user changed value to =", d.String())
if d.Custom != nil {
d.Custom()
}

View File

@ -89,15 +89,15 @@ func (w *BasicWindow) StandardClose() {
}
w.win.Custom = w.win.StandardClose
/*
log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.title)
log.Warn("BasicWindow.Custom() closed. handled properly?", w.title)
if w.Custom != nil {
log.Warn("BasicWindow.Custom() HAS CUSTOM")
w.Custom()
return
log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.title)
log.Warn("BasicWindow.Custom() closed. handled properly?", w.title)
if w.Custom != nil {
log.Warn("BasicWindow.Custom() HAS CUSTOM")
w.Custom()
return
}
w.win.StandardExit()
}
w.win.StandardExit()
}
*/
return
}
@ -143,9 +143,6 @@ func (w *BasicWindow) Ready() bool {
}
func (w *BasicWindow) Box() *gui.Node {
if !w.Initialized() {
return nil
}
if w.win == nil {
w.Draw()
}
@ -171,9 +168,6 @@ func (w *BasicWindow) Horizontal() {
}
func (w *BasicWindow) Make() {
if !w.Initialized() {
return
}
if w.win != nil {
log.Warn("BasicWindow.Make() window was already created")
return
@ -200,6 +194,7 @@ func (w *BasicWindow) Make() {
w.box = w.win.NewHorizontalBox("BW HBOX")
log.Log(INFO, "BasicWindow.Make() made NewHorizontalBox", w.title)
}
w.win.SetVisable(false)
w.ready = true
}
@ -217,11 +212,8 @@ func (w *BasicWindow) TestDraw() {
}
func (w *BasicWindow) Draw() {
if !w.Initialized() {
return
}
if w.win != nil {
log.Warn("BasicWindow.Draw() window was already created")
if w.win == nil {
log.Warn("BasicWindow.Draw() needs Make()")
w.Make()
}
w.win.TestDraw()

6
go.mod
View File

@ -3,13 +3,13 @@ module go.wit.com/lib/gadgets
go 1.21.4
require (
go.wit.com/gui v0.12.18
go.wit.com/log v0.5.5
go.wit.com/gui v0.12.19
go.wit.com/log v0.5.6
)
require (
go.wit.com/dev/alexflint/arg v1.4.5 // indirect
go.wit.com/dev/alexflint/scalar v1.2.1 // indirect
go.wit.com/dev/davecgh/spew v1.1.4 // indirect
go.wit.com/widget v1.1.5 // indirect
go.wit.com/widget v1.1.6 // indirect
)

8
go.sum
View File

@ -6,7 +6,11 @@ go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNe
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/gui v0.12.18 h1:gFVDaJFz/Su8JgUd9Oxnb3t+FS+bzy5WJSvGoKVGYZU=
go.wit.com/gui v0.12.18/go.mod h1:27+THr2a84GZ61KKUuN30WYnYoSsBewllUKc+fnWLto=
go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4=
go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/gui v0.12.19 h1:OEnsnZnec7Q2jZVjwl413V0wuVAAB4r2mGTY0IouBuw=
go.wit.com/gui v0.12.19/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA=
go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4=
go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/widget v1.1.5 h1:jx5hJ2WLZJnCcvMuaLHegzpNlzwo+0kOkzsRkzRiB30=
go.wit.com/widget v1.1.5/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=
go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY=
go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=

View File

@ -1,5 +1,5 @@
/*
A log.Flag
A simple GUI gadget to control on a 'log' package flag
-----------------------------------------------
| | |
@ -10,55 +10,111 @@ A log.Flag
package gadgets
import (
"errors"
"go.wit.com/gui"
"go.wit.com/log"
)
type LogFlag struct {
p *gui.Node // parent widget
c *gui.Node // checkbox widget
lf *log.LogFlag
// p *gui.Node // parent widget
checkbox *gui.Node // checkbox widget
lf *log.LogFlag // this is the object from the 'log' package
Name string
Subsystem string
Desc string
Default bool
b bool
name string
subsystem string
desc string
orig bool
// b bool
Custom func()
}
func (f *LogFlag) Get() bool {
return f.lf.Get()
// probably a better name than GetValue()
func (f *LogFlag) Bool() bool {
if f.lf.Bool() != f.checkbox.Bool() {
log.Error(errors.New("gadget.LogFlag error. actual flag.Bool() does not match checkbox.Bool()"))
// set the checkbox to reflect the actual flag value
f.checkbox.SetChecked(f.lf.Bool())
}
return f.lf.Bool()
}
func (f *LogFlag) Set(b bool) {
log.Info("LogFlag.Set() =", b)
f.lf.Set(b)
f.c.SetChecked(b)
func (f *LogFlag) GetValue() bool {
return f.checkbox.Bool()
}
func (f *LogFlag) SetDefault() {
log.Info("LogFlag.SetDefault() =", f.Default)
func (f *LogFlag) GetName() string {
return f.name
}
func (f *LogFlag) GetSubsystem() string {
return f.subsystem
}
func (f *LogFlag) GetDesc() string {
return f.name
}
func (f *LogFlag) SetValue(b bool) {
log.Info("LogFlag.SetValue() before SetValue() log.flag =", f.lf.Bool(), "checkbox =", f.checkbox.Bool())
f.checkbox.SetChecked(b)
f.lf.SetBool(b)
log.Info("LogFlag.SetValue() after SetValue() log.flag =", f.lf.Bool(), "checkbox =", f.checkbox.Bool())
}
// should be RestoreDefault() ?
func (f *LogFlag) RestoreDefault() {
f.lf.SetDefault()
f.c.SetChecked(f.lf.Get())
}
func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
f := LogFlag{
p: n,
lf: lf,
name: lf.GetName(),
subsystem: lf.GetSubsystem(),
desc: lf.GetDesc(),
orig: lf.GetDefault(),
}
f.Name = lf.GetName()
f.Subsystem = lf.GetSubsystem()
f.Desc = lf.GetDesc()
// various timeout settings
f.c = n.NewCheckbox(f.Name + ": " + f.Desc)
f.c.Custom = func() {
f.lf.Set(f.c.Bool())
log.Info("LogFlag.Custom() user changed value to =", f.lf.Get())
// make the checkbox for turning on and off the logging flag
f.checkbox = n.NewCheckbox(f.name + ": " + f.desc)
// when the user checks the logging flag, do a sanity check here
// since this is likely the one place, when everything else
// has gone black, that the user(probably a developer in this case)
// will have. if the toolkit, general GUI code or whatever else
// is not working, this will sanity check that the checkboxes
// are at least working to set the logging flags
// which will let the developer have some home of seeing the
// output errors from whatever might be broken
// this is useful when trying to debug toolkit plugins
var watcher bool = true
var counter int = 0
f.checkbox.Custom = func() {
if counter == 0 {
// store the first clicked value
watcher = f.lf.Bool()
} else {
// if the value has changed, then everything is fine
if watcher != f.lf.Bool() {
watcher = f.lf.Bool()
counter = 0
}
// this means the value has not changed 3 times
// in a row. something is wrong! inform the user
// (in the GUI since that is where they are clicking
// the checkbox so we know they can seen things there
if counter > 4 {
f.checkbox.SetLabel(f.name + ": log settings are not working")
counter = 0
}
}
counter += 1
f.lf.SetBool(f.checkbox.Bool())
}
f.c.SetChecked(lf.Get())
f.checkbox.SetValue(lf.Bool())
return &f
}