cleaner window code

This commit is contained in:
Jeff Carr 2025-03-06 04:36:07 -06:00
parent f97e2a48c6
commit 8edebe18e1
4 changed files with 83 additions and 34 deletions

View File

@ -15,8 +15,9 @@ import (
var argv args var argv args
type args struct { type args struct {
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
Port int `arg:"--port" default:"8080" help:"port to run on"` Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
Port int `arg:"--port" default:"8080" help:"port to run on"`
} }
func (args) Version() string { func (args) Version() string {

View File

@ -11,17 +11,17 @@ import (
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
func debug() { // refresh the windows & tables the user has open
for { func refresh() {
time.Sleep(90 * time.Second) time.Sleep(90 * time.Second)
log.Info("TODO: zookeeper scan here. repo count =") if argv.Verbose {
if me.machinesWin != nil { log.Info("zookeeper scan here")
doMachinesUpgradeTable() }
} if me.zood != nil {
doMachinesUpgradeTable()
} }
} }
@ -45,29 +45,22 @@ func doGui() {
group1 := vbox.NewGroup("Zookeeper Settings") group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0) grid := group1.NewGrid("buildOptions", 0, 0)
grid.NewButton("show zoo", func() { grid.NewButton("zood versions", func() {
// if the window exists, just toggle it open or closed // if the window exists, just toggle it open or closed
if me.machinesWin != nil { if me.zood != nil {
me.machinesWin.Toggle() me.zood.Toggle()
return return
} }
makeZoodWin()
me.machinesWin = gadgets.NewGenericWindow("Zoo Machines", "Stuff") })
me.machinesWin.Win.Custom = func() { grid.NewButton("update zood versions", func() {
log.Info("test delete window here") if me.zood != nil {
doMachinesUpgradeTable()
} }
me.machinesBox = me.machinesWin.Bottom.Box().SetProgName("TBOX")
doMachinesUpgradeTable()
}) })
// sits here forever // sit here forever refreshing the GUI
debug() for {
} refresh()
func findVersion(m *zoopb.Machine, pkgname string) string {
zood := m.Packages.FindByName(pkgname)
if zood == nil {
return "n/a"
} }
return zood.Version
} }

View File

@ -29,4 +29,22 @@ type zookeep struct {
machinesWin *gadgets.GenericWindow // the machines gui window machinesWin *gadgets.GenericWindow // the machines gui window
machinesBox *gui.Node // the machines gui parent box widget machinesBox *gui.Node // the machines gui parent box widget
machinesTB *zoopb.MachinesTable // the machines gui table buffer machinesTB *zoopb.MachinesTable // the machines gui table buffer
zood *stdTableWin // the zood version window
}
type stdTableWin struct {
win *gadgets.GenericWindow // the machines gui window
box *gui.Node // the machines gui parent box widget
TB *zoopb.MachinesTable // the machines gui table buffer
update bool // if the window should be updated
}
func (w *stdTableWin) Toggle() {
if w == nil {
return
}
if w.win == nil {
return
}
w.win.Toggle()
} }

View File

@ -8,25 +8,40 @@ import (
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
func makeZoodWin() {
me.zood = new(stdTableWin)
me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
me.zood.win.Custom = func() {
log.Info("test delete window here")
}
group := me.zood.win.Group
group.NewButton("save machines.pb", func() {
saveMachineState()
})
me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX")
doMachinesUpgradeTable()
}
func doMachinesUpgradeTable() { func doMachinesUpgradeTable() {
if me.machinesTB != nil { if me.zood.TB != nil {
me.machinesTB.Delete() me.zood.TB.Delete()
me.machinesTB = nil me.zood.TB = nil
} }
// display the protobuf // display the protobuf
me.machinesTB = AddMachinesPB(me.machinesBox, me.machines) me.zood.TB = AddMachinesPB(me.zood.box, me.machines)
f := func(m *zoopb.Machine) { f := func(m *zoopb.Machine) {
log.Info("upgrade machine", m.Hostname, "memory", m.Memory/(1024*1024*1024)) log.Info("upgrade machine", m.Hostname, "memory", m.Memory/(1024*1024*1024))
log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE") log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE")
log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE") log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE")
} }
me.machinesTB.Custom(f) me.zood.TB.Custom(f)
log.Info("table has uuid", me.machinesTB.GetUuid()) log.Info("table has uuid", me.zood.TB.GetUuid())
} }
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
@ -40,9 +55,11 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t.AddStringFunc("sMB", func(m *zoopb.Machine) string { t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
return fmt.Sprintf("%d mb", m.Memory/(1024*1024)) return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
}) })
t.AddStringFunc("zood", func(m *zoopb.Machine) string { t.AddStringFunc("zood", func(m *zoopb.Machine) string {
return findVersion(m, "zood") return findVersion(m, "zood")
}) })
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time { t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
return m.Laststamp.AsTime() return m.Laststamp.AsTime()
}) })
@ -55,3 +72,23 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t.ShowTable() t.ShowTable()
return t return t
} }
func findVersion(m *zoopb.Machine, pkgname string) string {
zood := m.Packages.FindByName(pkgname)
if zood == nil {
return "n/a"
}
return zood.Version
}
func saveMachineState() {
now := zoopb.NewMachines()
all := me.machines.SortByHostname()
for all.Scan() {
m := all.Next()
log.Info("have machine:", m.Hostname)
now.Append(m)
}
// me.machines.ConfigSave()
}