protobuf update works

This commit is contained in:
Jeff Carr 2025-03-05 07:46:05 -06:00
parent 46f69bee21
commit a57b2875af
3 changed files with 88 additions and 154 deletions

View File

@ -6,7 +6,6 @@ package main
// An app to submit patches for the 30 GO GUI repos
import (
"fmt"
"os"
"time"
@ -28,22 +27,14 @@ func doGui() {
me.myGui.InitEmbed(resources)
me.myGui.Default()
mainWindow := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
mainWindow.Make()
mainWindow.Show()
mainWindow.Custom = func() {
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
win.Make()
win.Show()
win.Custom = func() {
log.Warn("Main window close")
os.Exit(0)
}
drawWindow(mainWindow)
// sits here forever
debug()
}
func drawWindow(win *gadgets.BasicWindow) {
box := win.Box()
vbox := box.NewVerticalBox("BOX2")
@ -51,23 +42,10 @@ func drawWindow(win *gadgets.BasicWindow) {
group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0)
var testWin *genericWindow
grid.NewButton("machine list", func() {
if testWin != nil {
testWin.Toggle()
return
}
testWin = makeMachineWindow(me.machines)
})
addButtonForZooPB(grid)
var test2 *genericWindow
grid.NewButton("test2", func() {
if test2 != nil {
test2.Toggle()
return
}
test2 = makeMachineWindow(me.machines)
})
// sits here forever
debug()
}
func findVersion(m *zoopb.Machine, pkgname string) string {
@ -77,36 +55,3 @@ 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

@ -1,92 +0,0 @@
// 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
}

81
windowZooPB.go Normal file
View File

@ -0,0 +1,81 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"fmt"
"time"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
func addButtonForZooPB(grid *gui.Node) (*gui.Node, *gadgets.GenericWindow) {
var win *gadgets.GenericWindow
b := grid.NewButton("show zoo", func() {
// if the window exists, just toggle it open or closed
if win != nil {
win.Toggle()
return
}
win = gadgets.NewGenericWindow("Zoo Raw PB View", "Stuff")
win.Win.Custom = func() {
log.Info("test delete window here")
}
tbox := win.Bottom.Box().SetProgName("TBOX")
grid := win.Group.RawGrid()
var t *zoopb.MachinesTable
grid.NewButton("Show", func() {
if t != nil {
t.Delete()
t = nil
}
// display the protobuf
t = AddMachinesPB(tbox, me.machines)
log.Info("table has uuid", t.GetUuid())
})
grid.NewButton("update", func() {
if t != nil {
t.Delete()
t = nil
}
t = AddMachinesPB(tbox, me.machines)
log.Info("table has uuid", t.GetUuid())
})
})
return b, win
}
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t := pb.NewTable("MachinesPB")
t.NewUuid()
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()
})
f := func(m *zoopb.Machine) string {
log.Info("machine =", m.Hostname)
return m.Hostname
}
t.AddButtonFunc("upgrade", f)
t.ShowTable()
return t
}