2019-05-15 13:03:42 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2019-05-24 13:44:57 -05:00
|
|
|
import "fmt"
|
2019-05-15 13:03:42 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
|
2019-05-15 13:03:42 -05:00
|
|
|
func ShowVM() {
|
2019-05-24 22:54:09 -05:00
|
|
|
name := Data.CurrentVM.Name
|
2019-05-24 03:17:14 -05:00
|
|
|
log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
|
2019-05-15 13:03:42 -05:00
|
|
|
VMwin := ui.NewWindow("VM " + name, 500, 300, false)
|
|
|
|
VMwin.OnClosing(func(*ui.Window) bool {
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
ui.OnShouldQuit(func() bool {
|
|
|
|
VMwin.Destroy()
|
|
|
|
VMwin = nil
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
VMtab := ui.NewTab()
|
|
|
|
VMwin.SetChild(VMtab)
|
|
|
|
VMwin.SetMargined(true)
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
createVmBox(VMtab, mouseClick, Data.CurrentVM)
|
2019-05-15 13:03:42 -05:00
|
|
|
VMwin.Show()
|
|
|
|
}
|
2019-05-24 03:17:14 -05:00
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
|
2019-05-24 22:54:09 -05:00
|
|
|
createVmBox(Data.cloudTab, mouseClick, Data.CurrentVM)
|
2019-05-24 03:17:14 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
2019-05-24 14:51:04 -05:00
|
|
|
func makeEntryVbox(hbox *ui.Box, a string, b string, edit bool) {
|
2019-05-24 03:17:14 -05:00
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
vboxN := ui.NewVerticalBox()
|
|
|
|
vboxN.SetPadded(true)
|
2019-05-24 13:32:47 -05:00
|
|
|
vboxN.Append(ui.NewLabel(a), false)
|
2019-05-24 03:17:14 -05:00
|
|
|
|
|
|
|
entryNick := ui.NewEntry()
|
2019-05-24 13:32:47 -05:00
|
|
|
entryNick.SetText(b)
|
2019-05-24 13:44:57 -05:00
|
|
|
if (edit == false) {
|
|
|
|
entryNick.SetReadOnly(true)
|
|
|
|
}
|
2019-05-24 03:17:14 -05:00
|
|
|
|
|
|
|
vboxN.Append(entryNick, false)
|
|
|
|
|
|
|
|
entryNick.OnChanged(func(*ui.Entry) {
|
2019-05-24 13:32:47 -05:00
|
|
|
log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
|
|
|
|
// Data.AccNick = entryNick.Text()
|
2019-05-24 03:17:14 -05:00
|
|
|
})
|
2019-05-24 13:32:47 -05:00
|
|
|
hbox.Append(vboxN, false)
|
2019-05-24 03:17:14 -05:00
|
|
|
// End 'Nickname' vertical box
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
2019-05-24 03:17:14 -05:00
|
|
|
|
2019-05-24 14:51:04 -05:00
|
|
|
func makeEntryHbox(hbox *ui.Box, a string, b string, edit bool) {
|
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
hboxN := ui.NewHorizontalBox()
|
|
|
|
hboxN.SetPadded(true)
|
|
|
|
hboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
|
|
|
entryNick := ui.NewEntry()
|
|
|
|
entryNick.SetText(b)
|
|
|
|
if (edit == false) {
|
|
|
|
entryNick.SetReadOnly(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
hboxN.Append(entryNick, false)
|
|
|
|
|
|
|
|
entryNick.OnChanged(func(*ui.Entry) {
|
|
|
|
log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
|
|
|
|
// Data.AccNick = entryNick.Text()
|
|
|
|
})
|
|
|
|
hbox.Append(hboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
func createVmBox(tab *ui.Tab, custom func(*ButtonMap), pbVM *pb.Event_VM) {
|
2019-05-24 13:32:47 -05:00
|
|
|
log.Println("createVmBox() START")
|
|
|
|
log.Println("createVmBox() pbVM.Name", pbVM.Name)
|
|
|
|
spew.Dump(pbVM)
|
|
|
|
if (Data.Debug) {
|
|
|
|
spew.Dump(pbVM)
|
|
|
|
}
|
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
2019-05-24 03:17:14 -05:00
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
hboxAccount := ui.NewHorizontalBox()
|
|
|
|
hboxAccount.SetPadded(true)
|
|
|
|
vbox.Append(hboxAccount, false)
|
2019-05-24 03:17:14 -05:00
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
// Add hostname entry box
|
2019-05-24 14:51:04 -05:00
|
|
|
makeEntryVbox(hboxAccount, "hostname:", pbVM.Hostname, true)
|
|
|
|
makeEntryVbox(hboxAccount, "IPv6:", pbVM.IPv6, true)
|
|
|
|
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",pbVM.Memory), true)
|
|
|
|
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",pbVM.Cpus), true)
|
|
|
|
makeEntryVbox(hboxAccount, "Disk (GB):", fmt.Sprintf("%d",pbVM.Disk), true)
|
|
|
|
makeEntryVbox(hboxAccount, "OS Image:", pbVM.BaseImage, true)
|
2019-05-24 03:17:14 -05:00
|
|
|
|
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
hboxButtons := ui.NewHorizontalBox()
|
|
|
|
hboxButtons.SetPadded(true)
|
|
|
|
vbox.Append(hboxButtons, false)
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
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)
|
2019-05-24 03:51:37 -05:00
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
tab.Append(Data.CurrentVM.Name, vbox)
|
2019-05-24 03:51:37 -05:00
|
|
|
tab.SetMargined(0, true)
|
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
func createAddVmBox(tab *ui.Tab, name string, custom func(*ButtonMap)) {
|
2019-05-24 14:51:04 -05:00
|
|
|
log.Println("createAddVmBox() START")
|
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
|
|
|
|
hboxAccount := ui.NewHorizontalBox()
|
|
|
|
hboxAccount.SetPadded(true)
|
|
|
|
vbox.Append(hboxAccount, false)
|
|
|
|
|
|
|
|
// Add hostname entry box
|
|
|
|
makeEntryHbox(hboxAccount, "hostname:", "", true)
|
|
|
|
|
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
hboxButtons := ui.NewHorizontalBox()
|
|
|
|
hboxButtons.SetPadded(true)
|
|
|
|
vbox.Append(hboxButtons, false)
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
hboxButtons.Append(CreateButton(nil, nil, "Add Virtual Machine", "CREATE", custom), false)
|
|
|
|
hboxButtons.Append(CreateButton(nil, nil, "Cancel", "DONE", custom), false)
|
2019-05-24 14:51:04 -05:00
|
|
|
|
|
|
|
tab.Append(name, vbox)
|
|
|
|
tab.SetMargined(0, true)
|
|
|
|
}
|