From f35ad0837bae88d260e896886033320b64c2772e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 05:55:51 -0600 Subject: [PATCH] more window handling Signed-off-by: Jeff Carr --- linuxstatus/common.go | 33 ++++++++++++++++++++------------- linuxstatus/new.go | 26 +++++++++++++++++++++++--- linuxstatus/structs.go | 13 +++++++------ 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/linuxstatus/common.go b/linuxstatus/common.go index c4aea10..8bedaf8 100644 --- a/linuxstatus/common.go +++ b/linuxstatus/common.go @@ -5,30 +5,37 @@ import ( "go.wit.com/log" ) -func (hs *LinuxStatus) Show() { +func (ls *LinuxStatus) Show() { log.Log(CHANGE, "linuxStatus.Show() window") - hs.window.Show() - hs.hidden = false + ls.window.Show() + ls.hidden = false } -func (hs *LinuxStatus) Hide() { +func (ls *LinuxStatus) Hide() { log.Log(CHANGE, "linuxStatus.Hide() window") - hs.window.Hide() - hs.hidden = true + ls.window.Hide() + ls.hidden = true } -func (hs *LinuxStatus) Toggle() { +func (ls *LinuxStatus) Toggle() { log.Log(CHANGE, "linuxStatus.Toggle() window") - if hs.hidden { - hs.window.Show() + if ls.hidden { + ls.window.Show() } else { - hs.window.Hide() + ls.window.Hide() } } -func (hs *LinuxStatus) Ready() bool { +func (ls *LinuxStatus) Ready() bool { if me == nil {return false} - if hs == nil {return false} - if hs.window == nil {return false} + if ls == nil {return false} + if ls.window == nil {return false} return me.ready } + +func (ls *LinuxStatus) Initialized() bool { + if me == nil {return false} + if ls == nil {return false} + if ls.parent == nil {return false} + return true +} diff --git a/linuxstatus/new.go b/linuxstatus/new.go index 0ce504c..5788ee1 100644 --- a/linuxstatus/new.go +++ b/linuxstatus/new.go @@ -2,16 +2,36 @@ package linuxstatus import ( + "go.wit.com/log" + + "go.wit.com/gui/gadgets" ) func New() *LinuxStatus { + if me != nil { + log.Warn("You have done New() twice. You can only do this once") + return me + } me = &LinuxStatus { hidden: true, ready: false, } - me.init = true return me - - // me.window = gadgets.NewBasicWindow(me.myGui, "Linux OS Details") +} + +func (ls *LinuxStatus) InitWindow() { + if ! ls.Initialized() { + log.Warn("LinuxStatus() is not initalized yet (no parent for the window?)") + return + } + if ls.window != nil { + log.Warn("You already have a window") + ls.ready = true + return + } + + ls.ready = true + log.Warn("Creating the Window") + ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details") } diff --git a/linuxstatus/structs.go b/linuxstatus/structs.go index 185f0d7..be541f2 100644 --- a/linuxstatus/structs.go +++ b/linuxstatus/structs.go @@ -14,13 +14,14 @@ import ( var me *LinuxStatus type LinuxStatus struct { - init bool - ready bool - hidden bool - changed bool + ready bool + hidden bool + changed bool - ifmap map[int]*IFtype // the current interfaces - ipmap map[string]*IPtype // the current ip addresses + parent *gui.Node + + ifmap map[int]*IFtype // the current interfaces + ipmap map[string]*IPtype // the current ip addresses window *gadgets.BasicWindow group *gui.Node