From 398d9fe3c44bdc8832fbf290beea7b6d13538f4b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 13:55:46 -0600 Subject: [PATCH] works in sierpinski carpet mode Signed-off-by: Jeff Carr --- gui.go | 18 ++++++++---------- linuxstatus/common.go | 31 +++++++++++++++++++------------ linuxstatus/hostname.go | 14 +++++++++++++- linuxstatus/linuxloop.go | 2 +- linuxstatus/update.go | 6 +++--- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gui.go b/gui.go index fbdc3fc..3f7fd10 100644 --- a/gui.go +++ b/gui.go @@ -228,22 +228,20 @@ func mainWindow(title string) { }) gr.NewButton("linuxstatus.New()", func () { me.statusOS = linuxstatus.New() - }) - gr.NewButton("SetParent()", func () { me.statusOS.SetParent(me.myGui) - }) - gr.NewButton("InitWindow()", func () { me.statusOS.InitWindow() }) - gr.NewButton("statusOS.Draw()", func () { - me.statusOS.Draw() - }) - gr.NewButton("statusOS.Draw2()", func () { - me.statusOS.Draw2() - }) gr.NewButton("statusOS.Ready()", func () { me.statusOS.Ready() }) + gr.NewButton("statusOS.Make()", func () { + me.statusOS.Make() + me.statusOS.Draw2() + }) + gr.NewButton("statusOS.Draw()", func () { + me.statusOS.Draw() + me.statusOS.Draw2() + }) gr.NewButton("statusOS.Update()", func () { me.statusOS.Update() }) diff --git a/linuxstatus/common.go b/linuxstatus/common.go index b568146..de4489e 100644 --- a/linuxstatus/common.go +++ b/linuxstatus/common.go @@ -6,10 +6,17 @@ import ( "go.wit.com/gui/gui" ) -func (ls *LinuxStatus) Draw() { - log.Log(CHANGE, "linuxStatus.Draw() window") +func (ls *LinuxStatus) Make() { + log.Log(CHANGE, "Draw() window") if ! ls.Ready() {return} - log.Log(CHANGE, "linuxStatus.Draw() window ready =", ls.ready) + log.Log(CHANGE, "Draw() window ready =", ls.ready) + ls.window.Make() + ls.ready = true +} +func (ls *LinuxStatus) Draw() { + log.Log(CHANGE, "Draw() window") + if ! ls.Ready() {return} + log.Log(CHANGE, "Draw() window ready =", ls.ready) ls.window.Draw() ls.ready = true } @@ -21,25 +28,25 @@ func (ls *LinuxStatus) Draw2() { } func (ls *LinuxStatus) Show() { - log.Log(CHANGE, "linuxStatus.Show() window") + log.Log(CHANGE, "Show() window") if ! ls.Ready() {return} - log.Log(CHANGE, "linuxStatus.Show() window ready =", ls.ready) + log.Log(CHANGE, "Show() window ready =", ls.ready) ls.window.Show() ls.hidden = false } func (ls *LinuxStatus) Hide() { - log.Log(CHANGE, "linuxStatus.Hide() window") + log.Log(CHANGE, "Hide() window") if ! ls.Ready() {return} - log.Log(CHANGE, "linuxStatus.Hide() window ready =", ls.ready) + log.Log(CHANGE, "Hide() window ready =", ls.ready) ls.window.Hide() ls.hidden = true } func (ls *LinuxStatus) Toggle() { - log.Log(CHANGE, "linuxStatus.Toggle() window") + log.Log(CHANGE, "Toggle() window") if ! ls.Ready() {return} - log.Log(CHANGE, "linuxStatus.Toggle() window ready =", ls.ready) + log.Log(CHANGE, "Toggle() window ready =", ls.ready) if ls.hidden { ls.Show() } else { @@ -48,7 +55,7 @@ func (ls *LinuxStatus) Toggle() { } func (ls *LinuxStatus) Ready() bool { - log.Log(CHANGE, "Ready() ls =", ls) + log.Log(CHANGE, "Ready()") if me == nil {return false} if ls == nil {return false} if ls.window == nil {return false} @@ -56,7 +63,7 @@ func (ls *LinuxStatus) Ready() bool { } func (ls *LinuxStatus) Initialized() bool { - log.Log(CHANGE, "checking Initialized() ls =", ls) + log.Log(CHANGE, "checking Initialized()") if me == nil {return false} if ls == nil {return false} if ls.parent == nil {return false} @@ -64,7 +71,7 @@ func (ls *LinuxStatus) Initialized() bool { } func (ls *LinuxStatus) SetParent(p *gui.Node) { - log.Log(CHANGE, "Attempting SetParent =", p) + log.Log(CHANGE, "Attempting SetParent") if me == nil {return} if ls == nil {return} if ls.parent == nil { diff --git a/linuxstatus/hostname.go b/linuxstatus/hostname.go index 50a5b27..6853ba6 100644 --- a/linuxstatus/hostname.go +++ b/linuxstatus/hostname.go @@ -14,6 +14,11 @@ import ( func (ls *LinuxStatus) GetDomainName() string { if ! me.Ready() {return ""} + if me.window == nil { + log.Log(NOW, "me.window == nil") + } else { + log.Log(NOW, "me.window exists, but has not been drawn") + } return me.domainname.Get() } @@ -22,7 +27,8 @@ func (ls *LinuxStatus) setDomainName(dn string) { me.domainname.Set(dn) } -func getHostname() { +func lookupHostname() { + if ! me.Ready() {return} var err error var s string = "gui.Label == nil" s, err = fqdn.FqdnHostname() @@ -33,6 +39,12 @@ func getHostname() { log.Error(errors.New("full hostname should be: " + s)) dn := run("domainname") + if me.window == nil { + log.Log(NOW, "me.window == nil") + } else { + log.Log(NOW, "me.window exists, but has not been drawn") + log.Log(NOW, "me.window.Draw() =") + } if (me.domainname.Get() != dn) { log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn) me.setDomainName(dn) diff --git a/linuxstatus/linuxloop.go b/linuxstatus/linuxloop.go index 1981aa2..ba981aa 100644 --- a/linuxstatus/linuxloop.go +++ b/linuxstatus/linuxloop.go @@ -14,7 +14,7 @@ import ( func linuxLoop() { me.changed = false - duration := timeFunction(getHostname) + duration := timeFunction(lookupHostname) log.Log(INFO, "getHostname() execution Time: ", duration, "me.changed =", me.changed) duration = timeFunction(scanInterfaces) diff --git a/linuxstatus/update.go b/linuxstatus/update.go index 0de7cf9..686d799 100644 --- a/linuxstatus/update.go +++ b/linuxstatus/update.go @@ -10,7 +10,7 @@ import ( func (ls *LinuxStatus) Update() { if ! ls.Ready() { - log.Warn("can't update yet. ready is false") + log.Log(WARN, "can't update yet. ready is false") log.Error(errors.New("Update() is not ready yet")) return } @@ -19,13 +19,13 @@ func (ls *LinuxStatus) Update() { linuxLoop() }) ls.SetSpeed(duration) - log.Info("linuxStatus() Update() END") + log.Log(INFO, "Update() END") } func (ls *LinuxStatus) SetSpeed(duration time.Duration) { s := fmt.Sprint(duration) if ls.speedActual == nil { - log.Warn("can't actually warn") + log.Log(WARN, "can't actually warn") return } ls.speedActual.Set(s)