summaryrefslogtreecommitdiff
path: root/examples/buttons
diff options
context:
space:
mode:
Diffstat (limited to 'examples/buttons')
-rw-r--r--examples/buttons/Makefile26
-rwxr-xr-xexamples/buttons/buttonpluginbin0 -> 6062120 bytes
-rwxr-xr-xexamples/buttons/buttonsbin0 -> 6062120 bytes
-rw-r--r--examples/buttons/log.go78
-rw-r--r--examples/buttons/main.go104
5 files changed, 208 insertions, 0 deletions
diff --git a/examples/buttons/Makefile b/examples/buttons/Makefile
new file mode 100644
index 0000000..74b7728
--- /dev/null
+++ b/examples/buttons/Makefile
@@ -0,0 +1,26 @@
+# with andlabs plugin loaded:
+# PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
+# 180006 jcarr 20 0 1918460 41688 31152 S 0.7 0.3 0:00.27 buttonplugin
+
+# with gocui plugin loaded:
+# 180365 jcarr 20 0 1392668 24364 12596 S 2.0 0.2 0:00.09 buttonplugin
+#
+
+run: build
+ ./buttons --gui andlabs
+
+build-release:
+ go get -v -u -x .
+ go build
+ ./buttons
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
+
+log:
+ reset
+ tail -f /tmp/witgui.* /tmp/guilogfile
diff --git a/examples/buttons/buttonplugin b/examples/buttons/buttonplugin
new file mode 100755
index 0000000..3f4dee3
--- /dev/null
+++ b/examples/buttons/buttonplugin
Binary files differ
diff --git a/examples/buttons/buttons b/examples/buttons/buttons
new file mode 100755
index 0000000..01ea9aa
--- /dev/null
+++ b/examples/buttons/buttons
Binary files differ
diff --git a/examples/buttons/log.go b/examples/buttons/log.go
new file mode 100644
index 0000000..7d65d05
--- /dev/null
+++ b/examples/buttons/log.go
@@ -0,0 +1,78 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "fmt"
+ arg "github.com/alexflint/go-arg"
+ "git.wit.org/wit/gui"
+ log "git.wit.org/wit/gui/log"
+)
+
+
+var args struct {
+ Foo string
+ Bar bool
+ User string `arg:"env:USER"`
+ Demo bool `help:"run a demo"`
+ gui.GuiArgs
+ log.LogArgs
+}
+
+/*
+var f1 *os.File
+var f2 *os.File
+var err error
+*/
+
+func init() {
+ arg.MustParse(&args)
+ fmt.Println(args.Foo, args.Bar, args.User)
+
+ if (args.Gui != "") {
+ gui.GuiArg.Gui = args.Gui
+ }
+ log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
+
+/*
+ log.Println()
+ log.Println("STDOUT is now at /tmp/guilogfile")
+ log.Println("STDOUT is now at /tmp/guilogfile")
+ log.Println()
+ f1, err = os.OpenFile(outfile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
+ if err != nil {
+ log.Fatalf("error opening file: %v", err)
+ }
+ // hmm. is there a trick here or must this be in main()
+ // defer f.Close()
+
+ log.SetOutput(f1)
+ log.Println("This is a test log entry")
+*/
+}
+
+/*
+func captureSTDOUT() {
+ f2, _ = os.OpenFile("/tmp/my.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
+ multiWriter := io.MultiWriter(os.Stderr, f2)
+ rd, wr, err := os.Pipe()
+ if err != nil {
+ os.Exit(1)
+ }
+
+ // overwrite os.Stdout
+ os.Stderr = wr
+
+ go func() {
+ scanner := bufio.NewScanner(rd)
+ for scanner.Scan() {
+ stdoutLine := scanner.Text()
+ multiWriter.Write([]byte(stdoutLine + "\n"))
+ }
+ }()
+
+ fmt.Println("foobar")
+
+ // hacky sleep to ensure the go routine can write before program exits
+ time.Sleep(time.Second)
+}
+*/
diff --git a/examples/buttons/main.go b/examples/buttons/main.go
new file mode 100644
index 0000000..3200e9e
--- /dev/null
+++ b/examples/buttons/main.go
@@ -0,0 +1,104 @@
+// This is a simple example
+package main
+
+import (
+ "fmt"
+ "log"
+ "strconv"
+ "git.wit.org/wit/gui"
+)
+
+var title string = "Demo Plugin Window"
+var outfile string = "/tmp/guilogfile"
+var myGui *gui.Node
+
+var buttonCounter int = 5
+var gridW int = 5
+var gridH int = 3
+
+func main() {
+ // This will turn on all debugging
+ // gui.SetDebug(true)
+
+ myGui = gui.New().Default()
+ buttonWindow()
+
+ // This is just a optional goroutine to watch that things are alive
+ gui.Watchdog()
+ gui.StandardExit()
+}
+
+// This creates a window
+func buttonWindow() {
+ var w, t, g, more, more2 *gui.Node
+
+ log.Println("buttonWindow() START")
+
+ w = myGui.NewWindow(title).SetText("Nueva Ventana de Botones")
+ t = w.NewTab("buttonTab is this thing")
+ g = t.NewGroup("buttonGroup")
+ g1 := t.NewGroup("buttonGroup 2")
+ more = g1.NewGroup("more")
+ g1.NewButton("hello2", func () {
+ log.Println("world2")
+ })
+ more2 = g1.NewGrid("gridnuts", gridW, gridH)
+
+ more2.NewLabel("more2")
+
+ g.NewButton("this app is useful for plugin debuggin", func () {
+ })
+ g.NewLabel("STDOUT is set to: " + outfile)
+
+ g.NewButton("hello", func () {
+ log.Println("world")
+ })
+
+ g.NewButton("Load 'gocui'", func () {
+ // this set the xterm and mate-terminal window title. maybe works generally?
+ fmt.Println("\033]0;" + title + "blah \007")
+ myGui.LoadToolkit("gocui")
+ })
+
+ g.NewButton("Load 'andlabs'", func () {
+ myGui.LoadToolkit("andlabs")
+ })
+
+ g.NewButton("NewButton(more)", func () {
+ name := "foobar " + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more) Adding button", name)
+ buttonCounter += 1
+ more.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewButton(more2)", func () {
+ name := "foobar " + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more2) Adding button", name)
+ buttonCounter += 1
+ more2.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewButton(more2 d)", func () {
+ name := "d" + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more2 d) Adding button", name)
+ buttonCounter += 1
+ more2.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewGroup()", func () {
+ name := "neat " + strconv.Itoa(buttonCounter)
+ log.Println("NewGroup() Adding button", name)
+ buttonCounter += 1
+ more.NewGroup(name)
+ })
+
+ g.NewButton("gui.DebugWindow()", func () {
+ gui.DebugWindow()
+ })
+}