start to refactor the splash area code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
2a6453306b
commit
6112b54b1e
56
area.go
56
area.go
|
@ -7,63 +7,45 @@ import _ "github.com/andlabs/ui/winmanifest"
|
|||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func makeSplashArea() *ui.Area {
|
||||
func makeSplashArea() *AreaHandler {
|
||||
// make this button just to get the default font (but don't display the button)
|
||||
// There should be another way to do this (?)
|
||||
Data.fontButton = CreateFontButton("SplashFont", "DONE")
|
||||
|
||||
makeAttributedString()
|
||||
myAH.Attrstr = makeAttributedString()
|
||||
Data.splashArea = ui.NewArea(myAH)
|
||||
Data.MyArea = Data.splashArea
|
||||
myAH.Area = Data.splashArea
|
||||
|
||||
// create a 'fake' button entry for the mouse clicks
|
||||
var newmap ButtonMap
|
||||
newmap.Action = "AREA"
|
||||
newmap.AH = &myAH
|
||||
newmap.A = Data.splashArea
|
||||
myAH.button = &newmap
|
||||
myAH.Button = &newmap
|
||||
Data.AllButtons = append(Data.AllButtons, newmap)
|
||||
|
||||
if (Data.Debug) {
|
||||
spew.Dump(Data.splashArea)
|
||||
log.Println("DEBUGGING", Data.Debug)
|
||||
} else {
|
||||
log.Println("NOT DEBUGGING AREA mhAH.button =", myAH.button)
|
||||
log.Println("NOT DEBUGGING AREA mhAH.Button =", myAH.Button)
|
||||
}
|
||||
return Data.splashArea
|
||||
return &myAH
|
||||
}
|
||||
|
||||
func appendWithAttributes(what string, attrs ...ui.Attribute) {
|
||||
start := len(Data.attrstr.String())
|
||||
func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
||||
start := len(newText.String())
|
||||
end := start + len(what)
|
||||
Data.attrstr.AppendUnattributed(what)
|
||||
newText.AppendUnattributed(what)
|
||||
for _, a := range attrs {
|
||||
Data.attrstr.SetAttribute(a, start, end)
|
||||
newText.SetAttribute(a, start, end)
|
||||
}
|
||||
}
|
||||
|
||||
func makeAttributedString() {
|
||||
Data.attrstr = ui.NewAttributedString("")
|
||||
|
||||
appendWithAttributes("Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT"
|
||||
|
||||
appendWithAttributes("(alpha)\n\n", ui.TextSize(10))
|
||||
|
||||
appendWithAttributes("This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold)
|
||||
appendWithAttributes("The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold)
|
||||
|
||||
Data.attrstr.AppendUnattributed("\n")
|
||||
Data.attrstr.AppendUnattributed("\n")
|
||||
appendWithAttributes("This control panel requires:\n")
|
||||
Data.attrstr.AppendUnattributed("\n")
|
||||
appendWithAttributes("IPv6\n")
|
||||
appendWithAttributes("Your hostname in DNS\n")
|
||||
Data.attrstr.AppendUnattributed("\n\n\n\n\n")
|
||||
|
||||
appendWithAttributes("<click or press any key>\n", ui.TextSize(10))
|
||||
}
|
||||
|
||||
func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||
func (ah AreaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
||||
String: Data.attrstr,
|
||||
String: myAH.Attrstr,
|
||||
DefaultFont: Data.fontButton.Font(),
|
||||
Width: p.AreaWidth,
|
||||
Align: ui.DrawTextAlign(1),
|
||||
|
@ -72,7 +54,7 @@ func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
|||
defer tl.Free()
|
||||
}
|
||||
|
||||
func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||
func (ah AreaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||
if (Data.Debug) {
|
||||
log.Println("GOT MouseEvent()")
|
||||
spew.Dump(me)
|
||||
|
@ -84,19 +66,19 @@ func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
|||
log.Println("GOT MOUSE UP")
|
||||
log.Println("GOT MOUSE UP")
|
||||
log.Println("GOT MOUSE UP")
|
||||
mouseClick(myAH.button)
|
||||
mouseClick(myAH.Button)
|
||||
}
|
||||
}
|
||||
|
||||
func (ah areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||
func (ah AreaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||
log.Println("GOT MouseCrossed()")
|
||||
}
|
||||
|
||||
func (ah areaHandler) DragBroken(a *ui.Area) {
|
||||
func (ah AreaHandler) DragBroken(a *ui.Area) {
|
||||
log.Println("GOT DragBroken()")
|
||||
}
|
||||
|
||||
func (ah areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||
func (ah AreaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||
log.Println("GOT KeyEvent()")
|
||||
if (ke.Key == 10) {
|
||||
log.Println("GOT ENTER")
|
||||
|
|
116
mainCloudBox.go
116
mainCloudBox.go
|
@ -2,16 +2,14 @@ package gui
|
|||
|
||||
import "log"
|
||||
import "time"
|
||||
import "fmt"
|
||||
import "regexp"
|
||||
// import "os"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func makeCloudInfoBox() *ui.Box {
|
||||
hbox := ui.NewHorizontalBox()
|
||||
|
@ -243,41 +241,11 @@ func makeCloudWindow() {
|
|||
Data.State = "splash"
|
||||
}
|
||||
|
||||
func GoShowVM() {
|
||||
ui.Main(ShowVM)
|
||||
}
|
||||
|
||||
func ShowVM() {
|
||||
name := Data.CurrentVM.Name
|
||||
log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
|
||||
VMwin := ui.NewWindow("VM " + name, 500, 300, false)
|
||||
|
||||
// create a 'fake' button entry for the mouse clicks
|
||||
var newButtonMap ButtonMap
|
||||
newButtonMap.Action = "WINDOW CLOSE"
|
||||
newButtonMap.W = VMwin
|
||||
Data.AllButtons = append(Data.AllButtons, newButtonMap)
|
||||
|
||||
VMwin.OnClosing(func(*ui.Window) bool {
|
||||
mouseClick(&newButtonMap)
|
||||
return true
|
||||
})
|
||||
ui.OnShouldQuit(func() bool {
|
||||
mouseClick(&newButtonMap)
|
||||
return true
|
||||
})
|
||||
|
||||
VMtab := ui.NewTab()
|
||||
VMwin.SetChild(VMtab)
|
||||
VMwin.SetMargined(true)
|
||||
|
||||
CreateVmBox(VMtab, Data.CurrentVM)
|
||||
VMwin.Show()
|
||||
}
|
||||
|
||||
/*
|
||||
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
|
||||
CreateVmBox(Data.cloudTab, Data.CurrentVM)
|
||||
}
|
||||
*/
|
||||
|
||||
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
||||
func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *EntryMap {
|
||||
|
@ -390,81 +358,3 @@ func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) {
|
|||
tab.Append(name, box)
|
||||
tab.SetMargined(0, true)
|
||||
}
|
||||
|
||||
func CreateVmBox(tab *ui.Tab, vm *pb.Event_VM) {
|
||||
log.Println("CreateVmBox() START")
|
||||
log.Println("CreateVmBox() vm.Name", vm.Name)
|
||||
spew.Dump(vm)
|
||||
if (Data.Debug) {
|
||||
spew.Dump(vm)
|
||||
}
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
hboxAccount := ui.NewHorizontalBox()
|
||||
hboxAccount.SetPadded(true)
|
||||
vbox.Append(hboxAccount, false)
|
||||
|
||||
// Add hostname entry box
|
||||
makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true, "Hostname")
|
||||
makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true, "IPv6")
|
||||
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory")
|
||||
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus")
|
||||
makeEntryVbox(hboxAccount, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk")
|
||||
makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true, "BaseImage")
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
hboxButtons := ui.NewHorizontalBox()
|
||||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Power On", "POWERON", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Power Off", "POWEROFF", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Destroy", "DESTROY", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "ping", "PING", runPingClick), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Console", "XTERM", runTestExecClick), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Save", "SAVE", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Done", "DONE", nil), false)
|
||||
|
||||
AddBoxToTab(Data.CurrentVM.Name, tab, vbox)
|
||||
}
|
||||
|
||||
func createAddVmBox(tab *ui.Tab, name string, b *ButtonMap) {
|
||||
log.Println("createAddVmBox() START")
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
hbox := ui.NewHorizontalBox()
|
||||
hbox.SetPadded(true)
|
||||
vbox.Append(hbox, false)
|
||||
|
||||
// Add hostname entry box
|
||||
hostname := makeEntryHbox(vbox, "Hostname:", "testhost", true, "Hostname")
|
||||
memory := makeEntryHbox(vbox, "Memory:", "512", true, "Memory")
|
||||
disk := makeEntryHbox(vbox, "Disk:", "20", true, "Disk")
|
||||
|
||||
log.Println("createAddVmBox() hostname, memory, disk =", hostname, memory, disk)
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
hboxButtons := ui.NewHorizontalBox()
|
||||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
var newb ButtonMap
|
||||
newb.Action = "CREATE"
|
||||
newb.VM = b.VM
|
||||
newb.Account = b.Account
|
||||
newb.T = tab
|
||||
hostname.B = &newb
|
||||
memory.B = &newb
|
||||
disk.B = &newb
|
||||
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
|
||||
|
||||
// hboxButtons.Append(CreateButton(nil, nil, "Add Virtual Machine","CREATE",nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, nil, "Cancel", "CLOSE", nil), false)
|
||||
|
||||
name += " (" + b.Account.Nick + ")"
|
||||
AddBoxToTab(name, tab, vbox)
|
||||
}
|
||||
|
|
30
splash.go
30
splash.go
|
@ -14,10 +14,11 @@ func ShowSplashBox() *ui.Box {
|
|||
newbox := ui.NewVerticalBox()
|
||||
newbox.SetPadded(true)
|
||||
|
||||
makeAttributedString()
|
||||
Data.MyArea = makeSplashArea()
|
||||
newText := makeAttributedString()
|
||||
myAH.Attrstr = newText
|
||||
newAH := makeSplashArea()
|
||||
|
||||
newbox.Append(Data.MyArea, true)
|
||||
newbox.Append(newAH.Area, true)
|
||||
|
||||
if runtime.GOOS == "linux" {
|
||||
newbox.Append(ui.NewLabel("OS: Linux"), false)
|
||||
|
@ -50,3 +51,26 @@ func ShowSplashBox() *ui.Box {
|
|||
|
||||
return newbox
|
||||
}
|
||||
|
||||
func makeAttributedString() *ui.AttributedString {
|
||||
newText := ui.NewAttributedString("")
|
||||
|
||||
appendWithAttributes(newText, "Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT"
|
||||
|
||||
appendWithAttributes(newText, "(alpha)\n\n", ui.TextSize(10))
|
||||
|
||||
appendWithAttributes(newText, "This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold)
|
||||
appendWithAttributes(newText, "The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold)
|
||||
|
||||
newText.AppendUnattributed("\n")
|
||||
newText.AppendUnattributed("\n")
|
||||
appendWithAttributes(newText, "This control panel requires:\n")
|
||||
newText.AppendUnattributed("\n")
|
||||
appendWithAttributes(newText, "IPv6\n")
|
||||
appendWithAttributes(newText, "newText, Your hostname in DNS\n")
|
||||
newText.AppendUnattributed("\n\n\n\n\n")
|
||||
|
||||
appendWithAttributes(newText, "<click or press any key>\n", ui.TextSize(10))
|
||||
|
||||
return newText
|
||||
}
|
||||
|
|
11
structs.go
11
structs.go
|
@ -13,7 +13,7 @@ import pb "git.wit.com/wit/witProtobuf"
|
|||
// be the safe way to interact with the GUI
|
||||
//
|
||||
var Data GuiDataStructure
|
||||
var myAH areaHandler
|
||||
var myAH AreaHandler
|
||||
|
||||
type GuiDataStructure struct {
|
||||
State string
|
||||
|
@ -111,6 +111,7 @@ type ButtonMap struct {
|
|||
|
||||
Account *pb.Account
|
||||
VM *pb.Event_VM
|
||||
AH *AreaHandler
|
||||
Action string // what type of button
|
||||
|
||||
custom func (*ButtonMap)
|
||||
|
@ -118,10 +119,10 @@ type ButtonMap struct {
|
|||
|
||||
|
||||
// AREA STRUCTURES START
|
||||
type areaHandler struct{
|
||||
// buttonFunc func(int, int)
|
||||
// closeFunc func(int)
|
||||
button *ButtonMap
|
||||
type AreaHandler struct{
|
||||
Button *ButtonMap
|
||||
Attrstr *ui.AttributedString
|
||||
Area *ui.Area
|
||||
}
|
||||
// AREA STRUCTURES END
|
||||
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
import "fmt"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func GoShowVM() {
|
||||
ui.Main(ShowVM)
|
||||
}
|
||||
|
||||
func ShowVM() {
|
||||
name := Data.CurrentVM.Name
|
||||
log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
|
||||
VMwin := ui.NewWindow("VM " + name, 500, 300, false)
|
||||
|
||||
// create a 'fake' button entry for the mouse clicks
|
||||
var newButtonMap ButtonMap
|
||||
newButtonMap.Action = "WINDOW CLOSE"
|
||||
newButtonMap.W = VMwin
|
||||
Data.AllButtons = append(Data.AllButtons, newButtonMap)
|
||||
|
||||
VMwin.OnClosing(func(*ui.Window) bool {
|
||||
mouseClick(&newButtonMap)
|
||||
return true
|
||||
})
|
||||
ui.OnShouldQuit(func() bool {
|
||||
mouseClick(&newButtonMap)
|
||||
return true
|
||||
})
|
||||
|
||||
VMtab := ui.NewTab()
|
||||
VMwin.SetChild(VMtab)
|
||||
VMwin.SetMargined(true)
|
||||
|
||||
CreateVmBox(VMtab, Data.CurrentVM)
|
||||
VMwin.Show()
|
||||
}
|
||||
|
||||
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
|
||||
CreateVmBox(Data.cloudTab, Data.CurrentVM)
|
||||
}
|
||||
|
||||
func CreateVmBox(tab *ui.Tab, vm *pb.Event_VM) {
|
||||
log.Println("CreateVmBox() START")
|
||||
log.Println("CreateVmBox() vm.Name", vm.Name)
|
||||
spew.Dump(vm)
|
||||
if (Data.Debug) {
|
||||
spew.Dump(vm)
|
||||
}
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
hboxAccount := ui.NewHorizontalBox()
|
||||
hboxAccount.SetPadded(true)
|
||||
vbox.Append(hboxAccount, false)
|
||||
|
||||
// Add hostname entry box
|
||||
makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true, "Hostname")
|
||||
makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true, "IPv6")
|
||||
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory")
|
||||
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus")
|
||||
makeEntryVbox(hboxAccount, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk")
|
||||
makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true, "BaseImage")
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
hboxButtons := ui.NewHorizontalBox()
|
||||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Power On", "POWERON", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Power Off", "POWEROFF", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Destroy", "DESTROY", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "ping", "PING", runPingClick), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Console", "XTERM", runTestExecClick), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Save", "SAVE", nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, vm, "Done", "DONE", nil), false)
|
||||
|
||||
AddBoxToTab(Data.CurrentVM.Name, tab, vbox)
|
||||
}
|
||||
|
||||
func createAddVmBox(tab *ui.Tab, name string, b *ButtonMap) {
|
||||
log.Println("createAddVmBox() START")
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
hbox := ui.NewHorizontalBox()
|
||||
hbox.SetPadded(true)
|
||||
vbox.Append(hbox, false)
|
||||
|
||||
// Add hostname entry box
|
||||
hostname := makeEntryHbox(vbox, "Hostname:", "testhost", true, "Hostname")
|
||||
memory := makeEntryHbox(vbox, "Memory:", "512", true, "Memory")
|
||||
disk := makeEntryHbox(vbox, "Disk:", "20", true, "Disk")
|
||||
|
||||
log.Println("createAddVmBox() hostname, memory, disk =", hostname, memory, disk)
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
hboxButtons := ui.NewHorizontalBox()
|
||||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
var newb ButtonMap
|
||||
newb.Action = "CREATE"
|
||||
newb.VM = b.VM
|
||||
newb.Account = b.Account
|
||||
newb.T = tab
|
||||
hostname.B = &newb
|
||||
memory.B = &newb
|
||||
disk.B = &newb
|
||||
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
|
||||
|
||||
// hboxButtons.Append(CreateButton(nil, nil, "Add Virtual Machine","CREATE",nil), false)
|
||||
hboxButtons.Append(CreateButton(nil, nil, "Cancel", "CLOSE", nil), false)
|
||||
|
||||
name += " (" + b.Account.Nick + ")"
|
||||
AddBoxToTab(name, tab, vbox)
|
||||
}
|
Loading…
Reference in New Issue