NODE: migrate more of my personal gui app
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
73006c8b5e
commit
c80f805bff
37
box.go
37
box.go
|
@ -185,3 +185,40 @@ func VerticalBreak(box *GuiBox) {
|
||||||
tmp := ui.NewVerticalSeparator()
|
tmp := ui.NewVerticalSeparator()
|
||||||
box.UiBox.Append(tmp, false)
|
box.UiBox.Append(tmp, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) AddComboBox(title string, s ...string) *Node {
|
||||||
|
box := n.uiBox
|
||||||
|
if (box == nil) {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
ecbox := ui.NewEditableCombobox()
|
||||||
|
|
||||||
|
for id, name := range s {
|
||||||
|
log.Println("Adding Combobox Entry:", id, name)
|
||||||
|
ecbox.Append(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
ecbox.OnChanged(func(*ui.EditableCombobox) {
|
||||||
|
test := ecbox.Text()
|
||||||
|
log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'")
|
||||||
|
})
|
||||||
|
|
||||||
|
box.Append(ecbox, false)
|
||||||
|
|
||||||
|
newNode := n.AddNode(title)
|
||||||
|
newNode.uiText = ecbox
|
||||||
|
return newNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) OnChanged(f func()) {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) GetText() string {
|
||||||
|
if (n.uiText == nil) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
ecbox := n.uiText
|
||||||
|
return ecbox.Text()
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 () {
|
||||||
|
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()
|
||||||
|
}
|
|
@ -27,14 +27,14 @@ func initGUI() {
|
||||||
gui.Config.Height = 480
|
gui.Config.Height = 480
|
||||||
gui.Config.Exit = myExit
|
gui.Config.Exit = myExit
|
||||||
node1 := gui.NewWindow()
|
node1 := gui.NewWindow()
|
||||||
node1.AddDemoTab("A Simple Tab Demo")
|
addDemoTab(node1, "A Simple Tab Demo")
|
||||||
|
|
||||||
gui.Config.Title = "WIT GUI Window Demo 2"
|
gui.Config.Title = "WIT GUI Window Demo 2"
|
||||||
gui.Config.Width = 640
|
gui.Config.Width = 640
|
||||||
gui.Config.Height = 240
|
gui.Config.Height = 240
|
||||||
gui.Config.Exit = myExit
|
gui.Config.Exit = myExit
|
||||||
node2 := gui.NewWindow()
|
node2 := gui.NewWindow()
|
||||||
node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo")
|
node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This demonstrates how to properly interact with the GUI
|
// This demonstrates how to properly interact with the GUI
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
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
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "log"
|
// import "log"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
|
@ -23,35 +23,3 @@ func (n *Node) AddGroup(title string) *Node {
|
||||||
newNode.uiBox = vbox
|
newNode.uiBox = vbox
|
||||||
return newNode
|
return newNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) GetText(name string) string {
|
|
||||||
if (n.uiText != nil) {
|
|
||||||
return n.uiText.Text()
|
|
||||||
}
|
|
||||||
return n.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) AddComboBox(title string, s ...string) *Node {
|
|
||||||
box := n.uiBox
|
|
||||||
if (box == nil) {
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
ecbox := ui.NewEditableCombobox()
|
|
||||||
|
|
||||||
for id, name := range s {
|
|
||||||
log.Println("Adding Combobox Entry:", id, name)
|
|
||||||
ecbox.Append(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
ecbox.OnChanged(func(*ui.EditableCombobox) {
|
|
||||||
test := ecbox.Text()
|
|
||||||
log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'")
|
|
||||||
})
|
|
||||||
|
|
||||||
box.Append(ecbox, false)
|
|
||||||
|
|
||||||
newNode := n.AddNode(title)
|
|
||||||
newNode.uiText = ecbox
|
|
||||||
return newNode
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue