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:
parent
e21b61fa96
commit
57843518b2
3
Makefile
3
Makefile
|
@ -11,6 +11,9 @@ all:
|
||||||
@echo in that sense, they are intended to be useful wrappers
|
@echo in that sense, they are intended to be useful wrappers
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
goimports:
|
||||||
|
goimports -w *.go
|
||||||
|
|
||||||
redomod:
|
redomod:
|
||||||
rm -f go.*
|
rm -f go.*
|
||||||
GO111MODULE= go mod init
|
GO111MODULE= go mod init
|
||||||
|
|
|
@ -20,7 +20,6 @@ type BasicCombobox struct {
|
||||||
ready bool
|
ready bool
|
||||||
progname string
|
progname string
|
||||||
|
|
||||||
parent *gui.Node // parent widget
|
|
||||||
l *gui.Node // label widget
|
l *gui.Node // label widget
|
||||||
d *gui.Node // dropdown widget
|
d *gui.Node // dropdown widget
|
||||||
|
|
||||||
|
@ -89,7 +88,6 @@ func (d *BasicCombobox) AddText(s string) {
|
||||||
|
|
||||||
func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
|
func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
|
||||||
d := BasicCombobox{
|
d := BasicCombobox{
|
||||||
parent: p,
|
|
||||||
progname: label,
|
progname: label,
|
||||||
ready: false,
|
ready: false,
|
||||||
}
|
}
|
||||||
|
@ -98,7 +96,7 @@ func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
|
||||||
d.l = p.NewLabel(label)
|
d.l = p.NewLabel(label)
|
||||||
d.d = p.NewCombobox()
|
d.d = p.NewCombobox()
|
||||||
d.d.Custom = func() {
|
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 {
|
if d.Custom != nil {
|
||||||
d.Custom()
|
d.Custom()
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,9 +143,6 @@ func (w *BasicWindow) Ready() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BasicWindow) Box() *gui.Node {
|
func (w *BasicWindow) Box() *gui.Node {
|
||||||
if !w.Initialized() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if w.win == nil {
|
if w.win == nil {
|
||||||
w.Draw()
|
w.Draw()
|
||||||
}
|
}
|
||||||
|
@ -171,9 +168,6 @@ func (w *BasicWindow) Horizontal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BasicWindow) Make() {
|
func (w *BasicWindow) Make() {
|
||||||
if !w.Initialized() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if w.win != nil {
|
if w.win != nil {
|
||||||
log.Warn("BasicWindow.Make() window was already created")
|
log.Warn("BasicWindow.Make() window was already created")
|
||||||
return
|
return
|
||||||
|
@ -200,6 +194,7 @@ func (w *BasicWindow) Make() {
|
||||||
w.box = w.win.NewHorizontalBox("BW HBOX")
|
w.box = w.win.NewHorizontalBox("BW HBOX")
|
||||||
log.Log(INFO, "BasicWindow.Make() made NewHorizontalBox", w.title)
|
log.Log(INFO, "BasicWindow.Make() made NewHorizontalBox", w.title)
|
||||||
}
|
}
|
||||||
|
w.win.SetVisable(false)
|
||||||
|
|
||||||
w.ready = true
|
w.ready = true
|
||||||
}
|
}
|
||||||
|
@ -217,11 +212,8 @@ func (w *BasicWindow) TestDraw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BasicWindow) Draw() {
|
func (w *BasicWindow) Draw() {
|
||||||
if !w.Initialized() {
|
if w.win == nil {
|
||||||
return
|
log.Warn("BasicWindow.Draw() needs Make()")
|
||||||
}
|
|
||||||
if w.win != nil {
|
|
||||||
log.Warn("BasicWindow.Draw() window was already created")
|
|
||||||
w.Make()
|
w.Make()
|
||||||
}
|
}
|
||||||
w.win.TestDraw()
|
w.win.TestDraw()
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -3,13 +3,13 @@ module go.wit.com/lib/gadgets
|
||||||
go 1.21.4
|
go 1.21.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.wit.com/gui v0.12.18
|
go.wit.com/gui v0.12.19
|
||||||
go.wit.com/log v0.5.5
|
go.wit.com/log v0.5.6
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.wit.com/dev/alexflint/arg v1.4.5 // indirect
|
go.wit.com/dev/alexflint/arg v1.4.5 // indirect
|
||||||
go.wit.com/dev/alexflint/scalar v1.2.1 // indirect
|
go.wit.com/dev/alexflint/scalar v1.2.1 // indirect
|
||||||
go.wit.com/dev/davecgh/spew v1.1.4 // 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
8
go.sum
|
@ -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/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 h1:gFVDaJFz/Su8JgUd9Oxnb3t+FS+bzy5WJSvGoKVGYZU=
|
||||||
go.wit.com/gui v0.12.18/go.mod h1:27+THr2a84GZ61KKUuN30WYnYoSsBewllUKc+fnWLto=
|
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/gui v0.12.19 h1:OEnsnZnec7Q2jZVjwl413V0wuVAAB4r2mGTY0IouBuw=
|
||||||
go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
|
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 h1:jx5hJ2WLZJnCcvMuaLHegzpNlzwo+0kOkzsRkzRiB30=
|
||||||
go.wit.com/widget v1.1.5/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=
|
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=
|
||||||
|
|
112
logFlag.go
112
logFlag.go
|
@ -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
|
package gadgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogFlag struct {
|
type LogFlag struct {
|
||||||
p *gui.Node // parent widget
|
// p *gui.Node // parent widget
|
||||||
c *gui.Node // checkbox widget
|
checkbox *gui.Node // checkbox widget
|
||||||
lf *log.LogFlag
|
lf *log.LogFlag // this is the object from the 'log' package
|
||||||
|
|
||||||
Name string
|
name string
|
||||||
Subsystem string
|
subsystem string
|
||||||
Desc string
|
desc string
|
||||||
Default bool
|
orig bool
|
||||||
b bool
|
// b bool
|
||||||
|
|
||||||
Custom func()
|
Custom func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *LogFlag) Get() bool {
|
// probably a better name than GetValue()
|
||||||
return f.lf.Get()
|
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) {
|
func (f *LogFlag) GetValue() bool {
|
||||||
log.Info("LogFlag.Set() =", b)
|
return f.checkbox.Bool()
|
||||||
f.lf.Set(b)
|
|
||||||
f.c.SetChecked(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *LogFlag) SetDefault() {
|
func (f *LogFlag) GetName() string {
|
||||||
log.Info("LogFlag.SetDefault() =", f.Default)
|
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.lf.SetDefault()
|
||||||
f.c.SetChecked(f.lf.Get())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
|
func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag {
|
||||||
f := 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
|
// make the checkbox for turning on and off the logging flag
|
||||||
f.c = n.NewCheckbox(f.Name + ": " + f.Desc)
|
f.checkbox = n.NewCheckbox(f.name + ": " + f.desc)
|
||||||
f.c.Custom = func() {
|
|
||||||
f.lf.Set(f.c.Bool())
|
// when the user checks the logging flag, do a sanity check here
|
||||||
log.Info("LogFlag.Custom() user changed value to =", f.lf.Get())
|
// 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
|
||||||
}
|
}
|
||||||
f.c.SetChecked(lf.Get())
|
// 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.checkbox.SetValue(lf.Bool())
|
||||||
|
|
||||||
return &f
|
return &f
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue