diff options
| author | Jeff Carr <[email protected]> | 2022-10-17 22:39:03 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2022-10-17 22:39:03 -0500 |
| commit | 15baefd9a7d145ddffced80d0fb6c14f258bdcc9 (patch) | |
| tree | 633838faafa5c545635e77d441455bc8eb47958f /cmds | |
| parent | 7e32b1fb9a44624ce2d4a8bc5c6acd5fafc820f3 (diff) | |
GROUP: implement 'group' in toolkit/
move gui.group into toolkit
remove duplicate code
update demo
Diffstat (limited to 'cmds')
| -rw-r--r-- | cmds/gui-demo/demo-window.go | 33 | ||||
| -rw-r--r-- | cmds/gui-demo/main.go | 14 | ||||
| -rw-r--r-- | cmds/gui-example/Makefile | 6 | ||||
| -rw-r--r-- | cmds/gui-example/demo-window.go | 105 | ||||
| -rw-r--r-- | cmds/gui-example/main.go | 68 | ||||
| -rw-r--r-- | cmds/gui-example/os.go | 99 | ||||
| -rw-r--r-- | cmds/helloworld/Makefile | 4 | ||||
| -rw-r--r-- | cmds/helloworld/main.go | 5 |
8 files changed, 6 insertions, 328 deletions
diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go deleted file mode 100644 index fd8e8f4..0000000 --- a/cmds/gui-demo/demo-window.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import "log" - -import "git.wit.org/wit/gui" - -func demoClick (n *gui.Node) { - log.Println("demoClick() Dumping node:") - n.Dump() -} - -func addDemoTab(n *gui.Node, title string) { - newNode := n.AddTab(title, nil) - if (gui.Config.Debug) { - newNode.Dump() - } - newNode.ListChildren(false) - - groupNode1 := newNode.AddGroup("group 1") - groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff") - groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") - - groupNode1.Dump() - - butNode1 := groupNode1.AddButton("button1", demoClick) - butNode1.Dump() - - butNode2 := groupNode1.AddButton("button2", demoClick) - butNode2.Dump() - - groupNode2 := newNode.AddGroup("group 2") - groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") -} diff --git a/cmds/gui-demo/main.go b/cmds/gui-demo/main.go index 8eae878..0084e3a 100644 --- a/cmds/gui-demo/main.go +++ b/cmds/gui-demo/main.go @@ -22,19 +22,7 @@ func main() { // This initializes the first window func initGUI() { - gui.Config.Title = "WIT GUI Window Demo 1" - gui.Config.Width = 640 - gui.Config.Height = 480 - gui.Config.Exit = myExit - node1 := gui.NewWindow() - addDemoTab(node1, "A Simple Tab Demo") - - gui.Config.Title = "WIT GUI Window Demo 2" - gui.Config.Width = 640 - gui.Config.Height = 240 - gui.Config.Exit = myExit - node2 := gui.NewWindow() - node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") + gui.ToolkitDemoWindow() } // This demonstrates how to properly interact with the GUI diff --git a/cmds/gui-example/Makefile b/cmds/gui-example/Makefile deleted file mode 100644 index 9ecbe55..0000000 --- a/cmds/gui-example/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -run: build - ./gui-example - -build: - GO111MODULE="off" go get -v . - GO111MODULE="off" go build diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go deleted file mode 100644 index 02c7a50..0000000 --- a/cmds/gui-example/demo-window.go +++ /dev/null @@ -1,105 +0,0 @@ -package main - -import "log" -import "reflect" - -import "git.wit.org/wit/gui" - -import "github.com/davecgh/go-spew/spew" - -func demoClick (n *gui.Node) { - log.Println("demoClick() Dumping node:") - n.Dump() -} - -var username = "jcarr" -var hostname = "fire" - -func newClick (n *gui.Node) { - var tmp []string - junk := "ssh -v " + username + "@" + hostname - log.Println("junk = " , junk) - xterm(junk) - log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) - // spew.Dump(tmp) -} - -func addDemoTab(n *gui.Node, title string) { - newNode := n.AddTab(title, nil) - if (gui.Config.Debug) { - newNode.Dump() - } - newNode.ListChildren(false) - - groupNode1 := newNode.AddGroup("group 1") - cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") - cbNode.OnChanged = func (cbNode *gui.Node) { - username = cbNode.GetText() - } - groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") - - groupNode1.Dump() - - butNode1 := groupNode1.AddButton("button1", demoClick) - butNode1.Dump() - - butNode2 := groupNode1.AddButton("button2", newClick) - butNode2.Dump() - - groupNode2 := newNode.AddGroup("group 2") - groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") - - gNode := newNode.AddGroup("domU") - makeSSHbutton(gNode, "hugo@www", "www.wit.org") - makeSSHbutton(gNode, "check.lab", "check.lab.wit.org") - makeSSHbutton(gNode, "gobuild.lab", "gobuild.lab.wit.org") - makeSSHbutton(gNode, "gobuild2.lab", "gobuild2.lab.wit.org") - -/////////////////////////////// Column DNS //////////////////////////////// - gNode = newNode.AddGroup("dns") - makeSSHbutton(gNode, "bind.wit.org", "bind.wit.org") - makeSSHbutton(gNode, "ns1.wit.com", "ns1.wit.com") - makeSSHbutton(gNode, "ns2.wit.com", "ns2.wit.com") - makeSSHbutton(gNode, "coredns", "coredns.lab.wit.org") - -/////////////////////////////// PHYS 530 ////////////////////////////////// - gNode = newNode.AddGroup("phys 530") - // makeXtermButton(gNode, "openwrt", "SUBDOMAIN", "ssh -4 -v root@openwrt") - gNode.AddButton("openwrt", func (*gui.Node) { - stuff := "ssh -4 -v root@openwrt" - xterm(stuff) - }) - makeSSHbutton (gNode, "mirrors", "mirrors.wit.org") - makeSSHbutton (gNode, "node004", "node004.lab.wit.org") - makeSSHbutton (gNode, "lenovo-z70", "lenovo-z70.lab.wit.org") - -/////////////////////////////// PHYS 522 ////////////////////////////////// - gNode = newNode.AddGroup("phys 522") - // makeXtermButton(gNode, "openwrt2", "SUBDOMAIN", "ssh -4 -v root@openwrt2") - gNode.AddButton("openwrt2", func (*gui.Node) { - stuff := "ssh -4 -v root@openwrt2" - xterm(stuff) - }) - makeSSHbutton (gNode, "fire.lab", "fire.lab.wit.org") - makeSSHbutton (gNode, "predator", "predator.lab.wit.org") - -/////////////////////////////// FLOAT ///////////////////////////////////// - gNode = newNode.AddGroup("float") - makeSSHbutton(gNode, "root@asus-n501vw", "asus-n501vw.lab.wit.org") -} - -func makeSSHbutton (n *gui.Node, name string, hostname string) { - bNode := n.AddButton(name, func (*gui.Node) { - var tmp []string - if (username == "") { - username = "root" - } - junk := "ssh -v " + username + "@" + hostname - log.Println("junk = " , junk) - log.Println("username = '" + username + "'") - xterm(junk) - log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) - spew.Dump(tmp) - }) - bNode.Dump() -} diff --git a/cmds/gui-example/main.go b/cmds/gui-example/main.go deleted file mode 100644 index 8eae878..0000000 --- a/cmds/gui-example/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "log" - "os" - "time" - - "git.wit.org/wit/gui" -) - -// This initializes the first window -// -// Then starts a goroutine to demonstrate how to -// inject things into the GUI -func main() { - log.Println("Starting my Control Panel") - - go gui.Main(initGUI) - - watchGUI() -} - -// This initializes the first window -func initGUI() { - gui.Config.Title = "WIT GUI Window Demo 1" - gui.Config.Width = 640 - gui.Config.Height = 480 - gui.Config.Exit = myExit - node1 := gui.NewWindow() - addDemoTab(node1, "A Simple Tab Demo") - - gui.Config.Title = "WIT GUI Window Demo 2" - gui.Config.Width = 640 - gui.Config.Height = 240 - gui.Config.Exit = myExit - node2 := gui.NewWindow() - node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") -} - -// This demonstrates how to properly interact with the GUI -// You can not involke the GUI from external goroutines in most cases. -func watchGUI() { - var i = 1 - for { - log.Println("Waiting", i, "seconds") - i += 1 - time.Sleep(1 * time.Second) - if i == 4 { - log.Println("Opening a Debug Window via the gui.Queue()") - gui.Config.Width = 800 - gui.Config.Height = 300 - gui.Config.Exit = myDebugExit - gui.Queue(gui.DebugWindow) - } - } -} - -func myExit(n *gui.Node) { - log.Println() - log.Println("Entered myExit() on node.Name =", n.Name) - log.Println() - os.Exit(0) -} - -func myDebugExit(n *gui.Node) { - log.Println("Entered myDebugExit() on node.Name =", n.Name) - log.Println("Don't actually os.Exit()") -} diff --git a/cmds/gui-example/os.go b/cmds/gui-example/os.go deleted file mode 100644 index ce5db8d..0000000 --- a/cmds/gui-example/os.go +++ /dev/null @@ -1,99 +0,0 @@ -package main - -import "log" -import "strings" -import "os" -import "os/exec" -import "io/ioutil" -import "errors" -// import "bufio" - -// import "github.com/davecgh/go-spew/spew" - -/* -import "time" -import "runtime" -import "runtime/debug" -import "runtime/pprof" - -import "git.wit.org/wit/gui" -import "git.wit.org/wit/shell" -import "github.com/gobuffalo/packr" -*/ - -func runSimpleCommand(s string) { - cmd := strings.TrimSpace(s) // this is like 'chomp' in perl - cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl - cmdArgs := strings.Fields(cmd) - runLinuxCommand(cmdArgs) -} - -var geom string = "120x30+500+500" - -func xterm(cmd string) { - var tmp []string - var argsXterm = []string{"nohup", "xterm", "-geometry", geom} - tmp = append(argsXterm, "-hold", "-e", cmd) - log.Println("xterm cmd=", cmd) - go runCommand(tmp) -} - -func runCommand(cmdArgs []string) { - log.Println("runCommand() START", cmdArgs) - process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) - // process := exec.Command("xterm", "-e", "ping localhost") - log.Println("runCommand() process.Start()") - process.Start() - log.Println("runCommand() process.Wait()") - err := process.Wait() - lookupError(err) - log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED") - log.Println("runCommand() OTHERWISE INFORM THE USER") - log.Println("runCommand() END", cmdArgs) -} - -func lookupError(err error) { - var ( - ee *exec.ExitError - pe *os.PathError - ) - - if errors.As(err, &ee) { - log.Println("ran, but non-zero exit code =", ee.ExitCode()) // ran, but non-zero exit code - } else if errors.As(err, &pe) { - log.Printf("os.PathError = %v", pe) // "no such file ...", "permission denied" etc. - } else if err != nil { - log.Printf("something really bad happened general err = %v", err) // something really bad happened! - if exitError, ok := err.(*exec.ExitError); ok { - log.Printf("exitError.ExitCode() is %d\n", exitError.ExitCode()) - } - } else { - log.Println("success! // ran without error (exit code zero)") - } -} - -func runLinuxCommand(cmdArgs []string) (string, error) { - process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) - - process.Stdin = os.Stdin - process.Stderr = os.Stderr - - stdOut, err := process.StdoutPipe() - if err != nil { - return "", err - } - - if err := process.Start(); err != nil { - return "", err - } - - bytes, err := ioutil.ReadAll(stdOut) - if err != nil { - return "", err - } - err = process.Wait() - lookupError(err) - - log.Println(string(bytes)) - return string(bytes), err -} diff --git a/cmds/helloworld/Makefile b/cmds/helloworld/Makefile index f18abaf..1d12c3c 100644 --- a/cmds/helloworld/Makefile +++ b/cmds/helloworld/Makefile @@ -1,11 +1,11 @@ run: build ./helloworld -build: +build-release: go get -v -u -x . go build -build-master: +build: GO111MODULE="off" go get -v -x . GO111MODULE="off" go build ./helloworld diff --git a/cmds/helloworld/main.go b/cmds/helloworld/main.go index 6e52a0b..bc0a046 100644 --- a/cmds/helloworld/main.go +++ b/cmds/helloworld/main.go @@ -26,8 +26,9 @@ func initGUI() { func addDemoTab(n *gui.Node, title string) { newNode := n.AddTab(title, nil) - groupNode1 := newNode.AddGroup("group 1") - groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + g := newNode.NewGroup("group 1") + // g.Dump() + g.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") } func myDefaultExit(n *gui.Node) { |
