summaryrefslogtreecommitdiff
path: root/logFlag.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-20 19:53:23 -0600
committerJeff Carr <[email protected]>2024-01-20 19:53:23 -0600
commit57843518b20cbf544a96b885b619e83529602597 (patch)
tree0712deb9602a8a5a184ad6b0d49dbee8b4699516 /logFlag.go
parente21b61fa9690e547d47a71ad99bfd2af6eb8c58a (diff)
lots of cleanups for the gui and toolkit packagesv0.12.14
log flags gui again fix panic() SetVisible() false on create update go mod Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'logFlag.go')
-rw-r--r--logFlag.go112
1 files changed, 84 insertions, 28 deletions
diff --git a/logFlag.go b/logFlag.go
index e8f2214..ca6d7af 100644
--- a/logFlag.go
+++ b/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
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) GetValue() bool {
+ return f.checkbox.Bool()
+}
+
+func (f *LogFlag) GetName() string {
+ return f.name
}
-func (f *LogFlag) Set(b bool) {
- log.Info("LogFlag.Set() =", b)
- f.lf.Set(b)
- f.c.SetChecked(b)
+func (f *LogFlag) GetSubsystem() string {
+ return f.subsystem
}
-func (f *LogFlag) SetDefault() {
- log.Info("LogFlag.SetDefault() =", f.Default)
+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
}