diff options
| author | Jeff Carr <[email protected]> | 2024-02-07 08:47:06 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-02-07 08:47:06 -0600 |
| commit | 2d0c73f58e68d34cbd2ab85ba82507d159da28de (patch) | |
| tree | eed9475503049dfb1176fe12c4c07f0b94337cda | |
| parent | 2aed14a60cbb9208f8f9a507c83a3dd297a93640 (diff) | |
use internal log flagsv0.20.1
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | action.go | 2 | ||||
| -rw-r--r-- | args.go | 18 | ||||
| -rw-r--r-- | checkbox.go | 2 | ||||
| -rw-r--r-- | common.go | 4 | ||||
| -rw-r--r-- | dropdown.go | 21 | ||||
| -rw-r--r-- | flags.go | 28 | ||||
| -rw-r--r-- | grid.go | 2 | ||||
| -rw-r--r-- | image.go | 2 | ||||
| -rw-r--r-- | main.go | 40 | ||||
| -rw-r--r-- | node.go | 7 | ||||
| -rw-r--r-- | plugin.go | 22 | ||||
| -rw-r--r-- | setText.go | 7 | ||||
| -rw-r--r-- | watchdog.go | 2 | ||||
| -rw-r--r-- | window.go | 2 |
14 files changed, 83 insertions, 76 deletions
@@ -166,7 +166,7 @@ func sendActionToPlugin(a *widget.Action) { aplug.pluginChan = aplug.PluginChannel() log.Log(PLUG, "Action() retrieved", aplug.pluginChan) } - log.Verbose("Action() SEND to pluginChan", aplug.name, a.ActionType, a.WidgetType, a.WidgetId, a.ProgName) + log.Log(INFO, "Action() SEND to pluginChan", aplug.name, a.ActionType, a.WidgetType, a.WidgetId, a.ProgName) aplug.pluginChan <- *a // added during debugging. might be a good idea in general for a tactile experience // start playing with this @@ -2,16 +2,8 @@ package gui import ( "go.wit.com/dev/alexflint/arg" - "go.wit.com/log" ) -var INFO *log.LogFlag -var NOW *log.LogFlag -var GUI *log.LogFlag -var NODE *log.LogFlag -var PLUG *log.LogFlag -var CHANGE *log.LogFlag - var argGui ArgsGui // This struct can be used with the go-arg package @@ -27,14 +19,4 @@ func ArgToolkit() string { func init() { arg.Register(&argGui) - - full := "go.wit.com/gui" - short := "gui" - - NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") - INFO = log.NewFlag("INFO", false, full, short, "General Info") - GUI = log.NewFlag("GUI", false, full, short, "basic GUI internals") - NODE = log.NewFlag("NODE", false, full, short, "binary tree debugging") - PLUG = log.NewFlag("PLUG", false, full, short, "basic PLUG debuggging") - CHANGE = log.NewFlag("CHANGE", false, full, short, "user changed something") } diff --git a/checkbox.go b/checkbox.go index f863f8e..f7c96da 100644 --- a/checkbox.go +++ b/checkbox.go @@ -22,7 +22,7 @@ func (parent *Node) NewCheckbox(name string) *Node { newNode.progname = name newNode.Custom = func() { - log.Warn("checkboxy now is", newNode.checked) + log.Log(WARN, "checkboxy now is", newNode.checked) } // inform the toolkits @@ -115,7 +115,7 @@ func (n *Node) SetBool(b bool) { case widget.Checkbox: n.checked = b default: - log.Warn("WidgetType not bool", n.WidgetType, n.id) + log.Log(WARN, "WidgetType not bool", n.WidgetType, n.id) } } @@ -123,7 +123,7 @@ func (n *Node) SetInt(i int) { switch n.WidgetType { default: // n.value = i - // log.Warn("WidgetType not bool", n.WidgetType, n.id) + // log.Log(WARN, "WidgetType not bool", n.WidgetType, n.id) } } diff --git a/dropdown.go b/dropdown.go index e7ee980..5ec5f51 100644 --- a/dropdown.go +++ b/dropdown.go @@ -1,30 +1,9 @@ package gui -// functions to create 'Dropdown' and 'Combobox' -// Combobox is a Dropdown you can edit -// Thererfore, AddDropdownName() is used on both combobox and dropdown nodes -// since it is the same. confusing names? maybe... - import ( "go.wit.com/widget" ) -/* -// add a new entry to the dropdown name -func (n *Node) AddDropdownName(name string) { - if ! n.Ready() { return } - log.Warn("AddDropdownName() deprecated") - n.AddText(name) -} - -// Set the dropdown menu to 'name' -func (n *Node) SetDropdownName(name string) { - if ! n.Ready() { return } - log.Warn("SetDropdownName() deprecated") - n.SetText(name) -} -*/ - func (parent *Node) NewDropdown() *Node { newNode := parent.newNode("dropdown", widget.Dropdown) diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..3c5dd85 --- /dev/null +++ b/flags.go @@ -0,0 +1,28 @@ +package gui + +import ( + "go.wit.com/log" +) + +var INFO *log.LogFlag +var NOW *log.LogFlag +var WARN *log.LogFlag + +var GUI *log.LogFlag +var NODE *log.LogFlag +var PLUG *log.LogFlag +var CHANGE *log.LogFlag + +func init() { + full := "go.wit.com/gui" + short := "gui" + + NOW = log.NewFlag("NOW", true, full, short, "currently debugging things") + WARN = log.NewFlag("WARN", true, full, short, "gui warnings") + + INFO = log.NewFlag("INFO", false, full, short, "General Info") + GUI = log.NewFlag("GUI", false, full, short, "basic GUI internals") + NODE = log.NewFlag("NODE", false, full, short, "binary tree debugging") + PLUG = log.NewFlag("PLUG", false, full, short, "basic PLUG debuggging") + CHANGE = log.NewFlag("CHANGE", false, full, short, "user changed something") +} @@ -85,7 +85,7 @@ func (n *Node) At(w int, h int) *Node { n.gridIncrement() if (n.NextW != w) || (n.NextH != h) { - log.Warn("At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH) + log.Log(WARN, "At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH) } return n } @@ -9,7 +9,7 @@ func (parent *Node) NewImage(name string) *Node { var newNode *Node newNode = parent.newNode(name, widget.Image) - log.Warn("NewImage() not implemented. fix this") + log.Log(WARN, "NewImage() not implemented. fix this") // inform the toolkits sendAction(newNode, widget.Add) @@ -66,27 +66,27 @@ func watchCallback() { // 99.9% of events are just widget changes n := me.rootNode.findId(a.WidgetId) if n != nil { - log.Verbose("guiChan() FOUND widget id =", n.id, n.progname) + log.Log(INFO, "guiChan() FOUND widget id =", n.id, n.progname) n.gotUserEvent(a) break } // if not a widget change, something more bizare if a.ActionType == widget.UserQuit { - log.Warn("guiChan() User sent Quit()") + log.Log(WARN, "guiChan() User sent Quit()") log.Exit("wit/gui toolkit.UserQuit") break } if a.ActionType == widget.ToolkitPanic { - log.Warn("guiChan() Toolkit panic() in", a.ProgName) - log.Warn("guiChan() unload toolkit plugin here", a.ProgName) + log.Log(WARN, "guiChan() Toolkit panic() in", a.ProgName) + log.Log(WARN, "guiChan() unload toolkit plugin here", a.ProgName) me.rootNode.ListToolkits() for _, aplug := range allPlugins { - log.Warn("ListToolkits() already loaded toolkit plugin =", aplug.name) + log.Log(WARN, "ListToolkits() already loaded toolkit plugin =", aplug.name) if aplug.name == a.ProgName { - log.Warn("FOUND PLUGIN =", aplug.name) - log.Warn("unload here") - log.Warn("panic on purpose") + log.Log(WARN, "FOUND PLUGIN =", aplug.name) + log.Log(WARN, "unload here") + log.Log(WARN, "panic on purpose") me.rootNode.CloseToolkit(aplug.name) // panic("panic trapped!") // log.Sleep(.5) @@ -101,21 +101,21 @@ func watchCallback() { } if a.ActionType == widget.ToolkitLoad { newPlug := widget.GetString(a.Value) - log.Warn("Attempt to load a new toolkit", newPlug, "here") + log.Log(WARN, "Attempt to load a new toolkit", newPlug, "here") me.rootNode.LoadToolkit(newPlug) } if a.ActionType == widget.EnableDebug { - log.Warn("guiChan() Enable Debugging Window") - log.Warn("guiChan() TODO: not implemented") - log.Warn("guiChan() Listing Toolkits:") + log.Log(WARN, "guiChan() Enable Debugging Window") + log.Log(WARN, "guiChan() TODO: not implemented") + log.Log(WARN, "guiChan() Listing Toolkits:") PLUG.SetBool(true) me.rootNode.ListToolkits() me.rootNode.ListChildren(true) /* for i, aplug := range allPlugins { - log.Warn("plug =", i, aplug.name) + log.Log("plug =", i, aplug.name) if aplug.name == "andlabs" { - log.Warn("Found plug =", i, aplug.name) + log.Log("Found plug =", i, aplug.name) //closePlugin(aplug) allPlugins = allPlugins[1:] } @@ -123,7 +123,7 @@ func watchCallback() { */ break } - log.Warn("guiChan() Action could not be found or handled", a.ActionType, a) + log.Log(WARN, "guiChan() Action could not be found or handled", a.ActionType, a) } } } @@ -137,6 +137,12 @@ func (n *Node) gotUserEvent(a widget.Action) { log.Log(CHANGE, "gotUserEvent() received event node =", n.id, n.progname, a.Value) switch n.WidgetType { + case widget.Dropdown: + // n.checked = a.State.Checked // TODO: do this and/or time to switch to protobuf + n.currentS = a.State.CurrentS + case widget.Combobox: + // n.checked = a.State.Checked // TODO: do this and/or time to switch to protobuf + n.currentS = a.State.CurrentS case widget.Checkbox: // n.checked = a.State.Checked // TODO: do this and/or time to switch to protobuf n.checked = a.State.Checked @@ -163,14 +169,14 @@ func New() *Node { // try to load andlabs, if that doesn't work, fall back to the console func (n *Node) Default() *Node { if argGui.GuiPlugin != "" { - log.Warn("New.Default() try toolkit =", argGui.GuiPlugin) + log.Log(WARN, "New.Default() try toolkit =", argGui.GuiPlugin) return n.LoadToolkit(argGui.GuiPlugin) } // if DISPLAY isn't set, return since gtk can't load // TODO: figure out how to check what to do in macos and mswindows if os.Getenv("DISPLAY") == "" { if n.LoadToolkit("gocui") == nil { - log.Warn("New() failed to load gocui") + log.Log(WARN, "New() failed to load gocui") } return n } @@ -15,8 +15,9 @@ there isn't much to see here. */ func (n *Node) newNode(s string, t widget.WidgetType) *Node { if n == nil { - log.Warn("newNode got parent == nil") - panic("gui newNode") + log.Log(WARN, "newNode() ERROR got parent == nil") + // this is an error internal to this gui package + return n } var newN *Node @@ -84,5 +85,5 @@ func (n *Node) Delete(d *Node) { return } } - log.Warn("did not find node to delete", d.id, d.progname) + log.Log(WARN, "did not find node to delete", d.id, d.progname) } @@ -57,7 +57,7 @@ func initPlugin(name string) *aplug { for _, aplug := range allPlugins { log.Log(PLUG, "initPlugin() already loaded toolkit plugin =", aplug.name) if aplug.name == name { - log.Warn("initPlugin() SKIPPING", name, "as you can't load it twice") + log.Log(WARN, "initPlugin() SKIPPING", name, "as you can't load it twice") return nil } } @@ -92,7 +92,8 @@ func sendCallback(p *aplug, funcName string) func(chan widget.Action) { test, err = p.plug.Lookup(funcName) if err != nil { - log.Error(err, "DID NOT FIND: name =", test) + log.Log(WARN, "sendCallback() err =", err) + log.Log(WARN, "sendCallback() DID NOT FIND: name =", funcName) return nil } @@ -123,7 +124,8 @@ func searchPaths(name string) *aplug { pfile, err = me.resFS.ReadFile(filename) if err == nil { filename = "/tmp/" + name + ".so" - log.Error(err, "write out file here", name, filename, len(pfile)) + log.Log(WARN, "searchPaths() using toolkit embedded in executable") + log.Log(WARN, "searchPaths() resource file", name, filename, len(pfile)) f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600) f.Write(pfile) f.Close() @@ -132,7 +134,7 @@ func searchPaths(name string) *aplug { return p } } else { - log.Error(err, filename, "was not embedded in the binary") + log.Log(INFO, "searchPaths()", filename, "was not embedded in the binary") } // attempt to write out the file from the internal resource @@ -185,11 +187,13 @@ func initToolkit(name string, filename string) *aplug { } } log.Log(PLUG, "initToolkit() Found plugin", name, "as filename", filename) - log.Verbose("initToolkit() Verbose Found plugin", name, "as filename", filename) plug, err := plugin.Open(filename) if err != nil { - log.Error(err, "initToolkit() plugin FAILED =", filename) + // turn on PLUG debugging if something goes wrong + PLUG.SetBool(true) + log.Log(PLUG, "plugin.Open() err =", err) + log.Log(PLUG, "initToolkit() FAILED =", filename) return nil } log.Log(PLUG, "initToolkit() SUCCESS loading plugin =", filename) @@ -214,7 +218,7 @@ func initToolkit(name string, filename string) *aplug { // set the communication to the plugins newPlug.pluginChan = newPlug.PluginChannel() if newPlug.pluginChan == nil { - log.Warn("initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename) + log.Log(WARN, "initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename) return nil } newPlug.Callback(me.guiChan) @@ -247,14 +251,14 @@ func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node { p := initToolkit(name, f.Name()) if p == nil { - log.Warn("LoadToolkitEmbed() embedded go file failed", name) + log.Log(WARN, "LoadToolkitEmbed() embedded go file failed", name) } return n } func (n *Node) ListToolkits() { for _, aplug := range allPlugins { - log.Info("ListToolkits() already loaded toolkit plugin =", aplug.name) + log.Log(WARN, "ListToolkits() already loaded toolkit plugin =", aplug.name) } } @@ -51,8 +51,15 @@ func (n *Node) SetText(text string) *Node { n.label = text case widget.Combobox: n.newString = text + n.currentS = text + n.defaultS = text case widget.Dropdown: n.newString = text + n.currentS = text + n.defaultS = text + case widget.Textbox: + n.currentS = text + n.defaultS = text case widget.Window: n.label = text default: diff --git a/watchdog.go b/watchdog.go index e27a31e..5bd9008 100644 --- a/watchdog.go +++ b/watchdog.go @@ -36,7 +36,7 @@ func myTicker(t time.Duration, name string, f func()) { for { select { case <-done: - log.Warn("gui.Watchdog() Done!") + log.Log(WARN, "myTicker() Watchdog Done!") return case t := <-ticker.C: log.Log(INFO, name, "Current time: ", t) @@ -109,7 +109,7 @@ func (n *Node) TestDraw() { n.changed = true n.visable = true - log.Verbose("TestDraw() sending widget.Add", n.id, n.WidgetType, n.progname) + log.Log(INFO, "TestDraw() sending widget.Add", n.id, n.WidgetType, n.progname) sendAction(n, widget.Add) for _, child := range n.children { |
