Compare commits

...

10 Commits

Author SHA1 Message Date
Jeff Carr db990457e5 fix build 2024-11-16 00:07:09 -06:00
Jeff Carr 161f3934ce update to also embed toolkit plugins in the binary
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-11-07 13:30:17 -06:00
Jeff Carr bc01313a04 use standard debugger.go
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-12 10:14:50 -06:00
Jeff Carr 0949113167 added things to debug the toolkit code
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-09 03:48:46 -06:00
Jeff Carr de85ed65b3 trying to debug box direction
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-07 15:24:06 -06:00
Jeff Carr 89c14962b8 use standard log things
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-07 08:58:51 -06:00
Jeff Carr 3f3e8e1b2e button to set basic entry
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-05 15:04:41 -06:00
Jeff Carr 1a0de8d839 show the user changed the dropdown
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-02 15:13:21 -06:00
Jeff Carr 7a42716b98 more stuff for testing
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-01 22:00:23 -06:00
Jeff Carr 8082a52862 remove test code
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-01 11:37:14 -06:00
10 changed files with 193 additions and 89 deletions

14
.gitignore vendored
View File

@ -1,5 +1,9 @@
* *.swp
!.gitignore go.mod
!Makefile go.sum
!*.go
!LICENSE /files/*
/*.deb
/resources/*
gadgetwindow

View File

@ -1,41 +1,45 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
all: build all: build
reset
./gadgetwindow ./gadgetwindow
build:
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install:
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
clean:
-rm -f gadgetwindow
-rm resources/*.so
touch resources/blank.so
# embed the toolkit plugins in the binary
embed:
-rm resources/*.so
touch resources/blank.so
cp -a ~/go/src/go.wit.com/toolkits/*.so resources/
nocui: build nocui: build
reset reset
./gadgetwindow --gui nocui ./gadgetwindow --gui nocui
gocui: build gocui: build
reset reset
# ./gadgetwindow --gui gocui >/tmp/gadgetwindow.stderr 2>&1 echo "redirecting STDOUT & STDERR to /tmp/gadgetwindow.out"
./gadgetwindow --gui gocui --tmp-log ./gadgetwindow --gui gocui
test-tmp-log: build
./gadgetwindow --gui andlabs --tmp-log
debugger: build debugger: build
reset reset
./gadgetwindow --debugger ./gadgetwindow --debugger
build:
ifeq ($(GO111MODULE),)
echo no. you must use GO111MODULE here
false
else
-rm -f gadgetwindow
go build -v -x
endif
stderr: build
echo "writing to /tmp/gadgetwindow.stderr"
./gadgetwindow >/tmp/gadgetwindow.stderr 2>&1
push:
git add --all
git commit -a
git push
goimports: goimports:
goimports -w *.go goimports -w *.go
@ -44,4 +48,3 @@ redomod:
goimports -w *.go goimports -w *.go
GO111MODULE= go mod init GO111MODULE= go mod init
GO111MODULE= go mod tidy GO111MODULE= go mod tidy

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# gadgetwindow
This simple 'gui' demo also embedds the plugins into the binary
## Install go-glone
go build go.wit.com/apps/gadgetwindow@latest

36
args.go
View File

@ -1,36 +0,0 @@
package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debugger"
"go.wit.com/log"
)
// GadgetDisplay string `arg:"env:DISPLAY"`
// GadgetTmpLog bool `arg:"--tmp-log" help:"automatically send STDOUT to /tmp"`
// GadgetVerboseDNS bool `arg:"--verbose" help:"debug your dns settings"`
var args struct {
TmpLog bool `arg:"--tmp-log" help:"automatically send STDOUT to /tmp"`
}
var NOW *log.LogFlag
func init() {
arg.MustParse(&args)
full := "go.wit.com/control-panels/dns"
short := "cpdns"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
if debugger.ArgDebug() {
log.Log(NOW, "INIT() gui debug == true")
} else {
log.Log(NOW, "INIT() gui debug == false")
}
}

38
argv.go Normal file
View File

@ -0,0 +1,38 @@
package main
import (
"os"
"github.com/alexflint/go-arg"
)
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
var argv args
type args struct {
Demo string `arg:"positional" help:"this is just a demo"`
}
func (a args) Description() string {
return `
This basicwindow example demonstrates multiple windows
`
}
func init() {
pp := arg.MustParse(&argv)
// for very new users or users unfamilar with the command line, this may help them
if argv.Demo == "version" || argv.Demo == "help" || argv.Demo == "?" {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
}
func (args) Version() string {
return "basicwindow " + VERSION
}

View File

@ -2,6 +2,9 @@
package main package main
import ( import (
"math/rand"
"time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log" "go.wit.com/log"
@ -25,7 +28,8 @@ func newChoices(parent *gui.Node) *choices {
var c *choices var c *choices
c = new(choices) c = new(choices)
c.group = parent.NewGroup("choices") c.group = parent.NewGroup("choices")
c.grid = c.group.NewGrid("gridiron", 2, 1) c.grid = c.group.NewGrid("gridiron", 8, 1)
c.grid.NewButton("hello", func() { c.grid.NewButton("hello", func() {
log.Info("world") log.Info("world")
}) })
@ -33,37 +37,87 @@ func newChoices(parent *gui.Node) *choices {
basicWindow.Toggle() basicWindow.Toggle()
}) })
c.grid.NewLabel("a label") c.grid.NewLabel("a label")
c.grid.NextRow()
c.computers = c.grid.NewDropdown().SetProgName("COMPUTERS") c.computers = c.grid.NewDropdown().SetProgName("COMPUTERS")
c.computers.AddText("Atari 500") c.computers.AddText("Atari 500")
c.computers.AddText("Beagleboard") c.computers.AddText("Beagleboard")
c.computers.AddText("Unmatched Rev B") c.computers.AddText("Unmatched Rev B")
c.computers.AddText("asldjf")
c.computers.AddText("asdjf")
c.computers.AddText("a1jf")
c.computers.AddText("jf")
c.computers.SetText("Beagleboard") c.computers.SetText("Beagleboard")
c.computers.Custom = func() {
log.Info("You changed the computer to:", c.computers.String())
}
c.grid.NewButton("modify dropdown state", func() {
c.computers.AddText("Irix")
c.computers.AddText("Macintosh Plus")
c.computers.SetText("Irix")
rand.Seed(time.Now().UnixNano())
// Generate a random number between 0 and 25
randomNum := rand.Intn(8) // 26 because Intn is [0, n)
// Convert to a corresponding uppercase letter
randomLetter := rune('A' + randomNum)
c.computers.AddText("WIT " + string(randomLetter))
c.showState()
})
c.grid.NewButton("toggle", func() {
if c.computers.Hidden() {
c.computers.Show()
} else {
c.computers.Hide()
}
})
c.grid.NewButton("dropdown state", func() {
c.showState()
})
c.grid.NextRow()
c.colors = c.grid.NewCombobox().SetProgName("COLORS") c.colors = c.grid.NewCombobox().SetProgName("COLORS")
c.colors.AddText("Cyan") c.colors.AddText("Cyan")
c.colors.AddText("Magenta") c.colors.AddText("Magenta")
c.colors.AddText("Yellow") c.colors.AddText("Yellow")
c.colors.SetText("orange") c.colors.SetText("orange")
c.grid.NewButton("modify combobox state", func() {
c.colors.AddText("Red")
rand.Seed(time.Now().UnixNano())
// Generate a random number between 0 and 25
randomNum := rand.Intn(26) // 26 because Intn is [0, n)
// Convert to a corresponding uppercase letter
randomLetter := rune('A' + randomNum)
c.colors.AddText("Yellow " + string(randomLetter))
c.colors.SetText("blue")
log.Info("color value =", c.colors.String())
})
c.grid.NewButton("toggle", func() {
if c.colors.Hidden() {
c.colors.Show()
} else {
c.colors.Hide()
}
})
c.grid.NewButton("show state", func() {
c.showState()
})
c.grid.NextRow()
c.checkers = c.grid.NewCheckbox("Checkers").SetProgName("CHECKERS") c.checkers = c.grid.NewCheckbox("Checkers").SetProgName("CHECKERS")
c.checkers.Custom = func() { c.checkers.Custom = func() {
log.Info("Checkers is", c.checkers.Bool()) log.Info("Checkers is", c.checkers.Bool())
} }
c.grid.NextRow()
c.socks = gadgets.NewOneLiner(c.grid, "two for one") c.socks = gadgets.NewOneLiner(c.grid, "two for one")
c.socks.SetValue("socks") c.socks.SetValue("socks")
c.grid.NextRow()
c.animal = gadgets.NewBasicCombobox(c.grid, "animals") c.animal = gadgets.NewBasicCombobox(c.grid, "animals")
c.animal.AddText("otter") c.animal.AddText("otter")
c.animal.AddText("honey badger") c.animal.AddText("honey badger")
c.animal.AddText("polar bear") c.animal.AddText("polar bear")
c.grid.NextRow()
c.place = gadgets.NewBasicEntry(c.grid, "common favorite place") c.place = gadgets.NewBasicEntry(c.grid, "favorite place")
c.place.Custom = func() { c.place.Custom = func() {
log.Info("now set to:", c.place.String()) log.Info("now set to:", c.place.String())
if c.place == section1.place { if c.place == section1.place {
@ -74,6 +128,7 @@ func newChoices(parent *gui.Node) *choices {
} }
} }
c.place.SetText("coffee shop") c.place.SetText("coffee shop")
c.grid.NextRow()
c.grid.NewButton("enable animals", func() { c.grid.NewButton("enable animals", func() {
c.animal.Enable() c.animal.Enable()
@ -81,6 +136,9 @@ func newChoices(parent *gui.Node) *choices {
c.grid.NewButton("disable animals", func() { c.grid.NewButton("disable animals", func() {
c.animal.Disable() c.animal.Disable()
}) })
c.grid.NewButton("set trust", func() {
c.place.SetText("trust")
})
return c return c
} }
@ -89,3 +147,14 @@ func (c *choices) SetSocks(s string) *choices {
c.socks.SetValue(s) c.socks.SetValue(s)
return c return c
} }
func (c *choices) showState() {
log.Info("computers value =", c.computers.String())
for i, s := range c.computers.Strings() {
log.Println("computers has:", i, s)
}
log.Info("color value =", c.colors.String())
for i, s := range c.colors.Strings() {
log.Println("has option", i, s)
}
}

20
debugger.go Normal file
View File

@ -0,0 +1,20 @@
package main
/*
enables GUI options and the debugger in your application
*/
import (
"go.wit.com/lib/debugger"
"go.wit.com/log"
)
func init() {
if debugger.ArgDebug() {
log.Info("cmd line --debugger == true")
go func() {
log.Sleep(2)
debugger.DebugWindow()
}()
}
}

30
main.go
View File

@ -1,7 +1,8 @@
// This creates a simple hello world window
package main package main
import ( import (
"embed"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/debugger" "go.wit.com/lib/debugger"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
@ -9,9 +10,15 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
// sent via -ldflags
var VERSION string
// This is the beginning of the binary tree of widgets // This is the beginning of the binary tree of widgets
var myGui *gui.Node var myGui *gui.Node
//go:embed resources/*
var resources embed.FS
// this is the primary window. If you close it, the program will exit // this is the primary window. If you close it, the program will exit
var mainWindow *gui.Node var mainWindow *gui.Node
@ -27,27 +34,13 @@ func main() {
log.SetAll(true) log.SetAll(true)
log.ShowFlags() log.ShowFlags()
} }
if args.TmpLog {
// send all log() output to a file in /tmp
log.SetTmp()
}
myGui = gui.New() myGui = gui.New()
// myGui.LoadToolkit("andlabs") myGui.InitEmbed(resources)
// myGui.LoadToolkit("nocui")
myGui.Default() myGui.Default()
helloworld() helloworld()
basicWindow = makebasicWindow() basicWindow = makebasicWindow()
// run the debugger if triggered from the commandline
if debugger.ArgDebug() {
go func() {
log.Sleep(2)
debugger.DebugWindow()
}()
}
// go will sit here until the window exits // go will sit here until the window exits
gui.Watchdog() gui.Watchdog()
} }
@ -57,6 +50,8 @@ func helloworld() {
mainWindow = myGui.NewWindow("hello world").SetProgName("BASEWIN1") mainWindow = myGui.NewWindow("hello world").SetProgName("BASEWIN1")
box := mainWindow.NewBox("hbox", true) box := mainWindow.NewBox("hbox", true)
// box := mainWindow.Box().Vertical()
// box := mainWindow.Box().Horizontal()
section1 = newChoices(box) section1 = newChoices(box)
group := box.NewGroup("interact") group := box.NewGroup("interact")
@ -83,6 +78,9 @@ func helloworld() {
group.NewButton("Hide apple", func() { group.NewButton("Hide apple", func() {
apple.Hide() apple.Hide()
}) })
group.NewCheckbox("test checkbox").SetChecked(true)
group.NewLabel("test label")
gadgets.NewBasicEntry(group, "test entry")
group.NewButton("set socks", func() { group.NewButton("set socks", func() {
section1.SetSocks("blue") section1.SetSocks("blue")
section2.SetSocks("green") section2.SetSocks("green")

0
resources/blank.so Normal file
View File

View File

@ -23,7 +23,9 @@ func makebasicWindow() *gadgets.BasicWindow {
box1 := basicWindow.Box() box1 := basicWindow.Box()
section2 = newChoices(box1) section2 = newChoices(box1)
vbox := box1.NewBox("vbox", false) // vbox := box1.NewBox("vbox", false)
// vbox := box1.Box().Vertical()
vbox := box1.Box().Horizontal()
group1 := vbox.NewGroup("controls").Horizontal() // Vertical() group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
group1.NewButton("hide apple", func() { group1.NewButton("hide apple", func() {
apple.Hide() apple.Hide()