Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-31 22:28:02 -07:00
parent 9bdd73cff4
commit 035daca718
7 changed files with 67 additions and 92 deletions

View File

@ -20,7 +20,7 @@ func AddEntry(box *GuiBox, name string) *GuiEntry {
}) })
box.UiBox.Append(ue, false) box.UiBox.Append(ue, false)
ge.E = ue ge.UiEntry = ue
box.EntryMap[name] = ge box.EntryMap[name] = ge
return ge return ge
@ -69,7 +69,7 @@ func generateSubdomain(b *GuiButton) {
} }
// subdomain.SetText("cust00013.wit.dev") // subdomain.SetText("cust00013.wit.dev")
txt := SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wpord.wit.com") txt := SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wprod.wit.com")
log.Println("generateSubdomain subdomain = ", txt) log.Println("generateSubdomain subdomain = ", txt)
log.Println("generateSubdomain END") log.Println("generateSubdomain END")
} }

29
area.go
View File

@ -1,44 +1,28 @@
package gui package gui
import "log" import "log"
// import "time"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
func findFB(button *GuiButton) *GuiButton { // THIS IS CLEAN
var a *GuiButton
for key, foo := range Data.AllButtons {
log.Println("findFB() Data.AllButtons key, foo=", key, foo)
if foo == button {
log.Println("findFB() FOUND BUTTON key, foo=", key, foo)
a = foo
}
}
return a
}
func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) { func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) {
// make this button just to get the default font (but don't display the button) // make this button just to get the default font (but don't display the button)
// There should be another way to do this (?) // There should be another way to do this (?)
var newB *GuiButton var newB *GuiButton
newB = CreateFontButton(gb, "AREA") newB = CreateFontButton(gb, "AREA")
newB.Box = gb
newB.GW = gb.W
// initialize the GuiArea{} // initialize the GuiArea{}
gb.Area = new(GuiArea) gb.Area = new(GuiArea)
gb.Area.Window = gb.W
gb.Area.UiAttrstr = newText
// ah.UiAttrstr = makeAttributedString()
gb.Area.UiArea = ui.NewArea(gb.Area)
newB.A = gb.Area.UiArea
newB.GW = gb.W
newB.Box = gb
// Data.AllButtons[1].A = ah.UiArea
// ah.Button = &Data.AllButtons[1]
gb.Area.Button = newB gb.Area.Button = newB
gb.Area.Box = gb
gb.Area.UiAttrstr = newText
gb.Area.UiArea = ui.NewArea(gb.Area)
if (Data.Debug) { if (Data.Debug) {
spew.Dump(gb.Area.UiArea) spew.Dump(gb.Area.UiArea)
@ -103,6 +87,7 @@ func (ah GuiArea) DragBroken(a *ui.Area) {
log.Println("GOT DragBroken()") log.Println("GOT DragBroken()")
} }
// TODO: fix KeyEvents
func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
log.Println("GOT KeyEvent()") log.Println("GOT KeyEvent()")
if (ke.Key == 10) { if (ke.Key == 10) {

17
gui.go
View File

@ -145,6 +145,7 @@ func mouseClick(b *GuiButton) {
createAddVmBox(b.GW, b) createAddVmBox(b.GW, b)
return return
} }
/*
if (b.Action == "WINDOW CLOSE") { if (b.Action == "WINDOW CLOSE") {
b.W.Hide() b.W.Hide()
// TODO: fix this (seems to crash? maybe because we are in the button here?) // TODO: fix this (seems to crash? maybe because we are in the button here?)
@ -154,10 +155,12 @@ func mouseClick(b *GuiButton) {
if (b.Action == "ADD") { if (b.Action == "ADD") {
log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?") log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?")
} }
*/
} }
if (Data.MouseClick == nil) { if (Data.MouseClick == nil) {
log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING") log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING")
log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function")
} else { } else {
log.Println("\tgui.mouseClick() Data.MouseClick() START") log.Println("\tgui.mouseClick() Data.MouseClick() START")
Data.MouseClick(b) Data.MouseClick(b)
@ -210,8 +213,7 @@ func AddButton(b *GuiButton, name string) *ui.Button {
return newB return newB
} }
func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*GuiButton)) *GuiButton {
name string, action string, custom func(*GuiButton)) *GuiButton {
newUiB := ui.NewButton(name) newUiB := ui.NewButton(name)
newUiB.OnClicked(defaultButtonClick) newUiB.OnClicked(defaultButtonClick)
@ -223,7 +225,6 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM,
panic("crap") panic("crap")
} }
newB.GW = box.W newB.GW = box.W
newB.T = box.W.UiTab
newB.Account = a newB.Account = a
newB.VM = vm newB.VM = vm
newB.Box = box newB.Box = box
@ -266,9 +267,9 @@ func GetText(box *GuiBox, name string) string {
return "" return ""
} }
e := box.EntryMap[name] e := box.EntryMap[name]
log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.E.Text()) log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.GetText() END") log.Println("gui.GetText() END")
return e.E.Text() return e.UiEntry.Text()
} }
func SetText(box *GuiBox, name string, value string) error { func SetText(box *GuiBox, name string, value string) error {
@ -283,9 +284,9 @@ func SetText(box *GuiBox, name string, value string) error {
return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ") return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ")
} }
e := box.EntryMap[name] e := box.EntryMap[name]
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.E.Text()) log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
e.E.SetText(value) e.UiEntry.SetText(value)
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.E.Text()) log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.SetText() END") log.Println("gui.SetText() END")
return nil return nil
} }

View File

@ -170,12 +170,13 @@ func GuiInit() {
}) })
} }
func StartNewWindow(c *pb.Config, bg bool, action string) { func StartNewWindow(c *pb.Config, bg bool, action string, text func() *ui.AttributedString) {
log.Println("InitNewWindow() Create a new window") log.Println("InitNewWindow() Create a new window")
var newGuiWindow GuiWindow var newGuiWindow GuiWindow
newGuiWindow.Width = int(c.Width) newGuiWindow.Width = int(c.Width)
newGuiWindow.Height = int(c.Height) newGuiWindow.Height = int(c.Height)
newGuiWindow.Action = action newGuiWindow.Action = action
newGuiWindow.GetText = text
Data.Windows = append(Data.Windows, &newGuiWindow) Data.Windows = append(Data.Windows, &newGuiWindow)
// make(newGuiWindow.BoxMap) // make(newGuiWindow.BoxMap)
@ -210,7 +211,7 @@ func InitWindow(gw *GuiWindow) {
// 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 = gw.UiWindow // newBM.W = gw.UiWindow
newBM.GW = gw newBM.GW = gw
Data.AllButtons = append(Data.AllButtons, &newBM) Data.AllButtons = append(Data.AllButtons, &newBM)
@ -231,7 +232,12 @@ func InitWindow(gw *GuiWindow) {
if (gw.Action == "SPLASH") { if (gw.Action == "SPLASH") {
log.Println("InitWindow() TRYING SPLASH") log.Println("InitWindow() TRYING SPLASH")
damnit := "click" + string(Data.Config.Hostname) damnit := "click" + string(Data.Config.Hostname)
tmp := getSplashText(damnit) var tmp *ui.AttributedString
if (gw.GetText == nil) {
tmp = getSplashText(damnit)
} else {
tmp = gw.GetText()
}
log.Println("InitWindow() TRYING SPLASH tmp =", tmp) log.Println("InitWindow() TRYING SPLASH tmp =", tmp)
abox := ShowSplashBox(gw, tmp) abox := ShowSplashBox(gw, tmp)
@ -252,7 +258,7 @@ func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action
e := defaultMakeEntry(startValue, edit, action) e := defaultMakeEntry(startValue, edit, action)
vboxN.Append(e.E, false) vboxN.Append(e.UiEntry, false)
hbox.Append(vboxN, false) hbox.Append(vboxN, false)
// End 'Nickname' vertical box // End 'Nickname' vertical box
@ -298,7 +304,7 @@ func defaultEntryChange(e *ui.Entry) {
if (Data.Debug) { if (Data.Debug) {
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em) log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
} }
if Data.AllEntries[key].E == e { if Data.AllEntries[key].UiEntry == e {
log.Println("defaultEntryChange() FOUND", log.Println("defaultEntryChange() FOUND",
"action =", Data.AllEntries[key].Action, "action =", Data.AllEntries[key].Action,
"Last =", Data.AllEntries[key].Last, "Last =", Data.AllEntries[key].Last,
@ -324,7 +330,7 @@ func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry {
// add the entry field to the global map // add the entry field to the global map
var newEntry GuiEntry var newEntry GuiEntry
newEntry.E = e newEntry.UiEntry = e
newEntry.Edit = edit newEntry.Edit = edit
newEntry.Action = action newEntry.Action = action
if (action == "Memory") { if (action == "Memory") {
@ -342,7 +348,7 @@ func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action
hboxN.Append(ui.NewLabel(a), false) hboxN.Append(ui.NewLabel(a), false)
e := defaultMakeEntry(startValue, edit, action) e := defaultMakeEntry(startValue, edit, action)
hboxN.Append(e.E, false) hboxN.Append(e.UiEntry, false)
hbox.Append(hboxN, false) hbox.Append(hboxN, false)
// End 'Nickname' vertical box // End 'Nickname' vertical box

View File

@ -74,9 +74,6 @@ func ShowSplashBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox {
okButton := CreateButton(gb, nil, nil, "OK", "AREA", nil) okButton := CreateButton(gb, nil, nil, "OK", "AREA", nil)
newbox.Append(okButton.B, false) newbox.Append(okButton.B, false)
okButton = CreateButton(gb, nil, nil, "NEWTEXT", "NEWTEXT", nil)
newbox.Append(okButton.B, false)
// os.Exit(0) // os.Exit(0)
return gb return gb
} }

View File

@ -71,13 +71,14 @@ type GuiData struct {
// //
type GuiWindow struct { type GuiWindow struct {
Action string Action string
// Area *GuiArea // should be moved to GuiBox
BoxMap map[string]*GuiBox BoxMap map[string]*GuiBox
Width int Width int
Height int Height int
// andlabs/ui abstraction mapping
UiWindow *ui.Window UiWindow *ui.Window
UiTab *ui.Tab // if this != nil, the window is 'tabbed' UiTab *ui.Tab // if this != nil, the window is 'tabbed'
GetText func() *ui.AttributedString
} }
@ -100,9 +101,6 @@ type GuiButton struct {
// andlabs/ui abstraction mapping // andlabs/ui abstraction mapping
B *ui.Button B *ui.Button
FB *ui.FontButton 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 {
@ -110,6 +108,7 @@ type GuiBox struct {
EntryMap map[string]*GuiEntry EntryMap map[string]*GuiEntry
Area *GuiArea Area *GuiArea
// andlabs/ui abstraction mapping
UiBox *ui.Box UiBox *ui.Box
} }
@ -120,13 +119,12 @@ type GuiEntry struct {
Normalize func (string) string // function to 'normalize' the data Normalize func (string) string // function to 'normalize' the data
B *GuiButton B *GuiButton
Box *GuiBox
Account *pb.Account Account *pb.Account
VM *pb.Event_VM VM *pb.Event_VM
E *ui.Entry // andlabs/ui abstraction mapping
W *ui.Window // should be moved to *GuiWindow or GuiBox UiEntry *ui.Entry
T *ui.Tab // should be moved to *GuiWindow or GuiBox
} }
// //
@ -135,8 +133,8 @@ type GuiEntry struct {
// AREA STRUCTURES START // AREA STRUCTURES START
// //
type GuiArea struct{ type GuiArea struct{
Window *GuiWindow // what window this area is in (should be GuiBox?)
Button *GuiButton // what button handles mouse events Button *GuiButton // what button handles mouse events
Box *GuiBox
UiAttrstr *ui.AttributedString UiAttrstr *ui.AttributedString
UiArea *ui.Area UiArea *ui.Area
@ -178,7 +176,6 @@ type TableData struct {
lastRow int lastRow int
lastColumn int lastColumn int
// parentTab *ui.Tab
} }
// //
@ -231,6 +228,7 @@ type RowData struct {
Status string // status of the row? Status string // status of the row?
/* /*
// TODO: These may or may not be implementable // TODO: These may or may not be implementable
// depending on if it's possible to detect the bgcolor or what row is selected
click func() // what function to call if the user clicks on it click func() // what function to call if the user clicks on it
doubleclick func() // what function to call if the user double clicks on it doubleclick func() // what function to call if the user double clicks on it
*/ */

View File

@ -10,35 +10,24 @@ import pb "git.wit.com/wit/witProtobuf"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
/*
func AddVmConfigureTab(wm *GuiWindow, name string, pbVM *pb.Event_VM) {
CreateVmBox(wm, pbVM)
}
*/
func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
log.Println("CreateVmBox() START") log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", vm.Name) log.Println("CreateVmBox() vm.Name =", vm.Name)
log.Println("CreateVmBox() gw =", gw) log.Println("CreateVmBox() gw =", gw)
var gb *GuiBox var box *GuiBox
gb = new(GuiBox) box = new(GuiBox)
vbox := ui.NewVerticalBox() vbox := ui.NewVerticalBox()
vbox.SetPadded(true) vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox) log.Println("CreateVmBox() vbox =", vbox)
log.Println("CreateVmBox() gb.UiBox =", gb.UiBox) log.Println("CreateVmBox() box.UiBox =", box.UiBox)
gb.UiBox = vbox box.UiBox = vbox
log.Println("CreateVmBox() gb.W =", gb.W) log.Println("CreateVmBox() box.W =", box.W)
gb.W = gw box.W = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap) log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
gw.BoxMap[vm.Name] = gb gw.BoxMap[vm.Name] = box
// gw.UiTab.Append(vm.Name, vbox)
spew.Dump(vm)
if (Data.Debug) { if (Data.Debug) {
spew.Dump(vm) spew.Dump(vm)
} }
@ -61,19 +50,19 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
hboxButtons.SetPadded(true) hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false) vbox.Append(hboxButtons, false)
a := CreateButton(gb, nil, vm, "Power On", "POWERON", nil) a := CreateButton(box, nil, vm, "Power On", "POWERON", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "Power Off", "POWEROFF", nil) a = CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "Destroy", "DESTROY", nil) a = CreateButton(box, nil, vm, "Destroy", "DESTROY", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "ping", "PING", runPingClick) a = CreateButton(box, nil, vm, "ping", "PING", runPingClick)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "Console", "XTERM", runTestExecClick) a = CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "Save", "SAVE", nil) a = CreateButton(box, nil, vm, "Save", "SAVE", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
a = CreateButton(gb, nil, vm, "Done", "DONE", nil) a = CreateButton(box, nil, vm, "Done", "DONE", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
AddBoxToTab(vm.Name, gw.UiTab, vbox) AddBoxToTab(vm.Name, gw.UiTab, vbox)
@ -83,14 +72,14 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) {
log.Println("createAddVmBox() START") log.Println("createAddVmBox() START")
name := "(" + b.Account.Nick + ")" name := "(" + b.Account.Nick + ")"
var gb *GuiBox var box *GuiBox
gb = new(GuiBox) box = new(GuiBox)
vbox := ui.NewVerticalBox() vbox := ui.NewVerticalBox()
vbox.SetPadded(true) vbox.SetPadded(true)
gb.UiBox = vbox box.UiBox = vbox
gb.W = gw box.W = gw
gw.BoxMap["ADD VM" + name] = gb gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox() hbox := ui.NewHorizontalBox()
hbox.SetPadded(true) hbox.SetPadded(true)
@ -113,13 +102,12 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) {
newb.Action = "CREATE" newb.Action = "CREATE"
newb.VM = b.VM newb.VM = b.VM
newb.Account = b.Account newb.Account = b.Account
newb.T = gw.UiTab
hostname.B = &newb hostname.B = &newb
memory.B = &newb memory.B = &newb
disk.B = &newb disk.B = &newb
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false) hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
a := CreateButton(gb, nil, nil, "Cancel", "CLOSE", nil) a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil)
hboxButtons.Append(a.B, false) hboxButtons.Append(a.B, false)
AddBoxToTab(name, gw.UiTab, vbox) AddBoxToTab(name, gw.UiTab, vbox)