save 'universal' go-arg
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
01ab0180f4
commit
7313c83e69
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
6
main.go
6
main.go
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue