single CreateButton function

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-24 20:54:09 -07:00
parent da315467cc
commit fdd473b23b
8 changed files with 52 additions and 80 deletions

View File

@ -9,12 +9,12 @@ func AddAccountQuestionBox(junk *ui.Box, custom func(*ButtonMap)) *ui.Box {
newbox := ui.NewVerticalBox()
newbox.SetPadded(true)
newButton := CreateButton("Create New Account", "DONE", custom)
newButton := CreateButton(nil, nil, "Create New Account", "DONE", custom)
newbox.Append(newButton, false)
newbox.Append(ui.NewHorizontalSeparator(), false)
okButton := CreateButton("I Have an Account", "DONE", custom)
okButton := CreateButton(nil, nil, "I Have an Account", "DONE", custom)
newbox.Append(okButton, false)
return newbox
@ -119,10 +119,10 @@ func AddAccountBox(custom func(*ButtonMap)) *ui.Box {
hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false)
okButton := CreateButton("Add Account", "ADD", custom)
okButton := CreateButton(nil, nil, "Add Account", "ADD", custom)
hboxButtons.Append(okButton, false)
backButton := CreateButton("Back", "BACK", custom)
backButton := CreateButton(nil, nil, "Back", "BACK", custom)
hboxButtons.Append(backButton, false)
return vbox

View File

@ -51,15 +51,15 @@ func addTableTab() {
log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(1 * 1000 * 1000 * 1000)
AddTableTab(Data.cloudTab, 1, "test seven", 7, parts)
AddTableTab(Data.cloudTab, 1, "test seven", 7, parts, nil)
}
func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap)) {
vbox.Append(ui.NewLabel("Debugging:"), false)
vbox.Append(ui.NewColorButton(), false)
vbox.Append(CreateButton("Add Account", "ADD", custom), false)
vbox.Append(CreateButton("Quit", "QUIT", custom), false)
vbox.Append(CreateButton(nil, nil, "Add Account", "ADD", custom), false)
vbox.Append(CreateButton(nil, nil, "Quit", "QUIT", custom), false)
// ATTEMPT TO ADD THE TABLE HERE
add2button := ui.NewButton("Add a Test Table")
@ -70,11 +70,11 @@ func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap)) {
vbox.Append(add2button, false)
// ATTEMPT TO ADD THE TABLE HERE END
vbox.Append(CreateButton("Close GUI", "QUIT", custom), false)
vbox.Append(CreateButton("DEBUG goroutines", "DEBUG", custom), false)
vbox.Append(CreateButton(nil, nil, "Close GUI", "QUIT", custom), false)
vbox.Append(CreateButton(nil, nil, "DEBUG goroutines", "DEBUG", custom), false)
// vbox.Append(CreateButton("ping", "PING", runPingClick), false)
vbox.Append(CreateButton("xterm", "XTERM", runTestExecClick), false)
vbox.Append(CreateButton("Load test.json config file", "CONFIG", custom), false)
vbox.Append(CreateButton(nil, nil, "xterm", "XTERM", runTestExecClick), false)
vbox.Append(CreateButton(nil, nil, "Load test.json config file", "CONFIG", custom), false)
}
func runPingClick(b *ButtonMap) {

45
gui.go
View File

@ -41,7 +41,7 @@ func InitColumns(mh *TableData, parts []TableColumnData) {
}
}
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []TableColumnData) *TableData {
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []TableColumnData, account *pb.Config_Account) *TableData {
mh := new(TableData)
mh.RowCount = rowcount
@ -90,8 +90,8 @@ func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
hbox.Append(CreateButton("Add Virtual Machine", "createAddVmBox", mouseClick), false)
hbox.Append(CreateButton("Close", "CLOSE", mouseClick), false)
hbox.Append(CreateButton(account, nil, "Add Virtual Machine", "createAddVmBox", mouseClick), false)
hbox.Append(CreateButton(account, nil, "Close", "CLOSE", mouseClick), false)
vbox.Append(hbox, false)
@ -193,48 +193,15 @@ func defaultFontButtonClick(button *ui.FontButton) {
}
}
func CreateButton(name string, note string, custom func(*ButtonMap)) *ui.Button {
func CreateButton(a *pb.Config_Account, vm *pb.Event_VM,
name string, note string, custom func(*ButtonMap)) *ui.Button {
newB := ui.NewButton(name)
newB.OnClicked(defaultButtonClick)
var newmap ButtonMap
newmap.B = newB
newmap.Account = a
newmap.Action = note
// newmap.Name = name
newmap.custom = custom
Data.AllButtons = append(Data.AllButtons, newmap)
return newB
}
func CreateAccountButton(pbC *pb.Config_Account, custom func(*ButtonMap)) *ui.Button {
name := "Show " + pbC.Nick
newB := ui.NewButton(name)
newB.OnClicked(defaultButtonClick)
var newmap ButtonMap
newmap.B = newB
newmap.Account = pbC
newmap.Action = "SHOW"
// newmap.Name = name
// newmap.AccNick = account
newmap.custom = custom
Data.AllButtons = append(Data.AllButtons, newmap)
return newB
}
func CreateLoginButton(pbC *pb.Config_Account, custom func(*ButtonMap)) *ui.Button {
name := "Login " + pbC.Nick
newB := ui.NewButton(name)
newB.OnClicked(defaultButtonClick)
var newmap ButtonMap
newmap.B = newB
newmap.Account = pbC
newmap.Action = "LOGIN"
// newmap.Name = name
// newmap.AccNick = account
newmap.custom = custom
Data.AllButtons = append(Data.AllButtons, newmap)

View File

@ -7,7 +7,7 @@ import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import pb "git.wit.com/wit/witProtobuf"
import pb "git.wit.com/wit/witProtobuf"
// import "github.com/davecgh/go-spew/spew"
func makeCloudInfoBox(custom func(*ButtonMap)) *ui.Box {
@ -48,7 +48,7 @@ func makeCloudInfoBox(custom func(*ButtonMap)) *ui.Box {
hostnameEntry.SetText(tmp)
hostnameEntry.SetReadOnly(true)
hostnamebox.Append(CreateButton("Edit", "EDIT", custom), false)
hostnamebox.Append(CreateButton(nil, nil, "Edit", "EDIT", custom), false)
vbox.Append(ui.NewHorizontalSeparator(), false)
@ -72,10 +72,12 @@ func makeCloudInfoBox(custom func(*ButtonMap)) *ui.Box {
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Username), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Domainname), 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
l := CreateLoginButton(Data.Config.Accounts[key], custom)
name := "Login " + Data.Config.Accounts[key].Nick
l := CreateButton(Data.Config.Accounts[key], nil, name, "LOGIN", custom)
agrid.Append(l, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
b := CreateAccountButton(Data.Config.Accounts[key], custom)
name = "Show " + Data.Config.Accounts[key].Nick
b := CreateButton(Data.Config.Accounts[key], nil, name, "SHOW", custom)
agrid.Append(b, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
row += 1
@ -84,16 +86,16 @@ func makeCloudInfoBox(custom func(*ButtonMap)) *ui.Box {
row += 1
agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
row += 1
a := CreateButton("Add Account", "ADD", custom)
a := CreateButton(nil, nil, "Add Account", "ADD", custom)
agrid.Append(a, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
q := CreateButton("Quit", "QUIT", custom)
q := CreateButton(nil, nil, "Quit", "QUIT", custom)
agrid.Append(q, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
vbox.Append(agrid, false)
return hbox
}
func AddVmsTab(name string, count int) *TableData {
func AddVmsTab(name string, count int, a *pb.Config_Account) *TableData {
var parts []TableColumnData
human := 0
@ -147,6 +149,6 @@ func AddVmsTab(name string, count int) *TableData {
parts = append(parts, tmp)
human += 1
mh := AddTableTab(Data.cloudTab, 1, name, count, parts)
mh := AddTableTab(Data.cloudTab, 1, name, count, parts, a)
return mh
}

View File

@ -45,7 +45,7 @@ func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(*ButtonMap)) *ui.Bo
}
}
okButton := CreateButton("OK", "DONE", custom)
okButton := CreateButton(nil, nil, "OK", "DONE", custom)
newbox.Append(okButton, false)
if (vbox != nil) {

View File

@ -64,8 +64,8 @@ type GuiDataStructure struct {
// a tab (maybe the one the user is playing with?)
CurrentTab *GuiTabStructure
// a VM (maybe the one the user is playing with?)
CurrentVM string
CurrentPbVM *pb.Event_VM
// CurrentVM string
CurrentVM *pb.Event_VM
// All the tabs
Tabs []GuiTabStructure
@ -99,6 +99,7 @@ type ButtonMap struct {
B *ui.Button
FB *ui.FontButton
Account *pb.Config_Account
VM *pb.Event_VM
Action string // what type of button
custom func (*ButtonMap)
@ -126,7 +127,7 @@ type RowData struct {
HumanData [20]HumanCellData
// The VM from the protobuf
PbVM *pb.Event_VM
VM *pb.Event_VM
}
//
@ -171,6 +172,8 @@ type TableData struct {
Cells [20]CellData
Human [20]HumanMap
Account *pb.Config_Account // what account this table is for
lastRow int
lastColumn int
parentTab *ui.Tab

View File

@ -7,7 +7,7 @@ package gui
//
import "log"
import "fmt"
// import "fmt"
import "image/color"
import "runtime"
@ -100,15 +100,15 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
vmname := mh.Rows[row].HumanData[humanID].Text
log.Println("vmname =", vmname)
log.Println("defaultSetCellValue() FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
Data.CurrentVM = fmt.Sprintf("%s",vmname)
Data.CurrentPbVM = mh.Rows[row].PbVM
log.Println("User last clicked on Data.CurrentVM =", Data.CurrentVM)
// Data.CurrentVM = fmt.Sprintf("%s",vmname)
Data.CurrentVM = mh.Rows[row].VM
log.Println("User last clicked on Data.CurrentVM =", mh.Rows[row].VM)
if (Data.Debug) {
go ui.Main(ShowVM)
} else {
// AddVmConfigureTab(vmname, mh.Rows[row].PbVM)
// createVmBox(Data.cloudTab, buttonVmClick, mh.Rows[row].PbVM)
createVmBox(Data.cloudTab, mouseClick, mh.Rows[row].PbVM)
createVmBox(Data.cloudTab, mouseClick, mh.Rows[row].VM)
}
}
}

View File

@ -11,7 +11,7 @@ import "github.com/davecgh/go-spew/spew"
import pb "git.wit.com/wit/witProtobuf"
func ShowVM() {
name := Data.CurrentVM
name := Data.CurrentVM.Name
log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
VMwin := ui.NewWindow("VM " + name, 500, 300, false)
VMwin.OnClosing(func(*ui.Window) bool {
@ -27,12 +27,12 @@ func ShowVM() {
VMwin.SetChild(VMtab)
VMwin.SetMargined(true)
createVmBox(VMtab, mouseClick, Data.CurrentPbVM)
createVmBox(VMtab, mouseClick, Data.CurrentVM)
VMwin.Show()
}
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
createVmBox(Data.cloudTab, mouseClick, Data.CurrentPbVM)
createVmBox(Data.cloudTab, mouseClick, Data.CurrentVM)
}
// makeEntryBox(box, "hostname:", "blah.foo.org") {
@ -108,15 +108,15 @@ func createVmBox(tab *ui.Tab, custom func(*ButtonMap), pbVM *pb.Event_VM) {
hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false)
hboxButtons.Append(CreateButton("Power On", "POWERON", custom), false)
hboxButtons.Append(CreateButton("Power Off", "POWEROFF", custom), false)
hboxButtons.Append(CreateButton("Destroy", "DESTROY", custom), false)
hboxButtons.Append(CreateButton("ping", "PING", runPingClick), false)
hboxButtons.Append(CreateButton("Console", "XTERM", runTestExecClick), false)
hboxButtons.Append(CreateButton("Save", "SAVE", custom), false)
hboxButtons.Append(CreateButton("Done", "DONE", custom), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Power On", "POWERON", custom), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Power Off", "POWEROFF", custom), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Destroy", "DESTROY", custom), false)
hboxButtons.Append(CreateButton(nil, pbVM, "ping", "PING", runPingClick), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Console", "XTERM", runTestExecClick), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Save", "SAVE", custom), false)
hboxButtons.Append(CreateButton(nil, pbVM, "Done", "DONE", custom), false)
tab.Append(Data.CurrentVM, vbox)
tab.Append(Data.CurrentVM.Name, vbox)
tab.SetMargined(0, true)
}
@ -138,8 +138,8 @@ func createAddVmBox(tab *ui.Tab, name string, custom func(*ButtonMap)) {
hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false)
hboxButtons.Append(CreateButton("Add Virtual Machine", "CREATE", custom), false)
hboxButtons.Append(CreateButton("Cancel", "DONE", custom), false)
hboxButtons.Append(CreateButton(nil, nil, "Add Virtual Machine", "CREATE", custom), false)
hboxButtons.Append(CreateButton(nil, nil, "Cancel", "DONE", custom), false)
tab.Append(name, vbox)
tab.SetMargined(0, true)