From 6a09621efc0a42cbf2bd677941f82388d7a117a1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 5 Jan 2024 12:13:21 -0600 Subject: [PATCH] comples and runs after go.wit.com/gui migration Signed-off-by: Jeff Carr --- Makefile | 6 ++-- apt.go | 23 ++++++++------- gui-button.go | 2 +- main.go | 40 +++++++++----------------- os.go | 22 +++++++------- systray.go | 32 ++++++++++----------- window-debug-golang.go | 40 +++++++++++++------------- window-dns-update.go | 37 +++++++++++------------- window-main.go | 26 ----------------- window-packages.go | 49 +++++++++++++++---------------- window-resets.go | 53 ++++++++++++++++------------------ window-resolv.go | 65 ++++++++++++++++++++++-------------------- window-ssh-generic.go | 55 ++++++++++++++++++----------------- window-www.go | 26 +++++++++-------- window-xterm.go | 46 +++++++++++++++++------------- 15 files changed, 244 insertions(+), 278 deletions(-) delete mode 100644 window-main.go diff --git a/Makefile b/Makefile index e1041dc..6835e89 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ VERSION = $(shell cat resources/VERSION) # PATH=/usr/bin:$PATH go version -run: new-build - ~/go/bin/debian-gui +run: build + ./wit-debian-gui new-build: # go mod edit -replace go.wit.com/wit/gui=/home/jcarr/go/src/git.wit.org/wit/gui @@ -21,7 +21,7 @@ new-build: # to build the old way build: - GO111MODULE="off" go install -ldflags " \ + GO111MODULE="off" go build -v -ldflags " \ -X main.GITCOMMIT=${GITCOMMIT} \ -X main.GOVERSION='${GOVERSION}' \ -X main.BUILDTIME='${BUILDTIME}' \ diff --git a/apt.go b/apt.go index 62c87b9..85d28e5 100644 --- a/apt.go +++ b/apt.go @@ -2,13 +2,14 @@ package main import ( + "go.wit.com/log" "go.wit.com/gui/gui" ) -func aptGroup(tab *gui.Node) { - n := tab.AddGroup("apt Resets") +func aptGroup(box *gui.Node) { + n := box.NewGroup("apt Resets") - n.AddButton("update apt-file", func (*gui.Node) { + n.NewButton("update apt-file", func () { // shell.Script("apt -y install apt-file\napt-file update") // xterm("apt -y install apt-file; apt-file update") // gui.ErrorWindow("test error window", "this is the error") @@ -17,7 +18,7 @@ func aptGroup(tab *gui.Node) { return err }) if (err != nil) { - gui.ErrorWindow("Error", "Failed to run:\napt install moon-buggy") + log.Warn("Error", "Failed to run:\napt install moon-buggy") return } err = bash("bash -x /tmp/jcarr") @@ -25,28 +26,28 @@ func aptGroup(tab *gui.Node) { bash("apt-file update") }) - n.AddButton("install packages", func (*gui.Node) { - aptPackagesWindow(nil) + n.NewButton("install packages", func () { + aptPackagesWindow() }) - n.AddButton("install base packages", func (*gui.Node) { + n.NewButton("install base packages", func () { sudo( func() error { line := "apt install moon-buggy2" err := bash(line) if (err != nil) { - gui.ErrorWindow("Error", "Failed to run:\n" + line) + log.Error(err, "Error", "Failed to run:\n" + line) return err } return nil }) }) - n.AddButton("purge rc-only", func (*gui.Node) { + n.NewButton("purge rc-only", func () { xterm("dpkg -l |grep ^rc | awk '{print $2}' |xargs apt remove --purge -y") }) - n.AddButton("install defaults", func (*gui.Node) { + n.NewButton("install defaults", func () { xterm("./resources/bin/setup-packages-default") }) - n.AddButton("install kvm", func (*gui.Node) { + n.NewButton("install kvm", func () { xterm("./resources/bin/setup-packages-kvm") }) diff --git a/gui-button.go b/gui-button.go index 658cd85..6e06b3d 100644 --- a/gui-button.go +++ b/gui-button.go @@ -40,7 +40,7 @@ func newMmakeButtonValues(name string, custom func(*gui.Node)) *myButtonInfo { } func makeXtermButton(n *gui.Node, name string, action string, custom string) *gui.Node { - n.AddButton(name, func (*gui.Node) { + n.NewButton(name, func () { log.Println("xterm cmd=", custom) xterm(custom) }) diff --git a/main.go b/main.go index 9d02d85..3d58930 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,12 @@ package main import ( - "log" "os" "time" + "go.wit.com/log" "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" "github.com/gobuffalo/packr" ) @@ -29,7 +30,9 @@ var debugTest bool = false // var xterm = []string{"nohup", "xterm", "-geometry", geom} var useFirefox bool = true var firefox = []string{"firefox", "--new-window"} -var packrBox packr.Box +var packrBox *packr.Box + +var myGui *gui.Node func customExit(n *gui.Node) { log.Println("Should Exit Here") @@ -61,38 +64,23 @@ func main() { // runs the GO profiler in a goroutine go pprofMain() - go gui.Main(initGUI) + myGui = gui.New().Default() + + log.Warn("Starting window") + gadgets.NewBasicWindow(myGui, "Debian SID Mate Control Panel " + VERSION) + + tabResets() + windowAddWWW() + golangDebug() time.Sleep(2 * time.Second) - gui.Queue(delayedTabs) + delayedTabs() go systrayMain() watchWindows() } -// only os.Exit() on close of the main Window -// TODO: Change to only exit from systray(?) -func initGUI() { - g := &gui.GuiConfig{ - Exit: customExit, - Stretchy: false, - } - log.Println("g =", g) - gui.Config.Exit = customExit - gui.Config.Stretchy = false - mainWindow(nil) - gui.Config.Exit = nil -} - func delayedTabs() { log.Println("delayedTabs() could have added a tab here\n") // jcarrWindow.AddTab("delayed tab", nil) } - -func normalWindowClose(n *gui.Node) { - log.Println("TODO: close this window correctly and empty the node") - n.Dump() - name := n.Name - // TODO: this is probably some sort of terrible and wrong memory leak - delete(gui.Data.NodeMap, name) -} diff --git a/os.go b/os.go index edb39ee..fdc3395 100644 --- a/os.go +++ b/os.go @@ -1,15 +1,17 @@ package main -import "log" -import "strings" -import "os" -import "os/exec" -import "io/ioutil" -import "errors" -import "bufio" +import ( + "strings" + "os" + "os/exec" + "io/ioutil" + "errors" + "bufio" -import "go.wit.com/gui/gui" -import "github.com/davecgh/go-spew/spew" + "go.wit.com/log" +// "go.wit.com/gui/gui" + "github.com/davecgh/go-spew/spew" +) func runSimpleCommand(s string) { cmd := strings.TrimSpace(s) // this is like 'chomp' in perl @@ -128,7 +130,7 @@ func sudo(f func() error) error { e := "You must be root to do this." log.Println(e, "uid =", uid) if (uid != 0) { - gui.ErrorWindow("Permissions Failed", e) + log.Warn("Permissions Failed", e) return errors.New("not root") } err := f() diff --git a/systray.go b/systray.go index 9b1d73a..6309fe8 100644 --- a/systray.go +++ b/systray.go @@ -1,15 +1,19 @@ package main -import "fmt" -import "os" -import "io/ioutil" -import "log" -import "time" +import ( + "fmt" + "os" + "io/ioutil" + "log" + "time" -import "go.wit.com/gui/gui" -import "github.com/davecgh/go-spew/spew" -import "github.com/getlantern/systray" -// "github.com/skratchdot/open-golang/open" +// "go.wit.com/gui/gui" + "go.wit.com/gui/debugger" + "github.com/davecgh/go-spew/spew" + "github.com/getlantern/systray" + + // "github.com/skratchdot/open-golang/open" +) func systrayMain() { onExit := func() { @@ -45,7 +49,6 @@ func onReady() { }() */ - var c = 0 // We can manipulate the systray in other goroutines go func() { systray.SetIcon(myIcon) @@ -91,16 +94,11 @@ func onReady() { log.Println("CHECKED END") case <-mDump.ClickedCh: log.Println("START") - gui.Config.Width = 800 - gui.Config.Height = 300 - gui.Queue(gui.DebugWindow) + debugger.DebugWindow(myGui) log.Println("END") case <-mShow.ClickedCh: log.Println("START Show()") - gui.Config.Width = 640 + c*20 - c = c + 1 - gui.Config.Height = 480 - gui.Queue(gui.DebugWindow) + debugger.DebugWindow(myGui) log.Println("END") case <-mHide.ClickedCh: log.Println("START Hide()") diff --git a/window-debug-golang.go b/window-debug-golang.go index 8fdf19f..095af31 100644 --- a/window-debug-golang.go +++ b/window-debug-golang.go @@ -2,66 +2,66 @@ package main import ( // "bufio" - "log" "os" "runtime" "runtime/debug" "runtime/pprof" + + "go.wit.com/log" +// "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" ) -import "go.wit.com/gui/gui" -func golangDebug(w *gui.Node) { - gui.Config.Stretchy = false - if (w == nil) { - gui.Config.Title = "golangDebug Window" - gui.Config.Width = 100 - gui.Config.Height = 100 - w = gui.NewWindow() +var langWin *gadgets.BasicWindow + +func golangDebug() { + if langWin != nil { + langWin.Toggle() + return } - - tab := w.AddTab("golangDebug()", nil) + langWin = gadgets.NewBasicWindow(myGui, "golangDebug") /////////////////////////////// Column DEBUG GOLANG ////////////////////// - gNode := tab.AddGroup("golang") + gNode := langWin.Box().NewGroup("golang") - gNode.AddButton("runtime.Stack() dump", func (*gui.Node) { + gNode.NewButton("runtime.Stack() dump", func () { log.Println("\tSTART") buf := make([]byte, 1<<16) runtime.Stack(buf, true) log.Printf("%s", buf) log.Println("\tEND") }) - gNode.AddButton("dumpModuleInfo", func (*gui.Node) { + gNode.NewButton("dumpModuleInfo", func () { log.Println("\tSTART") dumpModuleInfo() log.Println("\tEND") }) - gNode.AddButton("debug.PrintStack", func (*gui.Node) { + gNode.NewButton("debug.PrintStack", func () { log.Println("\tSTART") debug.PrintStack() log.Println("\tEND") }) - gNode.AddButton("pprof.Lookup goroutine", func (*gui.Node) { + gNode.NewButton("pprof.Lookup goroutine", func () { log.Println("\tSTART") pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) log.Println("\tEND") }) - gNode.AddButton("pprof.Lookup", func (*gui.Node) { + gNode.NewButton("pprof.Lookup", func () { log.Println("\tSTART") pprof.Lookup("heap").WriteTo(os.Stdout, 1) log.Println("\tEND") }) - gNode.AddButton("pprof.Lookup block", func (*gui.Node) { + gNode.NewButton("pprof.Lookup block", func () { log.Println("\tSTART") pprof.Lookup("block").WriteTo(os.Stdout, 1) log.Println("\tEND") }) - gNode.AddButton("pprof.Lookup threadcreate", func (*gui.Node) { + gNode.NewButton("pprof.Lookup threadcreate", func () { log.Println("\tSTART") pprof.Lookup("threadcreate").WriteTo(os.Stdout, 1) log.Println("\tEND") }) - gNode.AddButton("runtime.ReadMemStats", func (*gui.Node) { + gNode.NewButton("runtime.ReadMemStats", func () { var s runtime.MemStats runtime.ReadMemStats(&s) log.Printf("alloc: %v bytes\n", s.Alloc) diff --git a/window-dns-update.go b/window-dns-update.go index c41838c..3fc6df4 100644 --- a/window-dns-update.go +++ b/window-dns-update.go @@ -1,36 +1,33 @@ package main -// import "os" -// import "log" -// import "strconv" -// import "io/ioutil" -// import "bufio" -import "go.wit.com/gui/gui" +import ( + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) + +var upDNSwin *gadgets.BasicWindow func updateDNS(w *gui.Node) { - if (w == nil) { - gui.Config.Title = "dns update Window" - gui.Config.Width = 110 - gui.Config.Height = 110 - w = gui.NewWindow() + if (upDNSwin != nil) { + upDNSwin.Toggle() + return } - tab := w.AddTab("updateDNS()", nil) - // populateNEW(tab, "new") + upDNSwin = gadgets.NewBasicWindow(w, "dns update Window") ////////////// filename ///////////////////////// - gNode := tab.AddGroup("eth0 update") + gNode := upDNSwin.Box().NewGroup("eth0 update") // fontsize := "16" - dnsNode := gNode.AddComboBox("8", - "16", - "24") - + dnsNode := gNode.NewCombobox("size") + dnsNode.AddText("8") + dnsNode.AddText("16") + dnsNode.AddText("24") dnsNode.SetText("12") ////////////// connect ///////////////////////// - gNode = tab.AddGroup("Update") + gNode = upDNSwin.Box().NewGroup("Update") - gNode.AddButton("setup .Xresources", func (*gui.Node) { + gNode.NewButton("setup .Xresources", func () { }) } diff --git a/window-main.go b/window-main.go deleted file mode 100644 index 96adaba..0000000 --- a/window-main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - // "log" - - "go.wit.com/gui/gui" -) - -func mainWindow(w *gui.Node) *gui.Node { - if w == nil { - gui.Config.Title = "Debian SID Mate Control Panel " + VERSION - gui.Config.Width = 101 - gui.Config.Height = 101 - w = gui.NewWindow() - } - - // newTab := w.AddTab("Main Tab", nil) - - tabResets(w) - - windowAddWWW(w) - - golangDebug(w) - - return w -} diff --git a/window-packages.go b/window-packages.go index 53de6d2..a61de79 100644 --- a/window-packages.go +++ b/window-packages.go @@ -8,28 +8,26 @@ import ( "strings" "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" ) -func aptPackagesWindow(w *gui.Node) { +var aptWin *gadgets.BasicWindow + +func aptPackagesWindow() { var aptoutput *gui.Node var aptNode *gui.Node var filename string - if w == nil { - gui.Config.Title = "apt configuration and package installer" - gui.Config.Width = 1600 - gui.Config.Height = 800 - gui.Config.Exit = nil - w = gui.NewWindow() + if aptWin != nil { + aptWin.Toggle() + return } - - tab := w.AddTab("apt", nil) - // populateNEW(tab, "new") + aptWin = gadgets.NewBasicWindow(myGui, "apt configuration and package installer") ////////////// filename ///////////////////////// - gNode := tab.AddGroup("Options") + gNode := aptWin.Box().NewGroup("Options") - gNode.AddButton("default packages", func(*gui.Node) { + gNode.NewButton("default packages", func() { log.Println("STARTED HOSTNAME") aptNode.SetText("bin/install-default-packages.sh") filename = "bin/install-default-packages.sh" @@ -40,9 +38,9 @@ func aptPackagesWindow(w *gui.Node) { log.Println("ENDED GetText() HOSTNAME =", filename) }) - gNode.CreateFontButton("fonts") + // gNode.CreateFontButton("fonts") - gNode.AddButton("Configure apt-file", func(*gui.Node) { + gNode.NewButton("Configure apt-file", func() { log.Println("STARTED HOSTNAME") aptNode.SetText("bin/apt-file.sh") filename = "bin/apt-file.sh" @@ -62,10 +60,13 @@ func aptPackagesWindow(w *gui.Node) { } // panic("junk") - aptNode = gNode.AddComboBox("test", tmp...) + aptNode = gNode.NewCombobox("test") + for _, thing := range tmp { + aptNode.AddText(thing) + } aptNode.SetText(filename) - aptNode.OnChanged = func() { + aptNode.Custom = func() { log.Println("STARTED HOSTNAME") filename = aptNode.GetText() b, _ := packrBox.FindString(filename) @@ -76,9 +77,9 @@ func aptPackagesWindow(w *gui.Node) { } ////////////// connect ///////////////////////// - gNode = tab.AddGroup("") + gNode = aptWin.Box().NewGroup("") - gNode.AddButton("Run Script", func(*gui.Node) { + gNode.NewButton("Run Script", func() { sudo(func() error { log.Println("set resolv.conf to", filename) b, _ := packrBox.FindString(filename) @@ -100,15 +101,15 @@ func aptPackagesWindow(w *gui.Node) { }) }) - gui.Config.Stretchy = true - gNode.AddButton("set output", func(*gui.Node) { + // gui.Config.Stretchy = true + gNode.NewButton("set output", func() { if aptoutput != nil { aptoutput.SetText("wow") - aptoutput.SetMargined(false) + aptoutput.Margin() } }) - gNode = tab.AddGroup("") - aptoutput = gNode.MakeGroupEdit("script:") - gui.Config.Stretchy = false + gNode = aptWin.Box().NewGroup("") + // aptoutput = gNode.MakeGroupEdit("script:") + // gui.Config.Stretchy = false } diff --git a/window-resets.go b/window-resets.go index 845563b..a989a2f 100644 --- a/window-resets.go +++ b/window-resets.go @@ -1,66 +1,61 @@ package main import ( - "log" - - "go.wit.com/gui/gui" + "go.wit.com/log" + "go.wit.com/gui/gadgets" ) -func tabResets(w *gui.Node) *gui.Node { - if w == nil { - gui.Config.Title = "resets window" - gui.Config.Width = 240 - gui.Config.Height = 280 - gui.Config.Exit = customExit - w = gui.NewWindow() - } +var tabWin *gadgets.BasicWindow - newTab := w.AddTab("tabResets()", nil) +func tabResets() { + if tabWin != nil { + tabWin.Toggle() + return + } + tabWin = gadgets.NewBasicWindow(myGui, "resets window") ///////////////////////////////////////////////////////////////////////////// - g1 := newTab.AddGroup("") + g1 := tabWin.Box().NewGroup("") g1.NewLabel("Working Stuff") - g1.AddButton("Configure resolv.conf", func(*gui.Node) { + g1.NewButton("Configure resolv.conf", func() { log.Println("supposed to make the resolv.conf window") - resolvWindow(nil) + resolvWindow() }) - g1.AddButton("Generic SSH Window", func(*gui.Node) { - sshGenericWindow(nil) + g1.NewButton("Generic SSH Window", func() { + sshGenericWindow() }) - g1.AddButton("Configure xterm", func(*gui.Node) { + g1.NewButton("Configure xterm", func() { xtermSettings(nil) }) - g1.AddButton("update DNS (IPv6)", func(*gui.Node) { + g1.NewButton("update DNS (IPv6)", func() { updateDNS(nil) }) - aptGroup(newTab) + aptGroup(tabWin.Box()) // 'stretchy' doesn't work here. this is because it was set on the hbox(?) // TODO: tear down all the gui elements and recreate them from the node tree - gui.Config.Stretchy = true - newTab.MakeBasicControlsPage("testing stuff") - gui.Config.Stretchy = false + // tabWin.Box().MakeBasicControlsPage("testing stuff") ///////////////////////////////////////////////////////////////////////////// - gn := newTab.AddGroup("GO") - gn.AddButton("go install golang.org/x/tools/gopls@latest", func(*gui.Node) { + gn := tabWin.Box().NewGroup("GO") + gn.NewButton("go install golang.org/x/tools/gopls@latest", func() { xterm("go install golang.org/x/tools/gopls@latest") }) - g := newTab.AddGroup("VIM") - g.AddButton("vim-go clone", func(*gui.Node) { + g := tabWin.Box().NewGroup("VIM") + g.NewButton("vim-go clone", func() { xterm("git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go") }) - g.AddButton("vim-go vimrc settings", func(*gui.Node) { + g.NewButton("vim-go vimrc settings", func() { log.Println("echo", "let g:go_def_mode='gopls'\nlet g:go_info_mode='gopls'") // xterm("echo", "let g:go_def_mode='gopls'\nlet g:go_info_mode='gopls'") }) - return newTab + return } diff --git a/window-resolv.go b/window-resolv.go index 9d015a7..380f38d 100644 --- a/window-resolv.go +++ b/window-resolv.go @@ -1,29 +1,30 @@ package main -import "log" -import "os" -import "bufio" -import "strings" -import "errors" -import "go.wit.com/gui/gui" +import ( + "os" + "bufio" + "strings" + "errors" + + "go.wit.com/log" + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) var filename string = "resolv-1-1-1-1.conf" var generaloutput *gui.Node -func resolvWindow(w *gui.Node) { - if (w == nil) { - gui.Config.Title = "resolv.conf Window" - gui.Config.Width = 1000 - gui.Config.Height = 400 - gui.Config.Exit = nil - w = gui.NewWindow() - } +var resWin *gadgets.BasicWindow - tab := w.AddTab("resolv.conf Tab", nil) - // populateNEW(tab, "new") +func resolvWindow() { + if (resWin != nil) { + resWin.Toggle() + return + } + resWin = gadgets.NewBasicWindow(myGui,"resolv.conf Window") ////////////// filename ///////////////////////// - gNode := tab.AddGroup("filename") + gNode := resWin.Box().NewGroup("filename") var tmp []string for i, s := range packrBox.List() { @@ -34,10 +35,13 @@ func resolvWindow(w *gui.Node) { } // panic("junk") - resolvNode := gNode.AddComboBox("test", tmp...) + resolvNode := gNode.NewCombobox("test") + for _, thing := range tmp { + resolvNode.AddText(thing) + } resolvNode.SetText(filename) - resolvNode.OnChanged = func () { + resolvNode.Custom = func () { log.Println("STARTED HOSTNAME") filename = resolvNode.GetText() b, _ := packrBox.FindString(filename) @@ -48,9 +52,9 @@ func resolvWindow(w *gui.Node) { } ////////////// connect ///////////////////////// - gNode = tab.AddGroup("") + gNode = resWin.Box().NewGroup("") - gNode.AddButton("Update /etc/resolv.conf", func (*gui.Node) { + gNode.NewButton("Update /etc/resolv.conf", func () { sudo( func() error { log.Println("set resolv.conf to",filename) b, _ := packrBox.FindString(filename) @@ -71,24 +75,23 @@ func resolvWindow(w *gui.Node) { return nil }) }) - gNode.AddButton("test ping ipv4", func (*gui.Node) { + gNode.NewButton("test ping ipv4", func () { bash("ping -c 3 -4 google.com") }) - gNode.AddButton("test ping ipv6", func (*gui.Node) { + gNode.NewButton("test ping ipv6", func () { bash("ping -c 3 -6 google.com") }) - gui.Config.Stretchy = true - gNode.AddButton("set output", func (*gui.Node) { + gNode.NewButton("set output", func () { if (generaloutput != nil) { generaloutput.SetText("wow") - generaloutput.SetMargined(false) + generaloutput.Margin() } }) - gui.Config.Stretchy = false - gui.Config.Stretchy = true - gNode = tab.AddGroup("Update") - generaloutput = gNode.MakeGroupEdit("resolv.conf:") - gui.Config.Stretchy = false + gNode = resWin.Box().NewGroup("Update") + gNode.NewButton("MakeGroupEdit()", func () { + log.Warn("recreate a gadget for editing the resolv.conf") + //generaloutput = gNode.MakeGroupEdit("resolv.conf:") + }) } diff --git a/window-ssh-generic.go b/window-ssh-generic.go index f63a71e..1ef0b65 100644 --- a/window-ssh-generic.go +++ b/window-ssh-generic.go @@ -1,33 +1,32 @@ package main -import "log" -import "os/user" -// import "reflect" -import "go.wit.com/gui/gui" +import ( + "os/user" + + "go.wit.com/log" + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) var userNode *gui.Node +var sshWin *gadgets.BasicWindow -func sshGenericWindow(w *gui.Node) { - if (w == nil) { - gui.Config.Title = "sshWindow" - gui.Config.Width = 101 - gui.Config.Height = 131 - gui.Config.Exit = customExit - w = gui.NewWindow() +func sshGenericWindow() { + if (sshWin != nil) { + sshWin.Toggle() + return } - - tab := w.AddTab("sshWindow()", nil) - // populateNEW(tab, "new") + sshWin = gadgets.NewBasicWindow(myGui, "sshWindow") ////////////// username ///////////////////////// - gNode := tab.AddGroup("username") + gNode := sshWin.Box().NewGroup("username") - userNode = gNode.AddComboBox("username", - "root", - "jcarr", - "hugo") + userNode = gNode.NewCombobox("username") + userNode.AddText("root") + userNode.AddText("jcarr") + userNode.AddText("hugo") - userNode.OnChanged = func () { + userNode.Custom = func () { username = userNode.GetText() log.Println("SETTING: username=", username) userNode.Dump() @@ -40,14 +39,14 @@ func sshGenericWindow(w *gui.Node) { // panic("blah") ////////////// hostname ///////////////////////// - gNode = tab.AddGroup("homename") + gNode = sshWin.Box().NewGroup("homename") - hostNode := gNode.AddComboBox("hostname", - "www", - "mirrors", - "git") + hostNode := gNode.NewCombobox("hostname") + hostNode.AddText("www") + hostNode.AddText("mirrors") + hostNode.AddText("git") - hostNode.OnChanged = func () { + hostNode.Custom = func () { log.Println("STARTED HOSTNAME") hostname = hostNode.GetText() log.Println("ENDED GetText() HOSTNAME") @@ -56,9 +55,9 @@ func sshGenericWindow(w *gui.Node) { hostNode.SetText("mirrors") ////////////// connect ///////////////////////// - gNode = tab.AddGroup("connect") + gNode = sshWin.Box().NewGroup("connect") - gNode.AddButton("connect", func (*gui.Node) { + gNode.NewButton("connect", func () { cmd := "ssh -v " + username + "@" + hostname log.Println("xterm cmd=", cmd) xterm(cmd) diff --git a/window-www.go b/window-www.go index b6d9cd7..b8e233b 100644 --- a/window-www.go +++ b/window-www.go @@ -1,20 +1,22 @@ package main -import "log" -import "go.wit.com/gui/gui" +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) -func windowAddWWW(w *gui.Node) { - if (w == nil) { - gui.Config.Title = "webpages" - gui.Config.Width = 102 - gui.Config.Height = 102 - w = gui.NewWindow() +var webWin *gadgets.BasicWindow + +func windowAddWWW() { + if (webWin != nil) { + webWin.Toggle() + return } - - tab := w.AddTab("http", nil) + webWin = gadgets.NewBasicWindow(myGui, "webpages") ////////////// connect ///////////////////////// - gNode := tab.AddGroup("www") + gNode := webWin.Box().NewGroup("www") firefoxButton(gNode, "git", "https://git.wit.org/") firefoxButton(gNode, "mirrors", "https://mirrors.wit.org/") firefoxButton(gNode, "IPv6-Only ping", "http://ping.wit.org/") @@ -23,7 +25,7 @@ func windowAddWWW(w *gui.Node) { } func firefoxButton (n *gui.Node, name string, url string) { - n.AddButton(name, func (*gui.Node) { + n.NewButton(name, func () { log.Println("button clicked: trying to open url") var tmp []string tmp = append(tmp, "nohup") diff --git a/window-xterm.go b/window-xterm.go index 5f53c10..bda9b54 100644 --- a/window-xterm.go +++ b/window-xterm.go @@ -1,37 +1,43 @@ package main -import "log" -// import "strconv" -import "io/ioutil" -import "go.wit.com/gui/gui" +import ( + "io/ioutil" + + "go.wit.com/log" + "go.wit.com/gui/gui" + "go.wit.com/gui/gadgets" +) var fontNode *gui.Node var fontsize string = "" -func xtermSettings(w *gui.Node) { - if (w == nil) { - gui.Config.Title = "Configure xterm" - gui.Config.Width = 105 - gui.Config.Height = 105 - gui.Config.Exit = normalWindowClose - w = gui.NewWindow() - } +var xtermWin *gadgets.BasicWindow - tab := w.AddTab("xtermSettings()", nil) +func xtermSettings(w *gui.Node) { + if (xtermWin != nil) { + xtermWin.Toggle() + return + } + xtermWin = gadgets.NewBasicWindow(myGui, "Configure xterm") // Select your fontsize - gNode := tab.AddGroup("fontsize") + gNode := xtermWin.Box().NewGroup("fontsize") fontsize = "16" - fontNode = gNode.AddComboBox("fontsize", "8", "12", "16", "24", "32") - fontNode.OnChanged = func () { + fontNode = gNode.NewCombobox("fontsize") + fontNode.AddText("8") + fontNode.AddText("12") + fontNode.AddText("16") + fontNode.AddText("24") + fontNode.AddText("32") + fontNode.Custom = func () { fontsize = fontNode.GetText() } fontNode.SetText(fontsize) ////////////// connect ///////////////////////// - gNode = tab.AddGroup("Update") + gNode = xtermWin.Box().NewGroup("Update") - gNode.AddButton("setup .Xresources", func (*gui.Node) { + gNode.NewButton("setup .Xresources", func () { log.Println("fontsize =", fontsize) // write out .Xresources file @@ -46,12 +52,12 @@ func xtermSettings(w *gui.Node) { log.Println("button click end") }) - gNode.AddButton("test xterm", func (*gui.Node) { + gNode.NewButton("test xterm", func () { cmd := "xterm" xterm(cmd) }) - gNode.AddButton("fontNode.GetText()", func (*gui.Node) { + gNode.NewButton("fontNode.GetText()", func () { if (fontNode != nil) { fontsize = fontNode.GetText() log.Println("set fontsize =", fontsize)