save 'universal' go-arg

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-29 09:24:06 -06:00
parent 01ab0180f4
commit 7313c83e69
4 changed files with 81 additions and 12 deletions

22
args.go Normal file
View File

@ -0,0 +1,22 @@
package gui
import (
arg "github.com/alexflint/go-arg"
)
var guiArg GuiArgs
// This struct can be used with the go-arg package
type GuiArgs struct {
Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"`
GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"`
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
}
func init() {
arg.Register(&guiArg)
}
func GetArg(a string) bool {
return guiArg.GuiDebug
}

56
gadgets/basicEntry.go Normal file
View File

@ -0,0 +1,56 @@
/*
A Labeled Single Line Entry widget:
-----------------------------
| | |
| Food: | <type here> |
| | |
-----------------------------
*/
package gadgets
import (
"go.wit.com/log"
"go.wit.com/gui"
)
type BasicEntry struct {
parent *gui.Node // parent widget
l *gui.Node // label widget
v *gui.Node // value widget
value string
label string
Custom func()
}
func (n *BasicEntry) Get() string {
return n.value
}
func (n *BasicEntry) Set(value string) *BasicEntry {
log.Println("BasicEntry.Set() =", value)
if (n.v != nil) {
n.v.Set(value)
}
n.value = value
return n
}
func NewBasicEntry(p *gui.Node, name string) *BasicEntry {
d := BasicEntry {
parent: p,
value: "",
}
// various timeout settings
d.l = p.NewLabel(name)
d.v = p.NewEntryLine("")
d.v.Custom = func() {
d.value = d.v.S
log.Println("BasicEntry.Custom() user changed value to =", d.value)
}
return &d
}

View File

@ -123,9 +123,9 @@ func New() *Node {
// try to load andlabs, if that doesn't work, fall back to the console // try to load andlabs, if that doesn't work, fall back to the console
func (n *Node) Default() *Node { func (n *Node) Default() *Node {
if (GuiArg.Gui != "") { if (guiArg.Gui != "") {
log(logError, "New.Default() try toolkit =", GuiArg.Gui) log(logError, "New.Default() try toolkit =", guiArg.Gui)
return n.LoadToolkit(GuiArg.Gui) return n.LoadToolkit(guiArg.Gui)
} }
// if DISPLAY isn't set, return since gtk can't load // if DISPLAY isn't set, return since gtk can't load
// TODO: figure out how to check what to do in macos and mswindows // TODO: figure out how to check what to do in macos and mswindows

View File

@ -23,15 +23,6 @@ import (
var me guiConfig var me guiConfig
var GuiArg GuiArgs
// This struct can be used with the go-arg package
type GuiArgs struct {
Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"`
GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"`
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
}
type guiConfig struct { type guiConfig struct {
initOnce sync.Once initOnce sync.Once