// This is a simple example package main import ( "strings" "os/exec" "go.wit.com/log" "go.wit.com/gui/gui" "go.wit.com/gui/gadgets" "go.wit.com/apps/control-panel-dns/smartwindow" ) var myGui *gui.Node func main() { myGui = gui.New().Default() helloworld() // This is just a optional goroutine to watch that things are alive gui.Watchdog() } func addRepo(grid *gui.Node, path string) { grid.NewLabel(path) ver := grid.NewLabel("VERSION") b, out := run(path, "git", "describe --tags") if b { ver.SetText(out) } // cmd := "dig +noall +answer www.wit.com A" // out = shell.Run(cmd) grid.NewLabel("jcarr") grid.NewLabel("dirty") grid.NewButton("commit", func () { log.Println("world") hellosmart() }) grid.NewButton("push", func () { log.Println("world") hellosmart() }) } // This creates a window func helloworld() { win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window") box := win.Box().NewBox("bw vbox", false) group := box.NewGroup("test") grid := group.NewGrid("test", 6, 1) grid.NewLabel("Repo") grid.NewLabel("Version") grid.NewLabel("Current branch") grid.NewLabel("is dirty?") grid.NewLabel("commit") grid.NewLabel("push to") addRepo(grid, "go.wit.com/log") addRepo(grid, "go.wit.com/arg") addRepo(grid, "go.wit.com/spew") addRepo(grid, "go.wit.com/shell") addRepo(grid, "") addRepo(grid, "go.wit.com/gui/gadgets") addRepo(grid, "go.wit.com/gui/gadgets") box.NewButton("hello", func () { log.Println("world") hellosmart() }) } // This creates a window func hellosmart() { win := smartwindow.New() win.SetParent(myGui) win.InitWindow() win.Title("helloworld golang wit/gui window") win.Vertical() win.SetDraw(smartDraw) win.Make() win.Box().NewButton("test smartwindow", func () { log.Println("smart") }) } func smartDraw(sw *smartwindow.SmartWindow) { sw.Box().NewButton("hello", func () { log.Println("smart") }) } func run(path string, thing string, cmdline string) (bool, string) { parts := strings.Split(cmdline, " ") // Create the command cmd := exec.Command(thing, parts...) // Set the working directory cmd.Dir = "/home/jcarr/go/src/" + path // Execute the command output, err := cmd.CombinedOutput() if err != nil { log.Error(err, "cmd error'd out", parts) return false, "" } // Print the output log.Info(string(output)) return true, string(output) }