convert to pb grid

This commit is contained in:
Jeff Carr 2025-02-22 13:40:30 -06:00
parent e9f7b99846
commit 49d2653fd4
3 changed files with 192 additions and 81 deletions

143
doGui.go
View File

@ -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
})
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)
})
if tbwin.Hidden() {
tbwin.Show()
} else {
tbwin.Hide()
var test2 *genericWindow
grid.NewButton("test2", func() {
if test2 != nil {
test2.Toggle()
return
}
return
test2 = makeMachineWindow(me.machines)
})
grid.NewButton("update table", func() {
newwin := makeTableWindow()
newwin.showTable(me.machines)
newwin.Show()
})
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))
/*
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.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()
})
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
}

View File

@ -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()
}
}
*/

92
windowGeneric.go Normal file
View File

@ -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
}