summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-22 13:40:30 -0600
committerJeff Carr <[email protected]>2025-02-22 13:50:27 -0600
commit49d2653fd41b1d3caa54950892a3a6d11a5abfff (patch)
tree4f1f4bcb25dc650b640334b36ef241b927525ce0
parente9f7b99846f6afa0ccdf0f026476b367dc7cfcec (diff)
convert to pb grid
-rw-r--r--doGui.go141
-rw-r--r--tableWindow.go38
-rw-r--r--windowGeneric.go92
3 files changed, 191 insertions, 80 deletions
diff --git a/doGui.go b/doGui.go
index e500b04..2ccd9a1 100644
--- a/doGui.go
+++ b/doGui.go
@@ -51,60 +51,83 @@ func drawWindow(win *gadgets.BasicWindow) {
group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0)
- var tbwin *tableWindow
- grid.NewButton("show zoo", func() {
- win.Disable()
- defer win.Enable()
+ /*
+ var tbwin *tableWindow
+ grid.NewButton("show zoo", func() {
+ win.Disable()
+ defer win.Enable()
- if tbwin == nil {
- log.Info("show zoo here")
- tbwin = makeTableWindow()
- tbwin.showTable(me.machines)
- }
+ if tbwin == nil {
+ log.Info("show zoo here")
+ tbwin = makeTableWindow()
+ tbwin.showTable(me.machines)
+ }
- if tbwin.Hidden() {
- tbwin.Show()
- } else {
- tbwin.Hide()
- }
- return
+ if tbwin.Hidden() {
+ tbwin.Show()
+ } else {
+ tbwin.Hide()
+ }
+ return
+
+ })
+
+ grid.NewButton("update table", func() {
+ newwin := makeTableWindow()
+ newwin.showTable(me.machines)
+ newwin.Show()
+ })
+ */
+ var testWin *genericWindow
+ grid.NewButton("machine list", func() {
+ if testWin != nil {
+ testWin.Toggle()
+ return
+ }
+ testWin = makeMachineWindow(me.machines)
})
- grid.NewButton("update table", func() {
- newwin := makeTableWindow()
- newwin.showTable(me.machines)
- newwin.Show()
+ var test2 *genericWindow
+ grid.NewButton("test2", func() {
+ if test2 != nil {
+ test2.Toggle()
+ return
+ }
+ test2 = makeMachineWindow(me.machines)
})
- grid.NewButton("me.machines.ShowTable()", func() {
- t := me.machines.NewTable("test 2")
- t.AddHostname()
- t.AddMemory()
- t.AddCpus()
- t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
- return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
- })
- t.AddStringFunc("zood", func(m *zoopb.Machine) string {
- return findVersion(m, "zood")
+ /*
+ grid.NewButton("me.machines.ShowTable()", func() {
+ t := me.machines.NewTable("test 2")
+ t.AddHostname()
+ t.AddMemory()
+ t.AddCpus()
+ t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
+ return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
+ })
+ t.AddStringFunc("zood", func(m *zoopb.Machine) string {
+ return findVersion(m, "zood")
+ })
+ t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
+ return m.Laststamp.AsTime()
+ })
+ t.ShowTable()
})
- t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
- return m.Laststamp.AsTime()
- })
- t.ShowTable()
- })
- grid.NewButton("ConfigSave(me.machines)", func() {
- log.Info("saving config...")
- me.machines.ConfigSave()
- })
+ grid.NewButton("ConfigSave(me.machines)", func() {
+ log.Info("saving config...")
+ me.machines.ConfigSave()
+ })
- grid.NewButton("ConfigSave(me.machines2)", func() {
- log.Info("saving config...")
- me.machines2.ConfigSave()
- })
+ grid.NewButton("ConfigSave(me.machines2)", func() {
+ log.Info("saving config...")
+ me.machines2.ConfigSave()
+ })
+ */
}
+/*
func (tw *tableWindow) showTable(allm *zoopb.Machines) {
all := allm.All()
for all.Scan() {
@@ -125,6 +148,7 @@ func (tw *tableWindow) showTable(allm *zoopb.Machines) {
tw.grid.NextRow()
}
}
+*/
func findVersion(m *zoopb.Machine, pkgname string) string {
zood := m.Packages.FindByName(pkgname)
@@ -133,3 +157,36 @@ func findVersion(m *zoopb.Machine, pkgname string) string {
}
return zood.Version
}
+
+func makeMachineWindow(pb *zoopb.Machines) *genericWindow {
+ win := initGenericWindow("Machines registered with Zookeeper", "Buttons of things")
+ grid := win.group.RawGrid()
+ grid.NewButton("List", func() {
+ log.Info("list...")
+ })
+ grid.NewButton("more", func() {
+ log.Info("?")
+ })
+ grid.NextRow()
+ grid.NewButton("smore", func() {
+ log.Info("smore")
+ })
+
+ tbox := win.win.Box().Vertical() // a vertical box (like a stack of books)
+ t := pb.NewTable("test 2")
+ t.SetParent(tbox)
+ t.AddHostname()
+ t.AddMemory()
+ t.AddCpus()
+ t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
+ return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
+ })
+ t.AddStringFunc("zood", func(m *zoopb.Machine) string {
+ return findVersion(m, "zood")
+ })
+ t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
+ return m.Laststamp.AsTime()
+ })
+ t.ShowTable()
+ return win
+}
diff --git a/tableWindow.go b/tableWindow.go
index 5d64bac..089a7dc 100644
--- a/tableWindow.go
+++ b/tableWindow.go
@@ -98,41 +98,3 @@ func makeTableWindow() *tableWindow {
// pw.addPatchset(grid, pset)
return pw
}
-
-/*
-func (r *tableWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
-
- all := pset.Patches.SortByFilename()
- for all.Scan() {
- p := all.Next()
- // for repo, patches := range repomap {
- rn := p.RepoNamespace
- repo := me.forge.FindByGoPath(rn)
- if repo == nil {
- log.Info("Could not figure out repo path", rn)
- rn += " bad repo"
- }
- log.Info("Adding patches for", rn)
- grid.NewLabel(rn)
-
- // hash := repohash[repo]
- grid.NewLabel(p.StartHash)
- grid.NewLabel(p.Filename)
-
- if repo == nil {
- continue
- }
- grid.NewButton("apply", func() {
- filename, _ := savePatch(p)
- if err := applyPatch(repo, filename); err != nil {
- log.Info("warn user of git am error", err)
- }
- })
- grid.NewCheckbox("").SetChecked(true)
- grid.NewCheckbox("").SetChecked(true)
- grid.NewButton("save patch to /tmp", func() {
- })
- grid.NextRow()
- }
-}
-*/
diff --git a/windowGeneric.go b/windowGeneric.go
new file mode 100644
index 0000000..7daae01
--- /dev/null
+++ b/windowGeneric.go
@@ -0,0 +1,92 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/log"
+
+ "go.wit.com/gui"
+)
+
+type genericWindow struct {
+ win *gadgets.BasicWindow // the window widget itself
+ box *gui.Node // the top box of the repolist window
+ group *gui.Node // the default group
+}
+
+func (r *genericWindow) Hidden() bool {
+ if r == nil {
+ return true
+ }
+ if r.win == nil {
+ return true
+ }
+ return r.win.Hidden()
+}
+
+func (r *genericWindow) Toggle() {
+ if r.Hidden() {
+ r.Show()
+ } else {
+ r.Hide()
+ }
+}
+
+func (r *genericWindow) Show() {
+ if r == nil {
+ return
+ }
+ if r.win == nil {
+ return
+ }
+ r.win.Show()
+}
+
+func (r *genericWindow) Hide() {
+ if r == nil {
+ return
+ }
+ if r.win == nil {
+ return
+ }
+ r.win.Hide()
+}
+
+func (r *genericWindow) Disable() {
+ if r == nil {
+ return
+ }
+ if r.box == nil {
+ return
+ }
+ r.box.Disable()
+}
+
+func (r *genericWindow) Enable() {
+ if r == nil {
+ return
+ }
+ if r.box == nil {
+ return
+ }
+ r.box.Enable()
+}
+
+func initGenericWindow(title string, grouptxt string) *genericWindow {
+ gw := new(genericWindow)
+ gw.win = gadgets.RawBasicWindow(title)
+ gw.win.Make()
+
+ gw.box = gw.win.Box().Vertical() // a vertical box (like a stack of books)
+ gw.win.Custom = func() {
+ log.Warn("Found Window close. setting hidden=true")
+ // sets the hidden flag to false so Toggle() works
+ gw.win.Hide()
+ }
+ gw.group = gw.box.NewGroup(grouptxt)
+ gw.Show()
+
+ return gw
+}