continue variable and structure improvements

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-31 06:58:23 -07:00
parent 02ab32835e
commit d73ae31eb2
4 changed files with 97 additions and 98 deletions

2
gui.go
View File

@ -237,7 +237,7 @@ func CreateFontButton(wm *GuiWindow, action string) *GuiButton {
var newBM GuiButton var newBM GuiButton
newBM.Action = action newBM.Action = action
newBM.FB = newB newBM.FB = newB
newBM.AH = wm.AH newBM.Area = wm.Area
Data.AllButtons = append(Data.AllButtons, &newBM) Data.AllButtons = append(Data.AllButtons, &newBM)
newB.OnChanged(func (*ui.FontButton) { newB.OnChanged(func (*ui.FontButton) {

View File

@ -13,7 +13,7 @@ import pb "git.wit.com/wit/witProtobuf"
// import "github.com/davecgh/go-spew/spew" // import "github.com/davecgh/go-spew/spew"
func makeCloudInfoBox(wm *GuiWindow) *ui.Box { func makeCloudInfoBox(gw *GuiWindow) *ui.Box {
hbox := ui.NewHorizontalBox() hbox := ui.NewHorizontalBox()
hbox.SetPadded(true) hbox.SetPadded(true)
@ -23,7 +23,7 @@ func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
vbox.SetPadded(true) vbox.SetPadded(true)
hbox.Append(vbox, false) hbox.Append(vbox, false)
addDebuggingButtons(wm, vbox) addDebuggingButtons(gw, vbox)
hbox.Append(ui.NewVerticalSeparator(), false) hbox.Append(ui.NewVerticalSeparator(), false)
} }
@ -46,7 +46,7 @@ func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
hostnameEntry.SetText(tmp) hostnameEntry.SetText(tmp)
hostnameEntry.SetReadOnly(true) hostnameEntry.SetReadOnly(true)
anew := CreateButton(wm, nil, nil, "Edit", "EDIT", nil) anew := CreateButton(gw, nil, nil, "Edit", "EDIT", nil)
hostnamebox.Append(anew.B, false) hostnamebox.Append(anew.B, false)
vbox.Append(ui.NewHorizontalSeparator(), false) vbox.Append(ui.NewHorizontalSeparator(), false)
@ -71,11 +71,11 @@ func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Email), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Email), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
name := "Login " + Data.Config.Accounts[key].Nick name := "Login " + Data.Config.Accounts[key].Nick
l := CreateButton(wm, Data.Config.Accounts[key], nil, name, "LOGIN", nil) l := CreateButton(gw, Data.Config.Accounts[key], nil, name, "LOGIN", nil)
agrid.Append(l.B, 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(l.B, 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
name = "Show " + Data.Config.Accounts[key].Nick name = "Show " + Data.Config.Accounts[key].Nick
b := CreateButton(wm, Data.Config.Accounts[key], nil, name, "SHOW", nil) b := CreateButton(gw, Data.Config.Accounts[key], nil, name, "SHOW", nil)
agrid.Append(b.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(b.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
row += 1 row += 1
@ -84,9 +84,9 @@ func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
row += 1 row += 1
agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
row += 1 row += 1
a := CreateButton(wm, nil, nil, "Add Account", "ADD TAB", nil) a := CreateButton(gw, nil, nil, "Add Account", "ADD TAB", nil)
agrid.Append(a.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(a.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
q := CreateButton(wm, nil, nil, "Quit", "QUIT", nil) q := CreateButton(gw, nil, nil, "Quit", "QUIT", nil)
agrid.Append(q.B, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) agrid.Append(q.B, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
vbox.Append(agrid, false) vbox.Append(agrid, false)
@ -102,7 +102,7 @@ func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
// which could be anything since TEXTCOLOR, TEXT, BG, etc // which could be anything since TEXTCOLOR, TEXT, BG, etc
// fields use between 1 and 3 values internally // fields use between 1 and 3 values internally
// //
func AddVmsTab(wm *GuiWindow, name string, count int, a *pb.Account) *TableData { func AddVmsTab(gw *GuiWindow, name string, count int, a *pb.Account) *TableData {
var parts []TableColumnData var parts []TableColumnData
human := 0 human := 0
@ -156,64 +156,71 @@ func AddVmsTab(wm *GuiWindow, name string, count int, a *pb.Account) *TableData
parts = append(parts, tmp) parts = append(parts, tmp)
human += 1 human += 1
mh := AddTableTab(wm, wm.T, 1, name, count, parts, a) mh := AddTableTab(gw, gw.T, 1, name, count, parts, a)
return mh return mh
} }
func ShowAccountQuestionTab(wm *GuiWindow) { func ShowAccountQuestionTab(gw *GuiWindow) {
log.Println("ShowAccountQuestionTab() wm =", wm) log.Println("ShowAccountQuestionTab() gw =", gw)
if (wm.T == nil) { if (gw.T == nil) {
log.Println("ShowAccountQuestionTab() wm.T = nil THIS IS BAD") log.Println("ShowAccountQuestionTab() gw.T = nil THIS IS BAD")
os.Exit(-1) os.Exit(-1)
} }
wm.T.Delete(0) gw.T.Delete(0)
log.Println("Sleep(200)") log.Println("Sleep(200)")
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
wm.Box2 = AddAccountQuestionBox(wm) gw.Box2 = AddAccountQuestionBox(gw)
wm.T.InsertAt("New Account?", 0, wm.Box2) gw.T.InsertAt("New Account?", 0, gw.Box2)
wm.T.SetMargined(0, true) gw.T.SetMargined(0, true)
} }
func ShowAccountTab(wm *GuiWindow, i int) { func ShowAccountTab(gw *GuiWindow, i int) {
log.Println("ShowAccountTab() START") log.Println("ShowAccountTab() START")
log.Println("Sleep(200)") log.Println("Sleep(200)")
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
// Create the things for the Account Tab // Create the things for the Account Tab
abox := AddAccountBox(wm) abox := AddAccountBox(gw)
// Set the parents and data structure links // Set the parents and data structure links
// aTab.me = wm.T // aTab.me = gw.T
// aTab.parentWindow = Data.Window1.W // aTab.parentWindow = Data.Window1.W
// aTab.tabOffset = 0 // aTab.tabOffset = 0
if (i >= 0) { if (i >= 0) {
log.Println("ShowAccountTab() InsertAt i=", i) log.Println("ShowAccountTab() InsertAt i=", i)
wm.T.Delete(0) gw.T.Delete(0)
wm.T.InsertAt("Add Account", i, abox) gw.T.InsertAt("Add Account", i, abox)
wm.T.SetMargined(0, true) gw.T.SetMargined(0, true)
} else { } else {
// TODO: After append try to discover the tab index # // TODO: After append try to discover the tab index #
log.Println("ShowAccountTab() Append") log.Println("ShowAccountTab() Append")
AddBoxToTab("Create New Account", wm.T, abox) AddBoxToTab("Create New Account", gw.T, abox)
} }
} }
func ShowMainTab(wm *GuiWindow) { func ShowMainTab(gw *GuiWindow) {
log.Println("ShowMainTab() wm =", wm) log.Println("ShowMainTab() gw =", gw)
log.Println("ShowMainTab() wm.T =", wm.T) log.Println("ShowMainTab() gw.T =", gw.T)
log.Println("ShowMainTab() wm.T =", wm.T) gw.T.Delete(0)
wm.T.Delete(0)
log.Println("Sleep(200)") log.Println("Sleep(200)")
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
wm.Box2 = makeCloudInfoBox(wm) gw.Box2 = makeCloudInfoBox(gw)
wm.T.InsertAt("Main", 0, wm.Box2) gw.T.InsertAt("Main", 0, gw.Box2)
wm.T.SetMargined(0, true) gw.T.SetMargined(0, true)
}
func GuiInit() {
ui.OnShouldQuit(func() bool {
// mouseClick(&newBM)
ui.Quit()
return true
})
} }
func StartNewWindow(c *pb.Config, bg bool, action string) { func StartNewWindow(c *pb.Config, bg bool, action string) {
@ -223,12 +230,6 @@ func StartNewWindow(c *pb.Config, bg bool, action string) {
newGuiWindow.Action = action newGuiWindow.Action = action
Data.Windows = append(Data.Windows, &newGuiWindow) Data.Windows = append(Data.Windows, &newGuiWindow)
ui.OnShouldQuit(func() bool {
// mouseClick(&newBM)
ui.Quit()
return true
})
if (bg) { if (bg) {
log.Println("ShowWindow() IN NEW GOROUTINE") log.Println("ShowWindow() IN NEW GOROUTINE")
go ui.Main(func() { go ui.Main(func() {
@ -250,47 +251,47 @@ func getSplashText(a string) *ui.AttributedString {
} }
func InitWindow(wm *GuiWindow) { func InitWindow(gw *GuiWindow) {
log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN") log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN")
c := wm.C c := gw.C
wm.W = ui.NewWindow("", int(c.Width), int(c.Height), true) gw.W = ui.NewWindow("", int(c.Width), int(c.Height), true)
wm.W.SetBorderless(false) gw.W.SetBorderless(false)
// create a 'fake' button entry for the mouse clicks // create a 'fake' button entry for the mouse clicks
var newBM GuiButton var newBM GuiButton
newBM.Action = "QUIT" newBM.Action = "QUIT"
newBM.W = wm.W newBM.W = gw.W
newBM.WM = wm newBM.WM = gw
Data.AllButtons = append(Data.AllButtons, &newBM) Data.AllButtons = append(Data.AllButtons, &newBM)
wm.W.OnClosing(func(*ui.Window) bool { gw.W.OnClosing(func(*ui.Window) bool {
log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING wm=", wm) log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw)
// mouseClick(&newBM) // mouseClick(&newBM)
ui.Quit() ui.Quit()
return true return true
}) })
wm.T = ui.NewTab() gw.T = ui.NewTab()
wm.W.SetChild(wm.T) gw.W.SetChild(gw.T)
wm.W.SetMargined(true) gw.W.SetMargined(true)
log.Println("InitWindow() wm =", wm) log.Println("InitWindow() gw =", gw)
log.Println("InitWindow() wm.Action =", wm.Action) log.Println("InitWindow() gw.Action =", gw.Action)
if (wm.Action == "SPLASH") { if (gw.Action == "SPLASH") {
log.Println("InitWindow() TRYING SPLASH") log.Println("InitWindow() TRYING SPLASH")
damnit := "click" + string(c.Hostname) damnit := "click" + string(c.Hostname)
tmp := getSplashText(damnit) tmp := getSplashText(damnit)
log.Println("InitWindow() TRYING SPLASH tmp =", tmp) log.Println("InitWindow() TRYING SPLASH tmp =", tmp)
wm.Box1 = ShowSplashBox(wm, tmp) gw.Box1 = ShowSplashBox(gw, tmp)
wm.T.Append("WIT Splash", wm.Box1) gw.T.Append("WIT Splash", gw.Box1)
wm.T.SetMargined(0, true) gw.T.SetMargined(0, true)
} }
Data.State = "splash" Data.State = "splash"
wm.W.Show() gw.W.Show()
} }
// makeEntryBox(box, "hostname:", "blah.foo.org") { // makeEntryBox(box, "hostname:", "blah.foo.org") {

View File

@ -23,12 +23,12 @@ func ShowSplashBox(wm *GuiWindow, newText *ui.AttributedString) *ui.Box {
newbox.SetPadded(true) newbox.SetPadded(true)
// initialize the GuiArea{} // initialize the GuiArea{}
wm.AH = new(GuiArea) wm.Area = new(GuiArea)
wm.AH.WM = wm wm.Area.Window = wm
wm.AH.UiAttrstr = newText wm.Area.UiAttrstr = newText
makeSplashArea(wm, wm.AH) makeSplashArea(wm, wm.Area)
newbox.Append(wm.AH.UiArea, true) newbox.Append(wm.Area.UiArea, true)
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
newbox.Append(ui.NewLabel("OS: Linux"), false) newbox.Append(ui.NewLabel("OS: Linux"), false)

View File

@ -22,10 +22,11 @@ type GuiData struct {
// if nothing else is defined to handle them // if nothing else is defined to handle them
MouseClick func(*GuiButton) MouseClick func(*GuiButton)
// account entry textboxes // passes in all the User accounts from the cloud-control-panel config file
Config *pb.Config Config *pb.Config
// general information on the App // general information on the App
// move all this to Config (?)
Version string Version string
GitCommit string GitCommit string
GoVersion string GoVersion string
@ -35,20 +36,20 @@ type GuiData struct {
DebugTable bool DebugTable bool
// official hostname and IPv6 address for this box // official hostname and IPv6 address for this box
// also move all this to Config (?)
Hostname string Hostname string
IPv6 string IPv6 string
// A map of all the entry boxes
AllEntries []*GuiEntry
Windows []*GuiWindow
// A map of all buttons everywhere on all // A map of all buttons everywhere on all
// windows, all tabs, across all goroutines // windows, all tabs, across all goroutines
// This is "GLOBAL" // This is "GLOBAL"
AllButtons []*GuiButton AllButtons []*GuiButton
ButtonMap map[*GuiButton][]func (*GuiButton) ButtonMap map[*GuiButton][]func (*GuiButton)
// A map of all the entry boxes
AllEntries []*GuiEntry
Windows []*GuiWindow
EntryNick *ui.Entry EntryNick *ui.Entry
EntryUser *ui.Entry EntryUser *ui.Entry
EntryPass *ui.Entry EntryPass *ui.Entry
@ -59,62 +60,59 @@ type GuiData struct {
// the user clicks it. You could probably // the user clicks it. You could probably
// call this 'GuiMouseClick' // call this 'GuiMouseClick'
type GuiButton struct { type GuiButton struct {
// andlabs/ui stuff Action string // what type of button
B *ui.Button Box *GuiBox // what box the button click was in
FB *ui.FontButton Area *GuiArea // indicates the button click was in an Area
A *ui.Area WM *GuiWindow // what window the button click was in (redundant?)
W *ui.Window
T *ui.Tab
Box *GuiBox Account *pb.Account // associated with what account?
AH *GuiArea VM *pb.Event_VM // associated with which VM?
// git.wit.com/wit/gui stuff
WM *GuiWindow
Account *pb.Account
VM *pb.Event_VM
Action string // what type of button
// a callback function for the main application // a callback function for the main application
custom func (*GuiButton) custom func (*GuiButton)
// andlabs/ui abstraction mapping
B *ui.Button
FB *ui.FontButton
A *ui.Area // should be deprecated
W *ui.Window // should be deprecated
T *ui.Tab // should be deprecated
} }
type GuiBox struct { type GuiBox struct {
W *GuiWindow W *GuiWindow
EntryMap map[string]*GuiEntry EntryMap map[string]*GuiEntry
A *GuiArea Area *GuiArea
UiBox *ui.Box UiBox *ui.Box
} }
type GuiEntry struct { type GuiEntry struct {
E *ui.Entry Action string // what type of button
Edit bool Edit bool
Last string // the last value Last string // the last value
Normalize func (string) string // function to 'normalize' the data Normalize func (string) string // function to 'normalize' the data
B *GuiButton
Account *pb.Account Account *pb.Account
VM *pb.Event_VM VM *pb.Event_VM
B *GuiButton E *ui.Entry
FB *ui.FontButton W *ui.Window // should be moved to *GuiWindow or GuiBox
A *ui.Area T *ui.Tab // should be moved to *GuiWindow or GuiBox
W *ui.Window
T *ui.Tab
Action string // what type of button
} }
type GuiWindow struct { type GuiWindow struct {
Action string
Area *GuiArea // should be moved to GuiBox
C *pb.Config
W *ui.Window W *ui.Window
T *ui.Tab T *ui.Tab
Box1 *ui.Box Box1 *ui.Box
Box2 *ui.Box Box2 *ui.Box
C *pb.Config
AH *GuiArea
Action string
} }
// //
@ -123,8 +121,8 @@ type GuiWindow struct {
// AREA STRUCTURES START // AREA STRUCTURES START
// //
type GuiArea struct{ type GuiArea struct{
WM *GuiWindow Window *GuiWindow // what window this area is in (should be GuiBox?)
Button *GuiButton Button *GuiButton // what button handles mouse events
UiAttrstr *ui.AttributedString UiAttrstr *ui.AttributedString
UiArea *ui.Area UiArea *ui.Area
@ -165,7 +163,7 @@ type TableData struct {
lastRow int lastRow int
lastColumn int lastColumn int
parentTab *ui.Tab // parentTab *ui.Tab
} }
// //