diff options
| author | Jeff Carr <[email protected]> | 2023-12-29 09:24:06 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-29 09:24:06 -0600 |
| commit | 4b0077cce106d638944ecd8a6d49ee23fae79dc4 (patch) | |
| tree | 123d38cd74ec6650fcd912ea0c8ad6f9e143e6a1 | |
| parent | 015847b28ee5dc5c7cfd29dfcbe14e3a2624569c (diff) | |
save 'universal' go-arg
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | args.go | 22 | ||||
| -rw-r--r-- | gadgets/basicEntry.go | 56 | ||||
| -rw-r--r-- | main.go | 6 | ||||
| -rw-r--r-- | structs.go | 9 |
4 files changed, 81 insertions, 12 deletions
@@ -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 +} diff --git a/gadgets/basicEntry.go b/gadgets/basicEntry.go new file mode 100644 index 0000000..105347b --- /dev/null +++ b/gadgets/basicEntry.go @@ -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 +} @@ -123,9 +123,9 @@ func New() *Node { // try to load andlabs, if that doesn't work, fall back to the console func (n *Node) Default() *Node { - if (GuiArg.Gui != "") { - log(logError, "New.Default() try toolkit =", GuiArg.Gui) - return n.LoadToolkit(GuiArg.Gui) + if (guiArg.Gui != "") { + log(logError, "New.Default() try toolkit =", guiArg.Gui) + return n.LoadToolkit(guiArg.Gui) } // if DISPLAY isn't set, return since gtk can't load // TODO: figure out how to check what to do in macos and mswindows @@ -23,15 +23,6 @@ import ( 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 { initOnce sync.Once |
